This commit is contained in:
shijing 2026-07-28 16:14:30 +08:00
commit 349a650171
14 changed files with 591 additions and 127 deletions

View File

@ -188,6 +188,12 @@ export default {
return await http.get( `${config.API_URL}/wf/ticket/${id}/transitions/`);
}
},
ticketAvailableActions: {
name: "获取当前用户可执行的工单操作",
req: async function(id){
return await http.get(`${config.API_URL}/wf/ticket/${id}/available_actions/`);
}
},
dutyAgg: {
url: `${config.API_URL}/wf/ticket/duty_agg/`,
name: "待办审批聚合",

View File

@ -0,0 +1,92 @@
<template>
<BaseEdge
:id="id"
:path="edgePath"
:marker-end="markerEnd"
:style="style"
:interaction-width="20"
/>
<EdgeLabelRenderer v-if="label">
<div
class="dagre-edge-label nodrag nopan"
:style="{
transform: `translate(-50%, -50%) translate(${labelPoint.x}px, ${labelPoint.y}px)`,
color: labelStyle && labelStyle.fill,
fontSize: labelStyle && labelStyle.fontSize,
fontWeight: labelStyle && labelStyle.fontWeight,
}"
>
{{ label }}
</div>
</EdgeLabelRenderer>
</template>
<script>
import { BaseEdge, EdgeLabelRenderer } from "@vue-flow/core";
import { curveCatmullRom, line } from "d3";
export default {
name: "DagreEdge",
components: { BaseEdge, EdgeLabelRenderer },
props: {
id: { type: String, required: true },
sourceX: { type: Number, required: true },
sourceY: { type: Number, required: true },
targetX: { type: Number, required: true },
targetY: { type: Number, required: true },
data: { type: Object, default: () => ({}) },
label: { type: [String, Number], default: "" },
markerEnd: { type: String, default: "" },
style: { type: Object, default: () => ({}) },
labelStyle: { type: Object, default: () => ({}) },
},
computed: {
points() {
const routed = this.data.dagrePoints || [];
const points = [
{ x: this.sourceX, y: this.sourceY },
...routed.slice(1, -1),
{ x: this.targetX, y: this.targetY },
];
const label = this.data.dagreLabel;
if (!label || points.some((point) => Math.abs(point.x - label.x) < 1 && Math.abs(point.y - label.y) < 1)) {
return points;
}
// TB y 线线穿
const insertAt = points.findIndex((point, index) => index > 0 && point.y >= label.y);
points.splice(insertAt > 0 ? insertAt : Math.ceil(points.length / 2), 0, label);
return points;
},
edgePath() {
return (
line()
.x((point) => point.x)
.y((point) => point.y)
.curve(curveCatmullRom.alpha(0.8))(this.points) || ""
);
},
labelPoint() {
if (this.data.dagreLabel) return this.data.dagreLabel;
const middle = this.points[Math.floor(this.points.length / 2)];
return middle || { x: (this.sourceX + this.targetX) / 2, y: (this.sourceY + this.targetY) / 2 };
},
},
};
</script>
<style scoped>
.dagre-edge-label {
position: absolute;
z-index: 1;
max-width: 190px;
padding: 5px 9px;
border: 1px solid #e4e7ed;
border-radius: 7px;
background: rgba(255, 255, 255, 0.96);
box-shadow: 0 1px 3px rgba(31, 45, 61, 0.08);
line-height: 1.25;
text-align: center;
white-space: normal;
pointer-events: all;
}
</style>

View File

@ -1,9 +1,27 @@
<template>
<div class="mnode" :class="'mnode--' + (data.kind || 'mid')">
<Handle type="target" :position="Position.Top" class="mnode__handle" />
<Handle
v-for="port in data.targetPorts || []"
:key="port.id"
:id="port.id"
type="target"
:position="Position.Top"
:style="{ left: port.left + '%' }"
class="mnode__handle mnode__route-handle"
/>
<span class="mnode__tag">{{ kindLabel }}</span>
<div class="mnode__name" :title="data.label">{{ data.label }}</div>
<Handle type="source" :position="Position.Bottom" class="mnode__handle" />
<Handle
v-for="port in data.sourcePorts || []"
:key="port.id"
:id="port.id"
type="source"
:position="Position.Bottom"
:style="{ left: port.left + '%' }"
class="mnode__handle mnode__route-handle"
/>
</div>
</template>
@ -64,6 +82,10 @@ export default {
-webkit-box-orient: vertical;
overflow: hidden;
}
.mnode__route-handle {
opacity: 0;
pointer-events: none;
}
.mnode--raw {
border-color: #f0c78a;
background: #fffaf2;
@ -95,12 +117,29 @@ export default {
padding: 0;
}
.vue-flow__handle {
display: flex;
align-items: center;
justify-content: center;
width: 56px;
height: 56px;
border-radius: 50%;
background: transparent;
border: 0;
cursor: crosshair;
}
.vue-flow__handle::after {
content: "";
width: 9px;
height: 9px;
background: #fff;
border: 2px solid #409eff;
border-radius: 50%;
background: #fff;
transition: width 0.15s, height 0.15s, background 0.15s, box-shadow 0.15s;
}
.vue-flow__handle:hover {
.vue-flow__handle:hover::after {
width: 13px;
height: 13px;
background: #409eff;
box-shadow: 0 0 0 4px rgba(64, 158, 255, 0.18);
}
</style>

View File

@ -7,18 +7,114 @@ export const NODE_H = 54;
* dagre 自动布局返回带 position nodes
* @param {Array} nodes Vue Flow 节点id 必须为字符串
* @param {Array} edges Vue Flow
* @param {Object} opts { rankdir: TB|BT|LR|RL, nodeW, nodeH }
* @param {Object} opts { rankdir: TB|BT|LR|RL, nodeW, nodeH, nodesep, edgesep, ranksep, marginx, marginy }
*/
export function layoutGraph(nodes, edges, opts = {}) {
const { rankdir = "TB", nodeW = NODE_W, nodeH = NODE_H } = opts;
const g = new dagre.graphlib.Graph();
g.setGraph({ rankdir, nodesep: 30, ranksep: 56, marginx: 20, marginy: 20 });
return layoutGraphWithEdges(nodes, edges, opts).nodes;
}
/**
* dagre 同时计算节点位置边的绕行点和标签位置
* Vue Flow 默认边只使用节点坐标会让跨层边穿过节点因此查看/编辑视图使用此完整结果
*/
export function layoutGraphWithEdges(nodes, edges, opts = {}) {
const {
rankdir = "TB",
nodeW = NODE_W,
nodeH = NODE_H,
nodesep = 30,
edgesep = 20,
ranksep = 56,
marginx = 20,
marginy = 20,
} = opts;
const g = new dagre.graphlib.Graph({ multigraph: true });
g.setGraph({ rankdir, nodesep, edgesep, ranksep, marginx, marginy });
g.setDefaultEdgeLabel(() => ({}));
nodes.forEach((n) => g.setNode(n.id, { width: nodeW, height: nodeH }));
edges.forEach((e) => g.setEdge(e.source, e.target));
const parallelCount = new Map();
const edgeRefs = [];
edges.forEach((e, index) => {
const key = `${e.source}->${e.target}`;
const parallelIndex = parallelCount.get(key) || 0;
parallelCount.set(key, parallelIndex + 1);
// 参考原 dagre-d3基础边跨 2 个 rank同组边逐条增加长度。
const minlen = e.layoutMinlen || 2 + parallelIndex;
const name = `route-${index}`;
const labelWidth = e.label ? Math.min(190, Math.max(56, String(e.label).length * 13 + 20)) : 0;
g.setEdge(
e.source,
e.target,
{
minlen,
width: labelWidth,
height: e.label ? 30 : 0,
// 标签位于工序线本身;平行边已由独立锚点和 dagre edgesep 分开。
labelpos: "c",
labeloffset: 0,
},
name
);
edgeRefs.push({ v: e.source, w: e.target, name });
});
dagre.layout(g);
return nodes.map((n) => {
const laidOutNodes = nodes.map((n) => {
const gn = g.node(n.id);
return { ...n, position: { x: gn.x - nodeW / 2, y: gn.y - nodeH / 2 } };
});
const laidOutEdges = edges.map((edge, index) => {
const ge = g.edge(edgeRefs[index]) || {};
return {
...edge,
data: {
...edge.data,
dagrePoints: ge.points || [],
dagreLabel: Number.isFinite(ge.x) && Number.isFinite(ge.y) ? { x: ge.x, y: ge.y } : null,
},
};
});
return { nodes: laidOutNodes, edges: laidOutEdges };
}
/**
* 为每条边分配独立的节点锚点避免多条工序共用中心 Handle 产生重叠
* 同一节点上的锚点按相邻节点横坐标排序可同时减少分支交叉
*/
export function assignEdgePorts(nodes, edges) {
const nodeMap = new Map(nodes.map((node) => [node.id, node]));
const outgoing = new Map();
const incoming = new Map();
const routedEdges = edges.map((edge, index) => {
const sourceHandle = `route-out-${index}`;
const targetHandle = `route-in-${index}`;
if (!outgoing.has(edge.source)) outgoing.set(edge.source, []);
if (!incoming.has(edge.target)) incoming.set(edge.target, []);
outgoing.get(edge.source).push({ edgeIndex: index, handleId: sourceHandle, neighborId: edge.target });
incoming.get(edge.target).push({ edgeIndex: index, handleId: targetHandle, neighborId: edge.source });
return { ...edge, sourceHandle, targetHandle };
});
const getCenterX = (id) => {
const node = nodeMap.get(id);
return node ? node.position.x + NODE_W / 2 : 0;
};
const makePorts = (items = []) =>
[...items]
.sort((a, b) => getCenterX(a.neighborId) - getCenterX(b.neighborId) || a.edgeIndex - b.edgeIndex)
.map((item, index, list) => ({
id: item.handleId,
left: ((index + 1) * 100) / (list.length + 1),
}));
const routedNodes = nodes.map((node) => ({
...node,
data: {
...node.data,
sourcePorts: makePorts(outgoing.get(node.id)),
targetPorts: makePorts(incoming.get(node.id)),
},
}));
return { nodes: routedNodes, edges: routedEdges };
}

View File

@ -13,7 +13,7 @@
<el-table v-bind="$attrs" :data="tableData" :row-key="rowKey || undefined" :key="toggleIndex" ref="scTable"
:height="height == 'auto' ? null : '100%'" :size="config.size" :border="config.border" :stripe="config.stripe"
:summary-method="remoteSummary ? remoteSummaryMethod : summaryMethod" :expand-row-keys="rowKey ? expandRowKeys : undefined" @sort-change="sortChange"
@filter-change="filterChange" @selection-change="selectionChange">
@filter-change="filterChange" @selection-change="selectionChange" @expand-change="handleExpandChange">
<slot></slot>
<template v-for="(item, index) in userColumn" :key="index">
<el-table-column v-if="!item.hide" :column-key="item.prop" :label="item.label" :prop="item.prop"
@ -563,16 +563,19 @@ export default {
},
// /
toggleExpandAll() {
const isExpandAll = this.expandRowKeys.length === this.tableData.length;
const rows = this.tableData || [];
const key = this.rowKey || "id";
const isExpandAll = rows.length > 0 && rows.every(item => this.expandRowKeys.includes(item[key]));
if (isExpandAll) {
this.expandRowKeys = []; //
} else {
this.expandRowKeys = this.tableData.map(item => item.id); //
this.expandRowKeys = rows.map(item => item[key]); //
}
},
// expandRowKeys
handleExpandChange(row, expandedRows) {
this.expandRowKeys = expandedRows.map(row => row.id); //
const key = this.rowKey || "id";
this.expandRowKeys = expandedRows.map(item => item[key]); //
}
},
};

View File

@ -5,7 +5,7 @@
<div class="flow-toolbar__left">
<el-button v-if="!readonly" type="primary" icon="el-icon-plus" size="small" round @click="addStep">新增工序</el-button>
<el-button icon="el-icon-magic-stick" size="small" round @click="relayout">自动布局</el-button>
<el-button icon="el-icon-full-screen" size="small" round @click="doFit">适应画布</el-button>
<el-button icon="el-icon-full-screen" size="small" round @click="fitToWidth">适应宽度</el-button>
<el-button icon="el-icon-circle-check" size="small" round @click="doValidate" :loading="validating">校验</el-button>
</div>
<div class="flow-legend">
@ -55,13 +55,15 @@
</div>
<!-- 画布 -->
<div class="flow-canvas" @drop="onDrop" @dragover.prevent>
<div ref="canvas" class="flow-canvas" @drop="onDrop" @dragover.prevent>
<VueFlow
:id="flowId"
:default-viewport="{ zoom: 0.9 }"
:min-zoom="0.2"
:max-zoom="2"
:connection-radius="8"
:pan-on-scroll="true"
:zoom-on-scroll="false"
:connection-radius="56"
:connect-on-click="false"
:nodes-draggable="true"
:nodes-connectable="!readonly"
@ -78,6 +80,9 @@
<template #node-material="{ data }">
<material-node :data="data" />
</template>
<template #edge-dagre="edgeProps">
<dagre-edge v-bind="edgeProps" />
</template>
<Background :gap="18" pattern-color="#e6e9ef" />
<Controls :show-interactive="false" />
@ -108,8 +113,9 @@ import { VueFlow, useVueFlow } from "@vue-flow/core";
import { Background } from "@vue-flow/background";
import { Controls } from "@vue-flow/controls";
import routeForm from "@/views/mtm/route_form.vue";
import DagreEdge from "./flow/DagreEdge.vue";
import MaterialNode from "./flow/MaterialNode.vue";
import { layoutGraph } from "./flow/dagreLayout";
import { assignEdgePorts, layoutGraphWithEdges, NODE_W } from "./flow/dagreLayout";
import "@vue-flow/core/dist/style.css";
import "@vue-flow/core/dist/theme-default.css";
import "@vue-flow/controls/dist/style.css";
@ -119,7 +125,7 @@ let flowSeq = 0;
export default {
name: "xtFlowEditor",
components: { VueFlow, Background, Controls, routeForm, MaterialNode },
components: { VueFlow, Background, Controls, routeForm, DagreEdge, MaterialNode },
props: {
// id
routepack: { type: String, default: "" },
@ -132,9 +138,9 @@ export default {
emits: ["changed"],
setup() {
const flowId = "route-flow-editor-" + ++flowSeq;
const { fitView, screenToFlowCoordinate, project, setNodes, setEdges, addNodes, removeNodes } =
const { setViewport, screenToFlowCoordinate, project, setNodes, setEdges, addNodes, removeNodes } =
useVueFlow(flowId);
return { flowId, fitView, screenToFlowCoordinate, project, setNodes, setEdges, addNodes, removeNodes };
return { flowId, setViewport, screenToFlowCoordinate, project, setNodes, setEdges, addNodes, removeNodes };
},
data() {
return {
@ -160,6 +166,8 @@ export default {
connectStartPos: null,
//
hasFitted: false,
resizeObserver: null,
resizeTimer: null,
};
},
computed: {
@ -180,6 +188,19 @@ export default {
mounted() {
this.loadMaterials();
if (this.routepack) this.reload();
if (typeof ResizeObserver !== "undefined") {
this.resizeObserver = new ResizeObserver(() => {
clearTimeout(this.resizeTimer);
this.resizeTimer = setTimeout(() => {
if (this.hasFitted) this.fitToWidth(false);
}, 80);
});
this.resizeObserver.observe(this.$refs.canvas);
}
},
beforeUnmount() {
if (this.resizeObserver) this.resizeObserver.disconnect();
clearTimeout(this.resizeTimer);
},
methods: {
/** 加载左侧物料面板列表 */
@ -252,11 +273,11 @@ export default {
target: tid,
label: (r.process_name || "") + (locked ? " 🔒" : ""),
data: { route: r, locked },
type: "smoothstep",
type: "dagre",
markerEnd: "arrowclosed",
style: {
stroke: locked ? "#c0c4cc" : "#409eff",
strokeWidth: locked ? 1.5 : 2,
strokeWidth: locked ? 1.7 : 2.2,
strokeDasharray: locked ? "5 4" : undefined,
},
labelStyle: { fill: "#5b6370", fontSize: "12px", fontWeight: 500 },
@ -290,11 +311,24 @@ export default {
this.seedNodes = this.seedNodes.filter((s) => !routeNodeIds.has(s.id));
const prevCount = this.nodes.length;
this.edges = edges;
this.nodes = layoutGraph(routeNodes.concat(this.seedNodes), edges);
const routedGraph = this.layoutAndRoute(routeNodes.concat(this.seedNodes), edges);
this.nodes = routedGraph.nodes;
this.edges = routedGraph.edges;
this.syncStore();
// dagre 线
if (this.hasFitted && this.nodes.length !== prevCount) this.doFit();
if (this.hasFitted && this.nodes.length !== prevCount) this.fitToWidth();
},
/** 编辑与查看使用一致的 dagre-d3 布局参数,并保留边绕行点 */
layoutAndRoute(nodes, edges) {
const laidOutGraph = layoutGraphWithEdges(nodes, edges, {
nodesep: 40,
edgesep: 25,
ranksep: 20,
marginx: 80,
marginy: 10,
});
return assignEdgePorts(laidOutGraph.nodes, laidOutGraph.edges);
},
/** 把本地 nodes/edges 命令式同步到 Vue Flow store先节点后边避免边找不到端点 */
@ -306,15 +340,36 @@ export default {
/** 重新布局并适应画布 */
relayout() {
this.nodes = layoutGraph([...this.nodes], this.edges);
const routedGraph = this.layoutAndRoute([...this.nodes], this.edges);
this.nodes = routedGraph.nodes;
this.edges = routedGraph.edges;
this.setNodes(this.nodes);
this.doFit();
this.setEdges(this.edges);
this.fitToWidth();
},
doFit() {
/** 按宽度保持节点可读,长流程通过滚轮或拖动画布纵向浏览 */
fitToWidth(animated = true) {
this.$nextTick(() => {
try {
this.fitView({ padding: 0.25, maxZoom: 1, duration: 300 });
const canvas = this.$refs.canvas;
if (!canvas || !this.nodes.length) return;
const xs = this.nodes.map((n) => n.position.x);
const ys = this.nodes.map((n) => n.position.y);
const minX = Math.min(...xs);
const maxX = Math.max(...xs) + NODE_W;
const minY = Math.min(...ys);
const paddingX = 48;
const paddingTop = 36;
const graphWidth = Math.max(maxX - minX, NODE_W);
const zoom = Math.min(1, Math.max(0.2, (canvas.clientWidth - paddingX * 2) / graphWidth));
const x = (canvas.clientWidth - graphWidth * zoom) / 2 - minX * zoom;
const y = paddingTop - minY * zoom;
this.setViewport(
{ x, y, zoom },
{ duration: animated && this.hasFitted ? 200 : 0 }
);
this.hasFitted = true;
} catch (e) {
/* noop */
}
@ -325,8 +380,7 @@ export default {
onNodesInit() {
if (this.hasFitted) return;
if (this.nodes.length === 0) return;
this.hasFitted = true;
this.doFit();
this.fitToWidth();
},
/* ============ 左侧面板拖拽入画布 ============ */

View File

@ -3,7 +3,7 @@
<!-- 顶部工具栏 xtFlowEditor 视觉一致 -->
<div class="flow-toolbar">
<div class="flow-toolbar__left">
<el-button icon="el-icon-full-screen" size="small" round @click="doFit">适应画布</el-button>
<el-button icon="el-icon-full-screen" size="small" round @click="fitToWidth">适应宽度</el-button>
</div>
<div class="flow-legend">
<span class="lg lg--raw">原料</span>
@ -11,11 +11,13 @@
<span class="lg lg--final">成品</span>
</div>
</div>
<div class="flow-canvas">
<div ref="canvas" class="flow-canvas">
<VueFlow
:id="flowId"
:min-zoom="0.2"
:max-zoom="2"
:pan-on-scroll="true"
:zoom-on-scroll="false"
:nodes-draggable="false"
:nodes-connectable="false"
:elements-selectable="false"
@ -24,6 +26,9 @@
<template #node-material="{ data }">
<material-node :data="data" />
</template>
<template #edge-dagre="edgeProps">
<dagre-edge v-bind="edgeProps" />
</template>
<Background :gap="18" pattern-color="#e6e9ef" />
<Controls :show-interactive="false" />
</VueFlow>
@ -39,8 +44,9 @@
import { VueFlow, useVueFlow } from "@vue-flow/core";
import { Background } from "@vue-flow/background";
import { Controls } from "@vue-flow/controls";
import DagreEdge from "./flow/DagreEdge.vue";
import MaterialNode from "./flow/MaterialNode.vue";
import { layoutGraph } from "./flow/dagreLayout";
import { assignEdgePorts, layoutGraphWithEdges, NODE_W } from "./flow/dagreLayout";
import "@vue-flow/core/dist/style.css";
import "@vue-flow/core/dist/theme-default.css";
import "@vue-flow/controls/dist/style.css";
@ -54,7 +60,7 @@ let viewerSeq = 0;
*/
export default {
name: "xtFlowViewer",
components: { VueFlow, Background, Controls, MaterialNode },
components: { VueFlow, Background, Controls, DagreEdge, MaterialNode },
props: {
nodes: { type: Array, default: () => [] },
edges: { type: Array, default: () => [] },
@ -62,14 +68,17 @@ export default {
},
setup() {
const flowId = "xt-flow-viewer-" + ++viewerSeq;
const { fitView, setNodes, setEdges } = useVueFlow(flowId);
return { flowId, fitView, setNodes, setEdges };
const { setViewport, setNodes, setEdges } = useVueFlow(flowId);
return { flowId, setViewport, setNodes, setEdges };
},
data() {
return {
// fit
hasFitted: false,
rebuildPending: false,
renderedNodes: [],
resizeObserver: null,
resizeTimer: null,
};
},
computed: {
@ -87,6 +96,19 @@ export default {
},
mounted() {
this.rebuild();
if (typeof ResizeObserver !== "undefined") {
this.resizeObserver = new ResizeObserver(() => {
clearTimeout(this.resizeTimer);
this.resizeTimer = setTimeout(() => {
if (this.hasFitted) this.fitToWidth(false);
}, 80);
});
this.resizeObserver.observe(this.$refs.canvas);
}
},
beforeUnmount() {
if (this.resizeObserver) this.resizeObserver.disconnect();
clearTimeout(this.resizeTimer);
},
methods: {
/** nodes/edges 通常被先后赋值,用微任务合并成一次 rebuild避免双次 dagre 布局 */
@ -104,19 +126,19 @@ export default {
const targetIds = new Set();
const rawEdges = (this.edges || [])
.filter((e) => e.source != null && e.target != null)
.map((e) => {
.map((e, index) => {
const sid = String(e.source);
const tid = String(e.target);
sourceIds.add(sid);
targetIds.add(tid);
return {
id: e.id != null ? String(e.id) : sid + "-" + tid,
id: e.id != null ? String(e.id) : `${sid}-${tid}-${edgeIndex}`,
source: sid,
target: tid,
label: e.label || "",
type: "smoothstep",
type: "dagre",
markerEnd: "arrowclosed",
style: { stroke: "#409eff", strokeWidth: 2 },
style: { stroke: "#409eff", strokeWidth: 2.2 },
labelStyle: { fill: "#5b6370", fontSize: "12px", fontWeight: 500 },
labelBgStyle: { fill: "#ffffff", stroke: "#e4e7ed", strokeWidth: 1 },
labelBgPadding: [7, 4],
@ -137,19 +159,49 @@ export default {
const nodeIds = new Set(vNodes.map((n) => n.id));
const vEdges = rawEdges.filter((e) => nodeIds.has(e.source) && nodeIds.has(e.target));
const laidOutGraph = layoutGraphWithEdges(vNodes, vEdges, {
rankdir: this.rankdir,
nodesep: 40,
edgesep: 25,
ranksep: 20,
marginx: 80,
marginy: 10,
});
const routedGraph = assignEdgePorts(laidOutGraph.nodes, laidOutGraph.edges);
this.renderedNodes = routedGraph.nodes;
this.setEdges([]);
this.setNodes(layoutGraph(vNodes, vEdges, { rankdir: this.rankdir }));
this.setEdges(vEdges);
// nodes-initialized fit fit
if (this.hasFitted) this.doFit();
this.setNodes(this.renderedNodes);
this.setEdges(routedGraph.edges);
// nodes-initialized
if (this.hasFitted) this.fitToWidth();
},
onNodesInit() {
this.doFit();
this.fitToWidth();
},
doFit() {
/**
* 只按宽度缩放长流程不再为了塞进高度而缩成缩略图
* 图从画布顶部开始展示用户可拖动画布继续向下查看
*/
fitToWidth(animated = true) {
this.$nextTick(() => {
try {
this.fitView({ padding: 0.2, maxZoom: 1, duration: this.hasFitted ? 200 : 0 });
const canvas = this.$refs.canvas;
if (!canvas || !this.renderedNodes.length) return;
const xs = this.renderedNodes.map((n) => n.position.x);
const ys = this.renderedNodes.map((n) => n.position.y);
const minX = Math.min(...xs);
const maxX = Math.max(...xs) + NODE_W;
const minY = Math.min(...ys);
const paddingX = 48;
const paddingTop = 36;
const graphWidth = Math.max(maxX - minX, NODE_W);
const zoom = Math.min(1, Math.max(0.2, (canvas.clientWidth - paddingX * 2) / graphWidth));
const x = (canvas.clientWidth - graphWidth * zoom) / 2 - minX * zoom;
const y = paddingTop - minY * zoom;
this.setViewport(
{ x, y, zoom },
{ duration: animated && this.hasFitted ? 200 : 0 }
);
this.hasFitted = true;
} catch (e) {
/* noop */

View File

@ -59,14 +59,9 @@
</el-tag>
</template>
</el-table-column>
<el-table-column label="交接到工段">
<el-table-column label="产出库存归属">
<template #default="scope">
<el-tag type="success" v-if="scope.row.into_wm_mgroup">
</el-tag>
<!-- <el-icon v-if="scope.row.into_wm_mgroup" color="green">
<CircleCheckFilled />
</el-icon> -->
{{ wmScopes[scope.row.into_wm_scope] }}
</template>
</el-table-column>
<el-table-column label="不合格品是否入库">
@ -211,6 +206,11 @@ export default {
20:'切分',
30:'结合'
},
wmScopes:{
10:'工段',
20:'部门',
30:'全局'
},
currentItem:{},
selectValue:[],
visible:false,

View File

@ -84,10 +84,15 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="交接到工段">
<el-switch
v-model="form.into_wm_mgroup"
></el-switch>
<el-form-item label="产出库存归属">
<el-select v-model="form.into_wm_scope">
<el-option
v-for="item in wmScopeOptions"
:key="item.value"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
@ -133,7 +138,7 @@ const defaultForm = {
mtype:10,
belong_dept: "",
wpr_number_rule: "",
into_wm_mgroup: true,
into_wm_scope: 20,
store_notok: true,
has_ok_b_defect:false,
};
@ -165,6 +170,11 @@ export default {
{name:'切分',value:20},
{name:'结合',value:30},
],
wmScopeOptions:[
{name:'工段',value:10},
{name:'部门',value:20},
{name:'全局',value:30},
],
visible: false,
isSaveing: false,
deptOptions: [],

View File

@ -13,6 +13,7 @@
ref="dialogForm"
:model="form"
:rules="rules"
:disabled="mode === 'show'"
label-position="right"
label-width="100px"
>
@ -197,7 +198,7 @@
</el-col>
<el-col>
<el-form-item label="工艺图纸">
<sc-upload-multiple v-model="fileurl" @imagesDel="imagesDel" @imagesChange="imagesChange" draggable :limit="9" tip="最多上传9个文件,单个文件不要超过10M,请上传图像格式文件"></sc-upload-multiple>
<sc-upload-multiple v-model="fileurl" @imagesDel="imagesDel" @imagesChange="imagesChange" draggable :disabled="mode === 'show'" :limit="9" tip="最多上传9个文件,单个文件不要超过10M,请上传图像格式文件"></sc-upload-multiple>
</el-form-item>
</el-col>
</el-row>
@ -226,9 +227,10 @@
</el-form-item>
</el-col>
</el-row>
<el-row v-if="project_code=='bxerp'&&mode=='edit'">
<el-row v-if="project_code=='bxerp'&&(mode=='edit'||mode=='show')">
<sc-form-table
hideDelete
:hideAdd="mode === 'show'"
ref="routematTable"
:tableHeight="300"
v-model="routemats"
@ -253,7 +255,7 @@
</el-select>
</template>
</el-table-column>
<el-table-column prop="open" label="操作" width="125" align="center">
<el-table-column v-if="mode !== 'show'" prop="open" label="操作" width="125" align="center">
<template #default="scope">
<el-button
text
@ -279,8 +281,8 @@
</el-form>
</el-main>
<el-footer>
<el-button type="primary" :loading="isSaveing" @click="submit">提交</el-button>
<el-button @click="visible = false">取消</el-button>
<el-button v-if="mode !== 'show'" type="primary" :loading="isSaveing" @click="submit">提交</el-button>
<el-button @click="visible = false">{{ mode === "show" ? "关闭" : "取消" }}</el-button>
</el-footer>
</el-container>
</el-dialog>
@ -347,7 +349,7 @@ export default {
fileurl_form:[],
paramsJsonFileurl:[],
materialOptions:[],
titleMap: { add: "新增", edit: "编辑" },
titleMap: { add: "新增", edit: "编辑", show: "工序详情" },
setFiltersVisible: false,
routeId: "",
processName: "",
@ -505,6 +507,9 @@ export default {
let that = this;
that.mode = mode;
that.resetForm();
if (that.project_code == "bxerp" && (mode === "edit" || mode === "show")) {
that.getMaterialOptions();
}
if (that.prefill) that.setData(that.prefill);
that.visible = true;
that.$nextTick(() => {

View File

@ -22,10 +22,9 @@
<div class="rs-card__title">工艺路线流程图</div>
<el-tabs v-if="tabsTitle.length > 1" v-model="activeName" class="rs-tabs"
@tab-click="tabshandleClick">
<el-tab-pane :label="item" v-for="item in tabsTitle" :key="item"></el-tab-pane>
<el-tab-pane :label="item" :name="item" v-for="item in tabsTitle" :key="item"></el-tab-pane>
</el-tabs>
<xtFlowViewer v-if="limitedWatch" :nodes="nodes" :edges="edges" class="rs-flow__canvas"
style="min-height: 0">
<xtFlowViewer :nodes="nodes" :edges="edges" class="rs-flow__canvas">
</xtFlowViewer>
</div>
@ -33,7 +32,17 @@
<div class="rs-card rs-steps">
<div class="rs-card__title">工序步骤</div>
<div class="rs-steps__table">
<scTable ref="tables" :data="tableData" row-key="id" hidePagination hideDo stripe border>
<scTable
ref="tables"
:data="tableData"
row-key="id"
hidePagination
hideDo
stripe
border
class="rs-steps__clickable"
@row-click="showStepDetail"
>
<el-table-column label="排序" prop="sort" width="50">
</el-table-column>
<el-table-column label="工序" prop="process_name">
@ -58,6 +67,13 @@
<el-tag v-if="scope.row.batch_bind" type="success"></el-tag>
</template>
</el-table-column>
<el-table-column label="操作" fixed="right" width="64">
<template #default="scope">
<el-link type="primary" :underline="false" @click.stop="showStepDetail(scope.row)">
查看
</el-link>
</template>
</el-table-column>
</scTable>
</div>
</div>
@ -66,16 +82,16 @@
<el-aside width="20%" v-if="form.ticket" class="rs-aside">
<ticketd :ticket_="form.ticket_"></ticketd>
</el-aside>
<route-form ref="routeDetail" :routepack="form.id || ''"></route-form>
</el-container>
</template>
<script>
import { defineAsyncComponent } from "vue";
import ticketd from '@/views/wf/ticketd.vue'
// Vue Flow
const xtFlowViewer = defineAsyncComponent(() => import(/* webpackPrefetch: true */ "@/components/xtFlowViewer.vue"));
import xtFlowViewer from "@/components/xtFlowViewer.vue";
import RouteForm from "./route_form.vue";
export default {
emits: ["success", "closed"],
components: { ticketd, xtFlowViewer },
components: { ticketd, xtFlowViewer, RouteForm },
props: {
t_id: { type: String, default: null },
},
@ -104,7 +120,6 @@ export default {
tableData: [],
project_code: "",
activeName: "总图",
limitedWatch: false,
};
},
mounted() {
@ -124,6 +139,11 @@ export default {
setData(data) {
let that = this;
Object.assign(that.form, data);
that.nodes = [];
that.edges = [];
that.tabsTitle = ['总图'];
that.tabsData = {};
that.activeName = "总图";
that.getRoute(that.form.material);
that.getDEGdatas(data.id);
this.getTabsList(data.id);
@ -135,11 +155,10 @@ export default {
getDEGdatas(id) {
let that = this;
that.$API.mtm.routepack.dag.req(id).then((res) => {
that.nodes = res.nodes;
that.edges = res.edges;
that.tabsData['总图'] = res;
if (!that.limitedWatch) {
that.limitedWatch = true;
//
if (that.activeName === "总图") {
that.showGraph(res);
}
})
},
@ -156,9 +175,16 @@ export default {
that.tabsData[res[key].name] = res[key];
}
}
console.log(that.tabsData);
const activeGraph = that.tabsData[that.activeName];
if (activeGraph) {
that.showGraph(activeGraph);
}
})
},
showGraph(graph) {
this.nodes = graph?.nodes || [];
this.edges = graph?.edges || [];
},
//
getRoute(id) {
this.$API.mtm.route.list
@ -168,12 +194,15 @@ export default {
});
},
tabshandleClick(val) {
let that = this;
let label = val.props.label;
that.$nextTick(() => {
that.nodes = that.tabsData[label].nodes;
that.edges = that.tabsData[label].edges;
})
const graph = this.tabsData[val.props.name || val.props.label];
if (graph) {
this.showGraph(graph);
}
},
async showStepDetail(row) {
if (!row || !row.id) return;
const detail = await this.$API.mtm.route.item.req(row.id);
this.$refs.routeDetail.open("show").setData(detail);
},
},
};
@ -254,11 +283,19 @@ export default {
}
.rs-flow__canvas {
flex: 1;
min-height: 0;
min-height: 320px;
}
.rs-tabs {
/* el-tabs 的空 content 默认会 flex-grow多个流程图时会把下方画布挤出可视区 */
flex: 0 0 auto;
height: auto;
}
.rs-tabs :deep(.el-tabs__header) {
margin: 0 0 8px;
}
.rs-tabs :deep(.el-tabs__content) {
display: none;
}
.rs-steps {
flex: 1;
min-width: 0;
@ -270,6 +307,9 @@ export default {
flex: 1;
min-height: 0;
}
.rs-steps__clickable :deep(.el-table__row) {
cursor: pointer;
}
/* 右侧工单/审批面板:与主体同底色,间距交给 ticketd 自身的内边距 */
.rs-aside {
background: #f5f7fa;

View File

@ -1,4 +1,12 @@
<template>
<el-button
v-if="needAccept"
type="success"
:loading="isAccepting"
:disabled="isAccepting"
@click="acceptTicket"
style="margin-right: 2px"
>接单</el-button>
<span v-if="actionShow"><el-button
v-for="item in transitions"
:key="item.id"
@ -17,10 +25,9 @@
</el-dialog>
</template>
<script setup>
import { ref, reactive, onMounted, defineEmits,watch } from 'vue'
import { ref, defineEmits, watch } from 'vue'
import { ElMessage } from 'element-plus'
import API from '@/api';
import TOOL from "@/utils/tool.js";
const props = defineProps({
@ -34,44 +41,53 @@ const props = defineProps({
const workflow = ref(null);
const transitions = ref([]);
let lastInitTicketId = null;
const tryInit = () => {
// ticket_ ticket_.id
let lastInitKey = null;
let requestVersion = 0;
const getInitKey = () => {
if (props.ticket_ && props.ticket_.id) {
if (lastInitTicketId !== props.ticket_.id) {
lastInitTicketId = props.ticket_.id;
init();
}
return;
return [
'ticket',
props.ticket_.id,
props.ticket_.state,
JSON.stringify(props.ticket_.participant),
props.ticket_.update_time,
].join(':');
}
// ticket_退 workflow_key
if (props.workflow_key) {
if (lastInitTicketId !== '__wf_key__:' + props.workflow_key) {
lastInitTicketId = '__wf_key__:' + props.workflow_key;
init();
}
return `workflow:${props.workflow_key}`;
}
return null;
};
const tryInit = () => {
const initKey = getInitKey();
if (initKey && lastInitKey !== initKey) {
lastInitKey = initKey;
init();
}
};
onMounted(() => { tryInit(); });
watch(() => props.ticket_, () => { tryInit(); }, { deep: true });
watch(() => props.workflow_key, () => { tryInit(); });
const ticketId = ref(null);
const actionShow = ref(false);
const needAccept = ref(false);
const init = async () => {
const currentRequestVersion = ++requestVersion;
actionShow.value = false;
needAccept.value = false;
transitions.value = [];
if (props.ticket_ && props.ticket_.id) {
ticketId.value = props.ticket_.id;
const isParticipant =
(props.ticket_.participant_type === 1 && props.ticket_.participant === currentUser.value) ||
(props.ticket_.participant_type === 2 && props.ticket_.participant.includes(currentUser.value))
if (isParticipant) {
actionShow.value = true;
transitions.value = await API.wf.ticket.ticketTransitions.req(ticketId.value);
const actionInfo = await API.wf.ticket.ticketAvailableActions.req(ticketId.value);
if (currentRequestVersion !== requestVersion) {
return;
}
needAccept.value = actionInfo.need_accept;
actionShow.value = actionInfo.permission;
transitions.value = actionInfo.transitions;
}else if (props.workflow_key !=null && props.workflow_key != undefined) {
let res = await API.wf.workflow.initkey.req(props.workflow_key);
if (currentRequestVersion !== requestVersion) {
return;
}
actionShow.value = true
transitions.value = res.transitions;
workflow.value = res.workflow
@ -79,11 +95,35 @@ const init = async () => {
ElMessage.error("缺少workflow_key或ticketId");
}
}
const currentUser = ref(TOOL.data.get("USER_INFO").id)
// immediate watcher init
// const init
watch(
() => [
props.ticket_?.id,
props.ticket_?.state,
props.ticket_?.participant,
props.ticket_?.update_time,
props.workflow_key,
],
tryInit,
{ deep: true, immediate: true },
);
const isSaveing = ref(false);
const isAccepting = ref(false);
const emit = defineEmits(["success"]);
const acceptTicket = async () => {
isAccepting.value = true;
try {
await API.wf.ticket.ticketAccept.req(ticketId.value, {});
ElMessage.success("接单成功");
lastInitKey = null;
await init();
} finally {
isAccepting.value = false;
}
};
const handleTransition = (item) => {
currentTransitionId.value = item.id;
if (item.attribute_type != 1) {
@ -160,4 +200,4 @@ const submit = async (transition_id) => {
const dialogVisible = ref(false);
const dialogTitle = ref("处理意见");
const suggestion = ref("");
</script>
</script>

View File

@ -316,6 +316,14 @@
</div>
<div style="display: flex; justify-content: space-between">
<div>
<el-button
v-if="needAccept"
type="success"
:loading="acceptLoading"
:disabled="acceptLoading"
@click="handleAccept"
>接单</el-button
>
<el-button
type="primary"
@click="addNode"
@ -628,6 +636,8 @@ export default {
dosOption: [],
handoverItem:{},
submitLoading: false,
acceptLoading: false,
needAccept: false,
userId: this.$TOOL.data.get("USER_INFO").id,
isOwn: false,
isDuty: false,
@ -760,6 +770,7 @@ export default {
getticketItem() {
let that = this;
that.mainLoading = true;
that.isDuty = false;
that.$API.wf.ticket.ticketItem.req(that.ticketId).then((res) => {
that.mainLoading = false;
that.ticketDetail = res;
@ -791,11 +802,11 @@ export default {
if (this.ticketDetail.create_by == this.userId) {
this.isOwn = true;
}
let participant = this.ticketDetail.participant;
if (
participant == this.userId ||
participant.indexOf(this.userId) > -1
) {
const participant = this.ticketDetail.participant;
const participants = Array.isArray(participant)
? participant
: [participant];
if (participants.map(String).includes(String(this.userId))) {
this.isDuty = true;
}
}).catch((e) => {
@ -806,21 +817,37 @@ export default {
getBtns() {
let that = this;
that.audit_imgs_show = false;
that.$API.wf.ticket.ticketTransitions.req(that.ticketId).then((res) => {
that.operationBtn = res;
that.audit_work_show = false;
that.needAccept = false;
that.$API.wf.ticket.ticketAvailableActions.req(that.ticketId).then((res) => {
that.operationBtn = res.transitions;
that.needAccept = res.need_accept;
if (res.permission || res.need_accept) {
that.isDuty = true;
}
console.log("operationBtn", that.operationBtn);
if(res.length>0){
for (let i = 0; i < res.length; i++) {
if(res[i].on_submit_func=="apps.opm.services.check_opl_audit_imgs"){
if(that.operationBtn.length>0){
for (let i = 0; i < that.operationBtn.length; i++) {
if(that.operationBtn[i].on_submit_func=="apps.opm.services.check_opl_audit_imgs"){
that.audit_imgs_show = true;
}
if(res[i].on_submit_func=="apps.opm.services.check_opl_work_imgs"){
if(that.operationBtn[i].on_submit_func=="apps.opm.services.check_opl_work_imgs"){
that.audit_work_show = true;
}
}
}
});
},
handleAccept() {
this.acceptLoading = true;
this.$API.wf.ticket.ticketAccept.req(this.ticketId, {}).then(() => {
this.$message.success("接单成功");
this.getticketItem();
this.getBtns();
}).finally(() => {
this.acceptLoading = false;
});
},
//访
getVisit() {
this.$API.vm.visit.read.req(this.projectId).then((res) => {

View File

@ -957,7 +957,7 @@ export default {
if(that.mlogItem.material_out_&&that.mlogItem.material_out_.tracking==10){
that.$refs.tableOut.refresh();
}else{
that.$refs.checkTable.refreshfun();
that.$refs.checkTable?.refreshfun?.();
}
//inout
});
@ -1060,7 +1060,7 @@ export default {
if(this.mlogItem.material_out_&&this.mlogItem.material_out_.tracking==10){
this.$refs.tableOut.refresh();
}else{
this.$refs.checkTable.refreshfun();
this.$refs.checkTable?.refreshfun?.();
}
},
handleCheckSuccess() {
@ -1081,7 +1081,7 @@ export default {
if(this.mlogItem.material_out_&&this.mlogItem.material_out_.tracking==10){
this.$refs.tableOut.refresh();
}else{
this.$refs.checkTable.refreshfun();
this.$refs.checkTable?.refreshfun?.();
}
},
//
@ -1099,7 +1099,7 @@ export default {
if(this.mlogItem.material_out_&&this.mlogItem.material_out_.tracking==10){
this.$refs.tableOut.refresh();
}else{
this.$refs.checkTable.refreshfun();
this.$refs.checkTable?.refreshfun?.();
}
},
checkDialogClose(){