/* CareerNexus 职联 · 全景图谱工作台(graph.js) * canvas 力导向 + 缩放平移 + 小地图 + 详情面板 + 节点编辑/备注/审核。 * 依赖 app.js 暴露的 CN 命名空间。 */ "use strict"; (function () { const { $, $$, api, post, esc, toast, openModal, closeModal, TYPE_META } = CN; /* ================= 状态 ================= */ const G = { nodes: [], edges: [], events: [], idx: {}, cam: { x: 0, y: 0, k: 1 }, // 相机:世界 -> 屏幕 screen = (world - cam.pan) * k ... 使用 cam.x/y 为平移(屏幕像素) showLabels: false, // 默认关闭:悬停/选中/缩放时才显示 filters: { types: { Job: true, Skill: true, Industry: false, Scenario: false }, category: "", level: "", edges: { required: true, preferred: true, applies: true, belongs: true } }, selected: null, // 选中节点 id soloJob: null, // 岗位子图模式:只看该岗位及其一跳邻居 hover: null, navStack: [], // 详情面板导航栈 drag: null, // {mode:'pan'|'node', ...} pending: [], // 待审核候选 raf: null, }; const canvas = () => $("#graph-canvas"); const NOTES_KEY = "cn_notes"; const VIEW_KEY = "cn_graph_view"; const DEFAULT_SOLO_JOB = "job_Java开发工程师"; // 首屏默认岗位子图(局部可读) /* 变化类型颜色(与 app.js CHANGE_META 一致):新增=青绿 / 增强=蓝紫 / 减弱=琥珀 / 退出=砖红 */ const CHANGE_COLORS = { "新增": "#13c2c2", "增强": "#722ed1", "减弱": "#ff7d00", "退出": "#f53f3f" }; const CHANGE_MARK = { "新增": "新", "增强": "↑", "减弱": "↓", "退出": "退" }; /* 变化角标数据:最近 2 季度有事件的技能(子图模式下按当前岗位过滤) */ function updateRecentChange() { const wins = [...new Set(G.events.map((e) => e.window))].sort().slice(-2); const m = new Map(); G.events.forEach((e) => { if (!wins.includes(e.window)) return; if (G.soloJob && e.job_id !== G.soloJob) return; m.set(e.skill, e); // 事件按窗口升序,后者覆盖前者 = 取最近事件 }); G.recentChange = m; } /* 同心分层布局(岗位子图):中心岗位 → 第一圈必备技能 → 第二圈加分技能 → 外圈场景/行业 */ function applySoloLayout() { const job = G.nodes[G.idx[G.soloJob]]; if (!job) return; const rings = [[], [], []]; G.edges.forEach((e) => { if (e.source !== G.soloJob) return; const t = G.nodes[G.idx[e.target]]; if (!t) return; if (e.rel === "REQUIRES") rings[e.importance === "required" ? 0 : 1].push(t); else rings[2].push(t); // APPLIES_TO / BELONGS_TO → 外圈 }); const base = [150, 260, 370]; let prevR = 0; rings.forEach((nodes, ri) => { nodes.sort((a, b) => String(a.title || a.id).localeCompare(String(b.title || b.id), "zh")); const R = Math.max(base[ri], prevR + 90, (nodes.length * 34) / (2 * Math.PI)); prevR = R; nodes.forEach((n, i) => { const a = (i / Math.max(1, nodes.length)) * Math.PI * 2 - Math.PI / 2; n.x = job.x + Math.cos(a) * R; n.y = job.y + Math.sin(a) * R; n.vx = 0; n.vy = 0; }); }); } /* 视野适配子图(只按子图节点的包围盒,而非全图) */ function fitSoloView() { const c = canvas(); const ids = new Set([G.soloJob, ...neighborsOf(G.soloJob)]); let minX = 1e9, minY = 1e9, maxX = -1e9, maxY = -1e9; G.nodes.forEach((n) => { if (!ids.has(n.id) || !visible(n)) return; minX = Math.min(minX, n.x); maxX = Math.max(maxX, n.x); minY = Math.min(minY, n.y); maxY = Math.max(maxY, n.y); }); if (minX > maxX) return fitView(); const w = maxX - minX || 1, h = maxY - minY || 1; const W = c.clientWidth, H = c.clientHeight; G.cam.k = Math.max(0.2, Math.min(W / (w + 160), H / (h + 160), 1.6)); G.cam.x = (W - w * G.cam.k) / 2 - minX * G.cam.k; G.cam.y = (H - h * G.cam.k) / 2 - minY * G.cam.k; requestDraw(); drawMinimap(); } /* ================= 数据装载 ================= */ async function load() { $("#graph-loading").classList.remove("hidden"); const [data, pending] = await Promise.all([ api("/api/graph"), api("/api/review/pending").catch(() => []), ]); CN.graphData = data; G.events = data.events || []; G.pending = pending; G.nodes = data.nodes.map((n) => ({ ...n, x: 0, y: 0, vx: 0, vy: 0 })); G.idx = Object.fromEntries(G.nodes.map((n, i) => [n.id, i])); G.edges = data.edges.filter((e) => e.source in G.idx && e.target in G.idx); /* 合并待审核候选为虚线节点 */ pending.forEach((c) => { if (!(c.job_id in G.idx)) { G.idx[c.job_id] = G.nodes.push({ id: c.job_id, type: "Job", title: c.title, category: c.category, status: "pending", pending: true, expected_years: c.expected_years, source_count: c.source_count, company_count: c.company_count, x: 0, y: 0, vx: 0, vy: 0, }) - 1; } [...c.required_skills.map((s) => [s, "required"]), ...c.preferred_skills.map((s) => [s, "preferred"])].forEach(([s, imp]) => { if (!(s in G.idx)) { G.idx[s] = G.nodes.push({ id: s, type: "Skill", category: "", x: 0, y: 0, vx: 0, vy: 0 }) - 1; } G.edges.push({ source: c.job_id, target: s, rel: "REQUIRES", importance: imp, weight: 1, intervals: [], sources: [], pending: true }); }); }); buildFilterOptions(); layout(); restoreView() || fitView(); /* 默认进入「Java开发工程师」岗位子图:同心分层布局(中心岗位 → 必备 → 加分 → 场景/行业), * 退出子图即全量「岗位生态总览」(每次装载仅应用一次) */ if (!G._defaultApplied && !G.pendingLocate && G.idx[DEFAULT_SOLO_JOB]) { G._defaultApplied = true; G.soloJob = DEFAULT_SOLO_JOB; updateSoloBadge(); applySoloLayout(); selectNode(DEFAULT_SOLO_JOB, false); fitSoloView(); } updateRecentChange(); renderSuggest(); renderChain(G.soloJob || null); $("#graph-loading").classList.add("hidden"); requestDraw(); drawMinimap(); if (G.pendingLocate) { const t = G.pendingLocate; G.pendingLocate = null; locateNode(t); } } function buildFilterOptions() { const cats = [...new Set(G.nodes.filter((n) => n.type === "Job" && n.category).map((n) => n.category))].sort(); $("#fp-category").innerHTML = `` + cats.map((c) => ``).join(""); } /* ================= 力导向布局 ================= */ function layout() { const N = G.nodes.length; G.nodes.forEach((n, i) => { const a = (i / N) * Math.PI * 2; n.x = Math.cos(a) * 400 + (Math.random() - 0.5) * 60; n.y = Math.sin(a) * 400 + (Math.random() - 0.5) * 60; n.vx = 0; n.vy = 0; }); for (let iter = 0; iter < 320; iter++) { for (let i = 0; i < N; i++) { const a = G.nodes[i]; for (let j = i + 1; j < N; j++) { const b = G.nodes[j]; let dx = a.x - b.x, dy = a.y - b.y; let d2 = dx * dx + dy * dy || 1; if (d2 > 640000) continue; const d = Math.sqrt(d2); const f = 2600 / d2; dx = (dx / d) * f; dy = (dy / d) * f; a.vx += dx; a.vy += dy; b.vx -= dx; b.vy -= dy; } } G.edges.forEach((e) => { const a = G.nodes[G.idx[e.source]], b = G.nodes[G.idx[e.target]]; let dx = b.x - a.x, dy = b.y - a.y; const d = Math.sqrt(dx * dx + dy * dy) || 1; const rest = (a.type === "Job" && b.type === "Job") ? 260 : 130; const f = (d - rest) * 0.015; dx = (dx / d) * f; dy = (dy / d) * f; a.vx += dx; a.vy += dy; b.vx -= dx; b.vy -= dy; }); G.nodes.forEach((n) => { n.vx *= 0.55; n.vy *= 0.55; n.x += Math.max(-24, Math.min(24, n.vx)); n.y += Math.max(-24, Math.min(24, n.vy)); }); } } function worldBounds() { let minX = 1e9, minY = 1e9, maxX = -1e9, maxY = -1e9; G.nodes.forEach((n) => { minX = Math.min(minX, n.x); maxX = Math.max(maxX, n.x); minY = Math.min(minY, n.y); maxY = Math.max(maxY, n.y); }); return { minX, minY, maxX, maxY, w: maxX - minX || 1, h: maxY - minY || 1 }; } /* ================= 相机 ================= */ function fitView() { const c = canvas(), b = worldBounds(); const W = c.clientWidth, H = c.clientHeight; G.cam.k = Math.min(W / (b.w + 120), H / (b.h + 120), 1.6); G.cam.x = (W - b.w * G.cam.k) / 2 - b.minX * G.cam.k; G.cam.y = (H - b.h * G.cam.k) / 2 - b.minY * G.cam.k; requestDraw(); drawMinimap(); } const toScreen = (n) => ({ x: n.x * G.cam.k + G.cam.x, y: n.y * G.cam.k + G.cam.y }); const toWorld = (sx, sy) => ({ x: (sx - G.cam.x) / G.cam.k, y: (sy - G.cam.y) / G.cam.k }); function zoomAt(factor, cx, cy) { const c = canvas(); cx = cx ?? c.clientWidth / 2; cy = cy ?? c.clientHeight / 2; const w = toWorld(cx, cy); G.cam.k = Math.max(0.15, Math.min(4, G.cam.k * factor)); G.cam.x = cx - w.x * G.cam.k; G.cam.y = cy - w.y * G.cam.k; requestDraw(); drawMinimap(); } function centerOn(node, k) { const c = canvas(); if (k) G.cam.k = k; G.cam.x = c.clientWidth / 2 - node.x * G.cam.k; G.cam.y = c.clientHeight / 2 - node.y * G.cam.k; requestDraw(); drawMinimap(); } /* ================= 可见性(筛选) ================= */ function jobLevel(n) { const y = n.expected_years; if (y == null) return ""; return y <= 2 ? "初级" : y <= 5 ? "中级" : "高级"; } function visible(n) { if (!G.filters.types[n.type]) return false; if (G.soloJob) { // 岗位子图:只保留该岗位与一跳邻居 if (n.id !== G.soloJob && !neighborsOf(G.soloJob).has(n.id)) return false; } if (n.type === "Job") { if (G.filters.category && n.category !== G.filters.category) return false; if (G.filters.level && jobLevel(n) !== G.filters.level) return false; } return true; } function edgeVisible(e) { const ef = G.filters.edges || {}; if (e.rel === "REQUIRES") return ef[e.importance === "required" ? "required" : "preferred"] !== false; if (e.rel === "APPLIES_TO") return ef.applies !== false; if (e.rel === "BELONGS_TO") return ef.belongs !== false; return true; } function neighborsOf(id) { const set = new Set(); G.edges.forEach((e) => { if (!edgeVisible(e)) return; if (e.source === id) set.add(e.target); if (e.target === id) set.add(e.source); }); return set; } /* ================= 渲染 ================= */ function requestDraw() { if (G.raf) return; G.raf = requestAnimationFrame(() => { G.raf = null; draw(); }); } function nodeRadius(n) { return n.type === "Job" ? 13 : n.type === "Scenario" ? 8 : n.type === "Industry" ? 10 : 6.5; } function draw() { const c = canvas(); if (!c.clientWidth) return; const dpr = window.devicePixelRatio || 1; c.width = c.clientWidth * dpr; c.height = c.clientHeight * dpr; const ctx = c.getContext("2d"); ctx.scale(dpr, dpr); ctx.clearRect(0, 0, c.clientWidth, c.clientHeight); const sel = G.selected; const hop = sel ? neighborsOf(sel) : null; /* ---- 边 ---- */ G.edges.forEach((e) => { const a = G.nodes[G.idx[e.source]], b = G.nodes[G.idx[e.target]]; if (!visible(a) || !visible(b)) return; if (!edgeVisible(e)) return; const pa = toScreen(a), pb = toScreen(b); const isHot = sel && (e.source === sel || e.target === sel); const dim = sel && !isHot; const isReq = e.importance === "required"; ctx.save(); if (e.rel === "APPLIES_TO") { ctx.strokeStyle = dim ? "rgba(114,46,209,0.05)" : isHot ? "rgba(114,46,209,0.7)" : "rgba(114,46,209,0.22)"; ctx.setLineDash([]); ctx.lineWidth = isHot ? 1.4 : 0.8; } else if (isReq) { ctx.strokeStyle = dim ? "rgba(78,89,105,0.05)" : isHot ? "rgba(47,84,235,0.75)" : "rgba(78,89,105,0.28)"; ctx.setLineDash([]); ctx.lineWidth = isHot ? 1.8 : 1; } else { ctx.strokeStyle = dim ? "rgba(19,194,194,0.05)" : isHot ? "rgba(19,194,194,0.8)" : "rgba(19,194,194,0.4)"; ctx.setLineDash([5, 4]); ctx.lineWidth = isHot ? 1.6 : 1; } if (e.pending) ctx.setLineDash([3, 4]); ctx.beginPath(); ctx.moveTo(pa.x, pa.y); ctx.lineTo(pb.x, pb.y); ctx.stroke(); ctx.setLineDash([]); /* 箭头(指向 target 节点边缘) */ const dx = pb.x - pa.x, dy = pb.y - pa.y; const d = Math.sqrt(dx * dx + dy * dy) || 1; const rB = nodeRadius(b) * G.cam.k + 2; const ax = pb.x - (dx / d) * rB, ay = pb.y - (dy / d) * rB; const ang = Math.atan2(dy, dx); const ah = isHot ? 7 : 5.5; ctx.fillStyle = ctx.strokeStyle; ctx.beginPath(); ctx.moveTo(ax, ay); ctx.lineTo(ax - ah * Math.cos(ang - 0.45), ay - ah * Math.sin(ang - 0.45)); ctx.lineTo(ax - ah * Math.cos(ang + 0.45), ay - ah * Math.sin(ang + 0.45)); ctx.closePath(); ctx.fill(); /* 关系标签(颜色 + 文字双重编码) */ if (G.showLabels && e.rel === "REQUIRES" && G.cam.k > 0.55 && !dim) { ctx.font = "10px sans-serif"; ctx.textAlign = "center"; ctx.fillStyle = isReq ? "rgba(47,84,235,0.85)" : "rgba(9,151,156,0.9)"; ctx.fillText(isReq ? "必备" : "加分", (pa.x + pb.x) / 2, (pa.y + pb.y) / 2 - 3); } ctx.restore(); }); /* ---- 节点 ---- */ G.nodes.forEach((n) => { if (!visible(n)) return; const p = toScreen(n); const r = Math.max(2.5, nodeRadius(n) * Math.sqrt(G.cam.k)); const isSel = n.id === sel; const isHop = hop && hop.has(n.id); const dim = sel && !isSel && !isHop; const meta = TYPE_META[n.type] || { color: "#86909c" }; ctx.save(); ctx.globalAlpha = dim ? 0.15 : 1; ctx.fillStyle = meta.color; if (n.type === "Skill") { const s = r * 1.7; ctx.beginPath(); ctx.roundRect(p.x - s / 2, p.y - s / 2, s, s, 2.5); ctx.fill(); } else { ctx.beginPath(); ctx.arc(p.x, p.y, r, 0, 7); ctx.fill(); } if (n.pending || n.status === "pending") { ctx.setLineDash([3, 3]); ctx.strokeStyle = "#ff7d00"; ctx.lineWidth = 1.6; ctx.beginPath(); ctx.arc(p.x, p.y, r + 3.5, 0, 7); ctx.stroke(); ctx.setLineDash([]); } if (isSel) { ctx.strokeStyle = "#1d2129"; ctx.lineWidth = 2; ctx.beginPath(); ctx.arc(p.x, p.y, r + 4, 0, 7); ctx.stroke(); } else if (isHop) { ctx.strokeStyle = "rgba(47,84,235,0.55)"; ctx.lineWidth = 1.5; ctx.beginPath(); ctx.arc(p.x, p.y, r + 2.5, 0, 7); ctx.stroke(); } /* 标签:岗位常显,其余放大或选中/悬停时显示 */ if (n.type === "Job" || G.cam.k > 1.05 || isSel || isHop || n.id === G.hover) { ctx.font = `${n.type === "Job" ? 11 : 10}px sans-serif`; ctx.textAlign = "center"; ctx.fillStyle = "rgba(255,255,255,0.85)"; const label = n.title || n.id; const tw = ctx.measureText(label).width; ctx.fillRect(p.x - tw / 2 - 3, p.y - r - 17, tw + 6, 13); ctx.fillStyle = n.type === "Job" ? "#1d2129" : "#4e5969"; ctx.fillText(label, p.x, p.y - r - 7); } /* 变化角标:最近 2 季度有事件的技能节点右上角显示 新/↑/↓/退 */ const ch = n.type === "Skill" && G.recentChange ? G.recentChange.get(n.id) : null; if (ch && !dim) { const mark = CHANGE_MARK[ch.change_type] || ""; const bc = CHANGE_COLORS[ch.change_type] || "#86909c"; const bx = p.x + r * 0.95, by = p.y - r * 0.95; ctx.fillStyle = bc; ctx.beginPath(); ctx.arc(bx, by, 7, 0, 7); ctx.fill(); ctx.strokeStyle = "#fff"; ctx.lineWidth = 1.2; ctx.beginPath(); ctx.arc(bx, by, 7, 0, 7); ctx.stroke(); ctx.fillStyle = "#fff"; ctx.font = "bold 8px sans-serif"; ctx.textAlign = "center"; ctx.textBaseline = "middle"; ctx.fillText(mark, bx, by + 0.5); ctx.textBaseline = "alphabetic"; } ctx.restore(); }); /* 悬停提示:有近期变化的技能显示变化时间与证据量 */ if (G.hover && G.recentChange && G.recentChange.has(G.hover) && G.idx[G.hover] != null) { const n = G.nodes[G.idx[G.hover]]; const e = G.recentChange.get(G.hover); const p = toScreen(n); const r = Math.max(2.5, nodeRadius(n) * Math.sqrt(G.cam.k)); const txt = `${e.window} ${e.change_type} · 支撑 ${(e.source_ids || []).length} 条 JD`; ctx.font = "11px sans-serif"; const tw = ctx.measureText(txt).width; const bx = Math.max(4, Math.min(c.clientWidth - tw - 20, p.x - tw / 2 - 8)); ctx.fillStyle = "rgba(29,33,41,0.92)"; ctx.beginPath(); ctx.roundRect(bx, p.y + r + 10, tw + 16, 20, 4); ctx.fill(); ctx.fillStyle = "#fff"; ctx.textAlign = "center"; ctx.fillText(txt, bx + tw / 2 + 8, p.y + r + 24); } } /* ================= 小地图 ================= */ function drawMinimap() { const mm = $("#minimap-canvas"); const ctx = mm.getContext("2d"); const W = mm.width, H = mm.height; ctx.clearRect(0, 0, W, H); if (!G.nodes.length) return; const b = worldBounds(); const k = Math.min((W - 10) / b.w, (H - 10) / b.h); const ox = (W - b.w * k) / 2 - b.minX * k; const oy = (H - b.h * k) / 2 - b.minY * k; G.edges.forEach((e) => { const a = G.nodes[G.idx[e.source]], bb = G.nodes[G.idx[e.target]]; if (!visible(a) || !visible(bb)) return; ctx.strokeStyle = "rgba(120,130,150,0.25)"; ctx.beginPath(); ctx.moveTo(a.x * k + ox, a.y * k + oy); ctx.lineTo(bb.x * k + ox, bb.y * k + oy); ctx.stroke(); }); G.nodes.forEach((n) => { if (!visible(n)) return; const meta = TYPE_META[n.type] || { color: "#86909c" }; ctx.fillStyle = n.pending ? "#ff7d00" : meta.color; ctx.beginPath(); ctx.arc(n.x * k + ox, n.y * k + oy, n.type === "Job" ? 2.6 : 1.6, 0, 7); ctx.fill(); }); /* 视口框 */ const c = canvas(); const tl = toWorld(0, 0), br = toWorld(c.clientWidth, c.clientHeight); ctx.strokeStyle = "#2f54eb"; ctx.lineWidth = 1.4; ctx.strokeRect(tl.x * k + ox, tl.y * k + oy, (br.x - tl.x) * k, (br.y - tl.y) * k); mm._proj = { k, ox, oy }; } $("#minimap-canvas").addEventListener("click", (e) => { const mm = e.currentTarget, p = mm._proj; if (!p) return; const rect = mm.getBoundingClientRect(); const wx = (e.clientX - rect.left - p.ox) / p.k; const wy = (e.clientY - rect.top - p.oy) / p.k; centerOn({ x: wx, y: wy }); }); /* ================= 交互:平移 / 缩放 / 点选 / 拖拽节点 ================= */ function pickNode(sx, sy) { let best = null, bd = 1e9; G.nodes.forEach((n) => { if (!visible(n)) return; const p = toScreen(n); const r = Math.max(8, nodeRadius(n) * Math.sqrt(G.cam.k) + 4); const d = (p.x - sx) ** 2 + (p.y - sy) ** 2; if (d < r * r && d < bd) { bd = d; best = n; } }); return best; } function bindCanvas() { const c = canvas(); c.addEventListener("mousedown", (e) => { const rect = c.getBoundingClientRect(); const sx = e.clientX - rect.left, sy = e.clientY - rect.top; const node = pickNode(sx, sy); G.drag = node ? { mode: "node", node, moved: false } : { mode: "pan", sx, sy, camX: G.cam.x, camY: G.cam.y, moved: false }; c.classList.add("dragging"); }); window.addEventListener("mousemove", (e) => { const rect = c.getBoundingClientRect(); const sx = e.clientX - rect.left, sy = e.clientY - rect.top; if (!G.drag) { const h = pickNode(sx, sy); const id = h ? h.id : null; if (id !== G.hover) { G.hover = id; requestDraw(); } c.classList.toggle("hovering", !!h); return; } G.drag.moved = true; if (G.drag.mode === "pan") { G.cam.x = G.drag.camX + (sx - G.drag.sx); G.cam.y = G.drag.camY + (sy - G.drag.sy); } else { const w = toWorld(sx, sy); G.drag.node.x = w.x; G.drag.node.y = w.y; } requestDraw(); }); window.addEventListener("mouseup", () => { if (G.drag && G.drag.mode === "node" && G.drag.moved) drawMinimap(); if (G.drag && G.drag.mode === "pan" && G.drag.moved) drawMinimap(); G.drag = null; c.classList.remove("dragging"); }); c.addEventListener("click", (e) => { if (G.drag && G.drag.moved) return; const rect = c.getBoundingClientRect(); const node = pickNode(e.clientX - rect.left, e.clientY - rect.top); selectNode(node ? node.id : null); }); c.addEventListener("wheel", (e) => { e.preventDefault(); const rect = c.getBoundingClientRect(); zoomAt(e.deltaY < 0 ? 1.12 : 0.89, e.clientX - rect.left, e.clientY - rect.top); }, { passive: false }); window.addEventListener("resize", () => { requestDraw(); drawMinimap(); }); } /* ================= 工具条 / 筛选 ================= */ function bindToolbar() { $("#tool-zoom-in").onclick = () => zoomAt(1.25); $("#tool-zoom-out").onclick = () => zoomAt(0.8); $("#tool-fit").onclick = fitView; $("#tool-relayout").onclick = () => { $("#graph-loading").classList.remove("hidden"); setTimeout(() => { layout(); fitView(); $("#graph-loading").classList.add("hidden"); toast("布局已整理", "success"); }, 30); }; $("#tool-labels").onclick = (e) => { G.showLabels = !G.showLabels; e.currentTarget.classList.toggle("active", G.showLabels); requestDraw(); }; $("#tool-filter").onclick = () => $("#graph-filter-panel").classList.toggle("hidden"); document.addEventListener("click", (e) => { if (!e.target.closest("#graph-filter-panel") && !e.target.closest("#tool-filter")) { $("#graph-filter-panel").classList.add("hidden"); } }); $$("#graph-filter-panel input[data-ftype]").forEach((cb) => { cb.onchange = () => { G.filters.types[cb.dataset.ftype] = cb.checked; requestDraw(); drawMinimap(); }; }); $$("#graph-filter-panel input[data-etype]").forEach((cb) => { cb.onchange = () => { G.filters.edges[cb.dataset.etype] = cb.checked; requestDraw(); drawMinimap(); }; }); $("#fp-category").onchange = (e) => { G.filters.category = e.target.value; requestDraw(); drawMinimap(); }; $("#fp-level").onchange = (e) => { G.filters.level = e.target.value; requestDraw(); drawMinimap(); }; $("#fp-reset").onclick = () => { G.filters = { types: { Job: true, Skill: true, Industry: false, Scenario: false }, category: "", level: "", edges: { required: true, preferred: true, applies: true, belongs: true } }; $$("#graph-filter-panel input[data-ftype]").forEach((cb) => { cb.checked = true; }); $$("#graph-filter-panel input[data-etype]").forEach((cb) => { cb.checked = true; }); $("#fp-category").value = ""; $("#fp-level").value = ""; requestDraw(); drawMinimap(); }; /* 头部主操作:查看演化 / 查看证据 / 开始匹配;保存/分享/导出收进「更多」 */ const activeJobId = () => { const n = G.selected != null ? G.nodes[G.idx[G.selected]] : null; if (n && n.type === "Job" && !n.pending) return G.selected; if (G.soloJob) return G.soloJob; return DEFAULT_SOLO_JOB; }; $("#btn-goto-evo").onclick = () => { CN.switchView("evolution"); $("#evo-job-select").value = activeJobId(); $("#evo-job-select").dispatchEvent(new Event("change")); }; $("#btn-goto-match").onclick = () => { CN.switchView("match"); $("#match-job-select").value = activeJobId(); $("#match-job-select").dispatchEvent(new Event("change")); toast("已带入目标岗位,请上传或载入示例简历", "success"); }; $("#btn-goto-evidence").onclick = () => { const id = G.selected || G.soloJob; if (!id) return toast("请先在画布中选择一个节点", "info"); const sources = new Set(); G.edges.forEach((e) => { if (e.source === id || e.target === id) (e.sources || []).forEach((s) => sources.add(s)); }); const list = [...sources]; if (!list.length) return toast("该节点暂无来源证据记录", "info"); const n = G.nodes[G.idx[id]]; CN.showJdEvidence(list, { jobTitle: n.title || id }); }; $("#btn-more-menu").onclick = (e) => { e.stopPropagation(); $("#more-menu").classList.toggle("hidden"); }; document.addEventListener("click", (e) => { if (!e.target.closest(".more-wrap")) $("#more-menu").classList.add("hidden"); }); $("#btn-save-view").onclick = () => { localStorage.setItem(VIEW_KEY, JSON.stringify({ cam: G.cam, filters: G.filters, labels: G.showLabels })); $("#more-menu").classList.add("hidden"); toast("当前视图(位置/缩放/筛选)已保存", "success"); }; $("#btn-share-graph").onclick = async () => { const url = `${location.origin}/#view=graph${G.selected ? `&node=${encodeURIComponent(G.selected)}` : ""}`; $("#more-menu").classList.add("hidden"); try { await navigator.clipboard.writeText(url); toast("分享链接已复制到剪贴板", "success"); } catch { CN.sysCopy({ title: "分享链接(请复制)", text: url }); } }; $("#btn-export-graph").onclick = () => { $("#more-menu").classList.add("hidden"); const c = canvas(); const tmp = document.createElement("canvas"); tmp.width = c.width; tmp.height = c.height; const tctx = tmp.getContext("2d"); tctx.fillStyle = "#ffffff"; tctx.fillRect(0, 0, tmp.width, tmp.height); tctx.drawImage(c, 0, 0); tmp.toBlob((blob) => { const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = `CareerNexus_岗位能力图谱_${new Date().toISOString().slice(0, 10)}.png`; a.click(); URL.revokeObjectURL(a.href); toast("图谱 PNG 已导出", "success"); }); }; } function restoreView() { try { const v = JSON.parse(localStorage.getItem(VIEW_KEY) || "null"); if (!v) return false; G.cam = v.cam; G.filters = Object.assign( { types: { Job: true, Skill: true, Industry: false, Scenario: false }, category: "", level: "", edges: { required: true, preferred: true, applies: true, belongs: true } }, v.filters); G.filters.edges = Object.assign({ required: true, preferred: true, applies: true, belongs: true }, (v.filters && v.filters.edges) || {}); G.showLabels = v.labels !== false; $("#tool-labels").classList.toggle("active", G.showLabels); $$("#graph-filter-panel input[data-ftype]").forEach((cb) => { cb.checked = !!G.filters.types[cb.dataset.ftype]; }); $$("#graph-filter-panel input[data-etype]").forEach((cb) => { cb.checked = G.filters.edges[cb.dataset.etype] !== false; }); $("#fp-category").value = G.filters.category || ""; $("#fp-level").value = G.filters.level || ""; return true; } catch { return false; } } /* ================= 系统发现(原画布浮层「智能建议」,移入右侧详情面板底部可折叠区块) ================= */ const IGNORED_KEY = "cn_ignored_findings"; const ignoredSet = () => new Set(JSON.parse(localStorage.getItem(IGNORED_KEY) || "[]")); function renderSuggest() { const ig = ignoredSet(); const items = []; G.pending.forEach((c) => items.push({ color: "#ff7d00", kind: "pending", id: c.job_id, nodeId: c.job_id, text: `新岗位候选「${esc(c.title)}」待审核`, sub: `原因:聚类发现 ${c.source_count} 条 JD / ${c.company_count} 家企业指向未收录岗位 · 证据 ${c.source_count} 条`, })); G.events.slice(-4).reverse().forEach((e) => items.push({ color: "#2f54eb", kind: "event", id: `${e.job_id}|${e.skill}|${e.window}`, nodeId: e.job_id, text: `「${esc(e.job_id.replace(/^job_/, ""))}」${esc(e.change_type)}技能 ${esc(e.skill)}`, sub: `证据:窗口 ${esc(e.window)} · 需求指数 ${e.prev_weight.toFixed(2)}→${e.curr_weight.toFixed(2)} · ${(e.source_ids || []).length} 条 JD`, })); const list = items.filter((it) => !ig.has(`${it.kind}|${it.id}`)); $("#gs-list").innerHTML = list.length ? list.map((it, i) => `