From ec5dd9adf7c1a240541cd40855b6b98bf74fa4d2 Mon Sep 17 00:00:00 2001 From: chiyi Date: Mon, 12 Oct 2026 13:59:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(canvas):=20=E8=8A=82=E7=82=B9=E9=97=B4?= =?UTF-8?q?=E8=BF=9E=E7=BA=BF=E5=8E=BB=E9=87=8D=E5=B9=B6=E6=94=BE=E5=A4=A7?= =?UTF-8?q?=E5=BC=AF=E6=8A=98=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/canvas/CanvasStage.vue | 2 +- frontend/src/utils/canvas.js | 4 ++++ frontend/src/views/CanvasView.vue | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/canvas/CanvasStage.vue b/frontend/src/components/canvas/CanvasStage.vue index 92ce3e3..4d69ee6 100644 --- a/frontend/src/components/canvas/CanvasStage.vue +++ b/frontend/src/components/canvas/CanvasStage.vue @@ -726,7 +726,7 @@ defineExpose({ class="cv-edge-bend" :cx="p.handle.x" :cy="p.handle.y" - r="5" + r="8" /> diff --git a/frontend/src/utils/canvas.js b/frontend/src/utils/canvas.js index cdab8ea..dde948c 100644 --- a/frontend/src/utils/canvas.js +++ b/frontend/src/utils/canvas.js @@ -123,10 +123,14 @@ export function normalizeDoc(raw) { } } if (Array.isArray(raw.edges)) { + const pairs = new Set() // 同一对节点只保留一条线(旧文档可能有重复) for (const e of raw.edges) { if (!e || typeof e.id !== 'string') continue if (typeof e.from !== 'string' || typeof e.to !== 'string') continue if (!ids.has(e.from) || !ids.has(e.to) || e.from === e.to) continue + const pair = e.from < e.to ? `${e.from}|${e.to}` : `${e.to}|${e.from}` + if (pairs.has(pair)) continue + pairs.add(pair) const edge = { id: e.id, from: e.from, to: e.to } if (['top', 'right', 'bottom', 'left'].includes(e.fromSide)) edge.fromSide = e.fromSide if (['top', 'right', 'bottom', 'left'].includes(e.toSide)) edge.toSide = e.toSide diff --git a/frontend/src/views/CanvasView.vue b/frontend/src/views/CanvasView.vue index ff8728f..963e5f8 100644 --- a/frontend/src/views/CanvasView.vue +++ b/frontend/src/views/CanvasView.vue @@ -378,7 +378,8 @@ function deleteSelection() { // ---- 手动连线 ---- function onLinkCreate({ from, to, fromSide, toSide }) { - if (doc.edges.some((e) => e.from === from && e.to === to)) return // 去重 + // 任意方向去重:两个节点之间只允许一条连线 + if (doc.edges.some((e) => (e.from === from && e.to === to) || (e.from === to && e.to === from))) return doc.edges.push({ id: newId('e'), from, to, fromSide, toSide }) pushHistory() }