fix:工艺画布拉线表单带入残留信息根因修复:禁用VueFlow connectOnClick(单击手柄会挂起待连接状态,之后再点手柄以旧节点为起点触发connect,导致间歇性带入错误输入/输出);预填改为prop挂载时确定;误吸附回起点按拉空白处理;单纯点击手柄不再弹新增表单;节点增减后重新适配视野

This commit is contained in:
caoqianming 2026-07-23 16:06:02 +08:00
parent 494999eb11
commit a378a39917
2 changed files with 37 additions and 7 deletions

View File

@ -61,6 +61,8 @@
:default-viewport="{ zoom: 0.9 }" :default-viewport="{ zoom: 0.9 }"
:min-zoom="0.2" :min-zoom="0.2"
:max-zoom="2" :max-zoom="2"
:connection-radius="8"
:connect-on-click="false"
:nodes-draggable="true" :nodes-draggable="true"
:nodes-connectable="!readonly" :nodes-connectable="!readonly"
:elements-selectable="true" :elements-selectable="true"
@ -87,13 +89,14 @@
</div> </div>
</div> </div>
<!-- 复用现有单步表单新增/编辑一条 Routekey 随每次打开递增强制重建实例杜绝上次内容残留 --> <!-- 复用现有单步表单新增/编辑一条 Routekey 随每次打开递增强制重建实例预填走 prop 在挂载时即确定 -->
<route-form <route-form
v-if="dialogVisible" v-if="dialogVisible"
:key="dialogSeq" :key="dialogSeq"
ref="routeForm" ref="routeForm"
:count="count" :count="count"
:routepack="routepack" :routepack="routepack"
:prefill="formPrefill"
@success="onFormSuccess" @success="onFormSuccess"
@closed="dialogVisible = false" @closed="dialogVisible = false"
></route-form> ></route-form>
@ -143,6 +146,7 @@ export default {
count: 0, count: 0,
dialogVisible: false, dialogVisible: false,
dialogSeq: 0, dialogSeq: 0,
formPrefill: null,
// //
matType: "30", matType: "30",
matKeyword: "", matKeyword: "",
@ -153,6 +157,7 @@ export default {
// 线 // 线
connectSource: null, connectSource: null,
connectMade: false, connectMade: false,
connectStartPos: null,
// //
hasFitted: false, hasFitted: false,
}; };
@ -284,9 +289,12 @@ export default {
if (pid) routeNodeIds.add(pid); if (pid) routeNodeIds.add(pid);
this.seedNodes = this.seedNodes.filter((s) => !routeNodeIds.has(s.id)); this.seedNodes = this.seedNodes.filter((s) => !routeNodeIds.has(s.id));
const prevCount = this.nodes.length;
this.edges = edges; this.edges = edges;
this.nodes = layoutGraph(routeNodes.concat(this.seedNodes), edges); this.nodes = layoutGraph(routeNodes.concat(this.seedNodes), edges);
this.syncStore(); this.syncStore();
// dagre 线
if (this.hasFitted && this.nodes.length !== prevCount) this.doFit();
}, },
/** 把本地 nodes/edges 命令式同步到 Vue Flow store先节点后边避免边找不到端点 */ /** 把本地 nodes/edges 命令式同步到 Vue Flow store先节点后边避免边找不到端点 */
@ -376,11 +384,18 @@ export default {
onConnectStart(params) { onConnectStart(params) {
this.connectSource = (params && (params.nodeId || params.source)) || null; this.connectSource = (params && (params.nodeId || params.source)) || null;
this.connectMade = false; this.connectMade = false;
const oe = params && params.event;
this.connectStartPos = oe && oe.clientX != null ? { x: oe.clientX, y: oe.clientY } : null;
}, },
/** 连到已有节点:新建一条 Route预填输入/输出物料 */ /** 连到已有节点:新建一条 Route预填输入/输出物料 */
onConnect(conn) { onConnect(conn) {
this.connectMade = true; this.connectMade = true;
if (this.readonly) return; if (this.readonly) return;
//
if (!conn.target || conn.target === conn.source) {
this.openAddFrom(conn.source);
return;
}
const src = this.nodes.find((n) => n.id === conn.source); const src = this.nodes.find((n) => n.id === conn.source);
const tgt = this.nodes.find((n) => n.id === conn.target); const tgt = this.nodes.find((n) => n.id === conn.target);
// id Number() // id Number()
@ -392,16 +407,28 @@ export default {
}); });
}, },
/** 拉线到空白处:新建工序,输出物料留空由后端自动生成下一节点 */ /** 拉线到空白处:新建工序,输出物料留空由后端自动生成下一节点 */
onConnectEnd() { onConnectEnd(evt) {
const src = this.connectSource; const src = this.connectSource;
const made = this.connectMade; const made = this.connectMade;
const startPos = this.connectStartPos;
this.connectSource = null; this.connectSource = null;
this.connectMade = false; this.connectMade = false;
this.connectStartPos = null;
if (this.readonly || made || !src) return; if (this.readonly || made || !src) return;
const node = this.nodes.find((n) => n.id === src); // ()线
const oe = evt && evt.clientX != null ? evt : evt && evt.event;
if (startPos && oe && oe.clientX != null) {
const dist = Math.hypot(oe.clientX - startPos.x, oe.clientY - startPos.y);
if (dist < 8) return;
}
this.openAddFrom(src);
},
/** 以某节点为输入新建工序:只带输入物料,其余字段一律默认值 */
openAddFrom(srcId) {
const node = this.nodes.find((n) => n.id === srcId);
// id // id
this.openForm("add", { this.openForm("add", {
material_in: src, material_in: srcId,
material_in_name: node ? node.data.label : "", material_in_name: node ? node.data.label : "",
}); });
}, },
@ -479,13 +506,13 @@ export default {
this.openForm("add", null); this.openForm("add", null);
}, },
/** 打开单步表单prefill 为 null 表示纯新增 */ /** 打开单步表单prefill 为 null 表示纯新增。预填经 prop 传入,在表单挂载 open 时一次性应用 */
openForm(mode, prefill) { openForm(mode, prefill) {
this.dialogSeq += 1; this.dialogSeq += 1;
this.formPrefill = prefill || null;
this.dialogVisible = true; this.dialogVisible = true;
this.$nextTick(() => { this.$nextTick(() => {
const inst = this.$refs.routeForm.open(mode); this.$refs.routeForm.open(mode);
if (prefill) inst.setData(prefill);
}); });
}, },

View File

@ -305,6 +305,8 @@ export default {
props: { props: {
count: { type: Number, default : 0 }, count: { type: Number, default : 0 },
routepack: { type: String, default: "" }, routepack: { type: String, default: "" },
// (线)setData
prefill: { type: Object, default: null },
}, },
emits: ["success", "closed"], emits: ["success", "closed"],
data() { data() {
@ -503,6 +505,7 @@ export default {
let that = this; let that = this;
that.mode = mode; that.mode = mode;
that.resetForm(); that.resetForm();
if (that.prefill) that.setData(that.prefill);
that.visible = true; that.visible = true;
that.$nextTick(() => { that.$nextTick(() => {
// setData sort // setData sort