wujingjing
2025-02-24 a61bd8abfb6bedacccbc1f1cdb01e4f433e58fd7
src/views/project/yw/systemManage/flowApp/components/Header.vue
@@ -53,7 +53,7 @@
      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
@@ -67,40 +67,43 @@
      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) : '';
   const res = await update_workflow_json_flow({
      agent_id: props.queryId,
      json_flow: jsonStr,
   });
   ElMessage.success('保存成功!');
   emit('saveClick');
   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();
@@ -109,6 +112,7 @@
      const jsonStr = obj ? JSONFormat(obj) : '';
      downloadJSON(jsonStr, 'flow');
   } else if (command === 'import') {
      reset();
      open();
   }
};