wujingjing
2024-12-12 6ee230ce0a8d338609ab96cebdeafc1e62f6e918
src/views/project/yw/systemManage/flowApp/components/Header.vue
@@ -1,11 +1,11 @@
<template>
   <div class="h-14 flex justify-between px-2 border border-solid border-x-0 border-t-0 border-gray-300">
      <div class="flex-items-center">
         <span class="ywifont ywicon-pre p-1 bg-white rounded-lg mr-2" @click="backMgr"> </span>
         <span class="ywifont ywicon-pre p-1.5 bg-white rounded-lg mr-4 shadow cursor-pointer" @click="backMgr"> </span>
         <!-- <img src="@/assets/logo.png" alt="logo" class="h-8 w-8"/> -->
         <div>
            <span class="font-bold cursor-pointer">{{ flowAgent?.title }}</span>
            <span class="font-bold text-medium">{{ flowAgent?.title }}</span>
         </div>
      </div>
      <div class="flex-items-center">
@@ -14,6 +14,7 @@
         <el-button type="primary">运行</el-button> -->
         <el-button @click="handleCommand('export')">导出工作流</el-button>
         <el-button @click="handleCommand('import')">导入工作流</el-button>
         <el-button type="danger" @click="clearGraph">清空画布</el-button>
         <el-button type="primary" @click="saveFlow">保存</el-button>
         <!-- <el-dropdown @command="handleCommand">
@@ -37,13 +38,13 @@
import { useVueFlow } from '@vue-flow/core';
import { useFileDialog } from '@vueuse/core';
import JSONFormat from 'json-format';
import { downloadJSON } from '/@/utils/util';
import { downloadJSON, elConfirm } from '/@/utils/util';
import { gotoRoute } from '/@/utils/route';
import { update_workflow_json_flow } from '/@/api/workflow';
import { ElMessage } from 'element-plus';
const props = defineProps(['queryId', 'flowAgent']);
const emit = defineEmits(['export']);
const { toObject, fromObject } = useVueFlow();
const { toObject, fromObject, nodes, edges, removeEdges, removeNodes } = useVueFlow();
const { files, open, reset, onCancel, onChange } = useFileDialog({
   //   accept: 'image/*', // Set to accept only image files
   // 选择 json文件
@@ -56,7 +57,14 @@
      name: 'WorkFlowIndex',
   });
};
const clearGraph = async () => {
   const yes = await elConfirm('确定要清空画布吗?');
   if (!yes) {
      return;
   }
   removeEdges(edges.value);
   removeNodes(nodes.value);
};
const saveFlow = async () => {
   const obj = toObject();
   const jsonStr = obj ? JSONFormat(obj) : '';
@@ -73,11 +81,13 @@
   // 获取json 中的内容
   const reader = new FileReader();
   reader.onload = (e) => {
      const jsonStr = e.target?.result;
      const jsonStr = e.target?.result as string;
      const json = JSON.parse(jsonStr);
      fromObject(json)
         .then((val) => {})
         .catch((err) => {});
         .catch((err) => {
            ElMessage.error('导入失败' + err);
         });
   };
   reader.readAsText(file[0]);
});