| | |
| | | default: false, |
| | | }, |
| | | }); |
| | | const emit = defineEmits(['export','saveClick']); |
| | | const emit = defineEmits(['export', 'saveClick']); |
| | | const { toObject, fromObject, nodes, edges, removeEdges, removeNodes } = useVueFlow(); |
| | | const { files, open, reset, onCancel, onChange } = useFileDialog({ |
| | | // accept: 'image/*', // Set to accept only image files |
| | |
| | | name: 'WorkFlowIndex', |
| | | }); |
| | | }; |
| | | |
| | | const applyClearGraph = async () => { |
| | | removeEdges(edges.value); |
| | | removeNodes(nodes.value); |
| | | }; |
| | | const clearGraph = async () => { |
| | | const yes = await elConfirm('确定要清空画布吗?'); |
| | | if (!yes) { |
| | | return; |
| | | } |
| | | removeEdges(edges.value); |
| | | removeNodes(nodes.value); |
| | | applyClearGraph(); |
| | | }; |
| | | const saveFlow = async () => { |
| | | const obj = toObject(); |
| | | const jsonStr = obj ? JSONFormat(obj) : ''; |
| | | |
| | | |
| | | emit('saveClick',jsonStr); |
| | | emit('saveClick', jsonStr); |
| | | }; |
| | | |
| | | onChange((file) => { |
| | | console.log(file); |
| | | if (!file) return; |
| | | // 获取json 中的内容 |
| | | const reader = new FileReader(); |
| | | reader.readAsText(file[0]); |
| | | |
| | | reader.onload = (e) => { |
| | | const jsonStr = e.target?.result as string; |
| | | const json = JSON.parse(jsonStr); |
| | | fromObject(json) |
| | | .then((val) => {}) |
| | | .catch((err) => { |
| | | ElMessage.error('导入失败' + err); |
| | | }); |
| | | applyClearGraph(); |
| | | setTimeout(() => { |
| | | const json = JSON.parse(jsonStr); |
| | | fromObject(json) |
| | | .then((val) => {}) |
| | | .catch((err) => { |
| | | ElMessage.error('导入失败' + err); |
| | | }); |
| | | }, 30); |
| | | }; |
| | | reader.readAsText(file[0]); |
| | | }); |
| | | const handleCommand = (command: string | number | object) => { |
| | | const obj = toObject(); |
| | |
| | | const jsonStr = obj ? JSONFormat(obj) : ''; |
| | | downloadJSON(jsonStr, 'flow'); |
| | | } else if (command === 'import') { |
| | | reset(); |
| | | open(); |
| | | } |
| | | }; |