Showing
2 changed files
with
69 additions
and
16 deletions
| 1 | <template> | 1 | <template> |
| 2 | <div class="app" style="height: 100vh"> | 2 | <div class="app" style="height: 100vh"> |
| 3 | <vue-flow-editor | 3 | <vue-flow-editor |
| 4 | + v-if="flowData" | ||
| 4 | ref="editor" | 5 | ref="editor" |
| 5 | menuWidth="200px" | 6 | menuWidth="200px" |
| 6 | modelWidth="300px" | 7 | modelWidth="300px" |
| 7 | - :data="state.data" | 8 | + :data="flowData" |
| 8 | :grid="showGrid" | 9 | :grid="showGrid" |
| 9 | :miniMap="showMiniMap" | 10 | :miniMap="showMiniMap" |
| 10 | :onRef="onRef" | 11 | :onRef="onRef" |
| ... | @@ -506,7 +507,57 @@ export default { | ... | @@ -506,7 +507,57 @@ export default { |
| 506 | ], | 507 | ], |
| 507 | }) | 508 | }) |
| 508 | 509 | ||
| 509 | - onMounted(() => { | 510 | + /** |
| 511 | + * 获取url参数 | ||
| 512 | + * @param url | ||
| 513 | + */ | ||
| 514 | + function getQueryParams(url: string) { | ||
| 515 | + const params = { | ||
| 516 | + flow_id: '', | ||
| 517 | + }; | ||
| 518 | + // 将url以问号为分隔符拆分为两部分 | ||
| 519 | + const parts = url.split("?"); | ||
| 520 | + // 如果只有url没有参数,则直接返回空对象 | ||
| 521 | + if (parts.length <= 1) { | ||
| 522 | + return params; | ||
| 523 | + } | ||
| 524 | + // 将参数部分以ampersand为分隔符拆分为多个参数 | ||
| 525 | + const queries = parts[1].split("&"); | ||
| 526 | + // 遍历每个参数 | ||
| 527 | + for (let i = 0; i < queries.length; i++) { | ||
| 528 | + // 将参数以等号为分隔符拆分为键值对 | ||
| 529 | + const query = queries[i].split("="); | ||
| 530 | + // 设置参数的键值对到params对象 | ||
| 531 | + params[query[0]] = query[1]; | ||
| 532 | + } | ||
| 533 | + return params; | ||
| 534 | + } | ||
| 535 | + | ||
| 536 | + // TAG: 接口获取流程图数据 | ||
| 537 | + const flowData = ref<any>(null); | ||
| 538 | + axios.get('/admin/?a=flow_nodes&flow_id=' + getQueryParams(location.href).flow_id) | ||
| 539 | + .then(res => { | ||
| 540 | + if (res.data.code) { | ||
| 541 | + let nodes = res.data.data.nodes; | ||
| 542 | + let edges = res.data.data.edges; | ||
| 543 | + // 没有流程图数据 | ||
| 544 | + if (!nodes.length && !edges.length) { | ||
| 545 | + flowData.value = AppData; // 设置默认的数据 | ||
| 546 | + } else { | ||
| 547 | + flowData.value = res.data.data; // 获取已存在的数据 | ||
| 548 | + } | ||
| 549 | + } else { | ||
| 550 | + ElMessage({ | ||
| 551 | + type: 'error', | ||
| 552 | + message: res.data.msg, | ||
| 553 | + }); | ||
| 554 | + } | ||
| 555 | + }) | ||
| 556 | + .catch(err => { | ||
| 557 | + console.error(err); | ||
| 558 | + }); | ||
| 559 | + | ||
| 560 | + onMounted(async () => { | ||
| 510 | document.title = '可视化流程设计器' | 561 | document.title = '可视化流程设计器' |
| 511 | // 显示提示框的标志位 | 562 | // 显示提示框的标志位 |
| 512 | var showConfirmation = true; | 563 | var showConfirmation = true; |
| ... | @@ -529,7 +580,7 @@ export default { | ... | @@ -529,7 +580,7 @@ export default { |
| 529 | }); | 580 | }); |
| 530 | }) | 581 | }) |
| 531 | 582 | ||
| 532 | - function handleActiveChange(name) { | 583 | + function handleActiveChange(name: any) { |
| 533 | console.warn(name) | 584 | console.warn(name) |
| 534 | } | 585 | } |
| 535 | 586 | ||
| ... | @@ -878,8 +929,8 @@ export default { | ... | @@ -878,8 +929,8 @@ export default { |
| 878 | type: string, | 929 | type: string, |
| 879 | ): Promise<any> { | 930 | ): Promise<any> { |
| 880 | let { nodes, edges } = editor.editorState.graph.save(); | 931 | let { nodes, edges } = editor.editorState.graph.save(); |
| 881 | - let start_edge_count = edges.filter(edge => edge.source === 'start-node'); // 连接到开始节点连接线的数量 | 932 | + let start_edge_count = edges.filter((edge: { source: string }) => edge.source === 'start-node'); // 连接到开始节点连接线的数量 |
| 882 | - let end_edge_count = edges.filter(edge => edge.target === 'end-node'); // 连接到结束节点连接线的数量 | 933 | + let end_edge_count = edges.filter((edge: { target: string }) => edge.target === 'end-node'); // 连接到结束节点连接线的数量 |
| 883 | // 不可以删除开始与结束连接线 | 934 | // 不可以删除开始与结束连接线 |
| 884 | let node_id = model.id; | 935 | let node_id = model.id; |
| 885 | for (let index = 0; index < edges.length; index++) { | 936 | for (let index = 0; index < edges.length; index++) { |
| ... | @@ -906,7 +957,7 @@ export default { | ... | @@ -906,7 +957,7 @@ export default { |
| 906 | return Promise.reject('reject') | 957 | return Promise.reject('reject') |
| 907 | } | 958 | } |
| 908 | // 流程图中必须有一个流程节点 | 959 | // 流程图中必须有一个流程节点 |
| 909 | - let is_flow_node = nodes.filter(node => node.control === 'flow' || node.control === 'cc'); | 960 | + let is_flow_node = nodes.filter((node: { control: string }) => node.control === 'flow' || node.control === 'cc'); |
| 910 | if (is_flow_node.length === 1) { | 961 | if (is_flow_node.length === 1) { |
| 911 | ElNotification.error('流程图中必须有一个流程节点') | 962 | ElNotification.error('流程图中必须有一个流程节点') |
| 912 | return Promise.reject('reject') | 963 | return Promise.reject('reject') |
| ... | @@ -938,8 +989,8 @@ export default { | ... | @@ -938,8 +989,8 @@ export default { |
| 938 | if (type === 'edge') { | 989 | if (type === 'edge') { |
| 939 | console.log('delete edge') | 990 | console.log('delete edge') |
| 940 | } | 991 | } |
| 941 | - state.data.nodes = editor.editorState.graph.save().nodes | 992 | + flowData.value.nodes = editor.editorState.graph.save().nodes |
| 942 | - state.data.edges = editor.editorState.graph.save().edges | 993 | + flowData.value.edges = editor.editorState.graph.save().edges |
| 943 | } | 994 | } |
| 944 | 995 | ||
| 945 | /** | 996 | /** |
| ... | @@ -994,7 +1045,7 @@ export default { | ... | @@ -994,7 +1045,7 @@ export default { |
| 994 | 1045 | ||
| 995 | model.id = uuidv4(); | 1046 | model.id = uuidv4(); |
| 996 | editor.updateModel(model); | 1047 | editor.updateModel(model); |
| 997 | - state.data.nodes = editor.editorState.graph.save().nodes | 1048 | + flowData.value.nodes = editor.editorState.graph.save().nodes |
| 998 | } | 1049 | } |
| 999 | } | 1050 | } |
| 1000 | 1051 | ||
| ... | @@ -1007,11 +1058,11 @@ export default { | ... | @@ -1007,11 +1058,11 @@ export default { |
| 1007 | function handleAfterAdd(model: myObj, type: string) { | 1058 | function handleAfterAdd(model: myObj, type: string) { |
| 1008 | if (type === 'node') { | 1059 | if (type === 'node') { |
| 1009 | console.log(`新增节点`) | 1060 | console.log(`新增节点`) |
| 1010 | - state.data.nodes = editor.editorState.graph.save().nodes | 1061 | + flowData.value.nodes = editor.editorState.graph.save().nodes |
| 1011 | } | 1062 | } |
| 1012 | if (type === 'edge') { | 1063 | if (type === 'edge') { |
| 1013 | console.log(`新增连接线`) | 1064 | console.log(`新增连接线`) |
| 1014 | - state.data.edges = editor.editorState.graph.save().edges | 1065 | + flowData.value.edges = editor.editorState.graph.save().edges |
| 1015 | } | 1066 | } |
| 1016 | } | 1067 | } |
| 1017 | 1068 | ||
| ... | @@ -1040,8 +1091,8 @@ export default { | ... | @@ -1040,8 +1091,8 @@ export default { |
| 1040 | editor.addNode(state.detailModel); | 1091 | editor.addNode(state.detailModel); |
| 1041 | editor.closeModel(); | 1092 | editor.closeModel(); |
| 1042 | // 保存流程图数据 | 1093 | // 保存流程图数据 |
| 1043 | - state.data.nodes = editor.editorState.graph.save().nodes | 1094 | + flowData.value.nodes = editor.editorState.graph.save().nodes |
| 1044 | - state.data.edges = editor.editorState.graph.save().edges | 1095 | + flowData.value.edges = editor.editorState.graph.save().edges |
| 1045 | } else { | 1096 | } else { |
| 1046 | ElNotification.error('开始或者结束节点不可以复制') | 1097 | ElNotification.error('开始或者结束节点不可以复制') |
| 1047 | } | 1098 | } |
| ... | @@ -1147,13 +1198,13 @@ export default { | ... | @@ -1147,13 +1198,13 @@ export default { |
| 1147 | * @param currentPath 当前路径 | 1198 | * @param currentPath 当前路径 |
| 1148 | * @param paths 结果数组 | 1199 | * @param paths 结果数组 |
| 1149 | */ | 1200 | */ |
| 1150 | - function findPathsToEndNode(data, currentNode, currentPath, paths) { | 1201 | + function findPathsToEndNode(data: any[], currentNode: string, currentPath: any[], paths: any[]) { |
| 1151 | if (currentNode === 'end-node') { | 1202 | if (currentNode === 'end-node') { |
| 1152 | paths.push(currentPath.slice()); // 将当前路径添加到结果数组中 | 1203 | paths.push(currentPath.slice()); // 将当前路径添加到结果数组中 |
| 1153 | return; | 1204 | return; |
| 1154 | } | 1205 | } |
| 1155 | 1206 | ||
| 1156 | - const nextObjs = data.filter(obj => obj.source === currentNode); | 1207 | + const nextObjs = data.filter((obj: { source: any }) => obj.source === currentNode); |
| 1157 | if (nextObjs.length === 0) { | 1208 | if (nextObjs.length === 0) { |
| 1158 | return; | 1209 | return; |
| 1159 | } | 1210 | } |
| ... | @@ -1169,6 +1220,7 @@ export default { | ... | @@ -1169,6 +1220,7 @@ export default { |
| 1169 | state, | 1220 | state, |
| 1170 | rules, | 1221 | rules, |
| 1171 | formRef, | 1222 | formRef, |
| 1223 | + flowData, | ||
| 1172 | 1224 | ||
| 1173 | showGrid: true, // 是否开启网格 | 1225 | showGrid: true, // 是否开启网格 |
| 1174 | showMiniMap: false, // 是否开启缩略图 | 1226 | showMiniMap: false, // 是否开启缩略图 |
| ... | @@ -1252,6 +1304,7 @@ body { | ... | @@ -1252,6 +1304,7 @@ body { |
| 1252 | cursor: pointer; | 1304 | cursor: pointer; |
| 1253 | } | 1305 | } |
| 1254 | .text-empty { | 1306 | .text-empty { |
| 1307 | + font-size: 14px; | ||
| 1255 | text-align: center; | 1308 | text-align: center; |
| 1256 | color: #dcdfe6; | 1309 | color: #dcdfe6; |
| 1257 | } | 1310 | } | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2023-10-27 09:29:48 | 2 | * @Date: 2023-10-27 09:29:48 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-11-22 17:41:19 | 4 | + * @LastEditTime: 2023-11-22 18:35:26 |
| 5 | * @FilePath: /vue-flow-editor/doc/data.js | 5 | * @FilePath: /vue-flow-editor/doc/data.js |
| 6 | * @Description: 初始化结构,数据都是固定的 | 6 | * @Description: 初始化结构,数据都是固定的 |
| 7 | */ | 7 | */ | ... | ... |
-
Please register or login to post a comment