wujingjing
2024-12-12 a3c84d896dff3758f3bc3274b0306afe018179a8
src/views/project/yw/systemManage/flowApp/components/Header.vue
@@ -1,18 +1,21 @@
<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"></span>
         <span class="ywifont ywicon-pre p-1 bg-white rounded-lg mr-2" @click="backMgr"> </span>
         <!-- <img src="@/assets/logo.png" alt="logo" class="h-8 w-8"/> -->
         <div>
            <span class="font-bold">测试</span>
            <span class="font-bold cursor-pointer">{{ flowAgent?.title }}</span>
         </div>
      </div>
      <div class="flex-items-center">
         <!-- <el-button>运行</el-button>
         <el-button>保存</el-button>
         <el-button type="primary">运行</el-button> -->
         <el-dropdown @command="handleCommand">
         <el-button @click="handleCommand('export')">导出工作流</el-button>
         <el-button type="primary" @click="saveFlow">保存</el-button>
         <!-- <el-dropdown @command="handleCommand">
            <el-button style="margin-left: 8px; width: 34px">
               <el-icon class="el-icon--center">
                  <more-filled />
@@ -24,25 +27,42 @@
                  <el-dropdown-item command="import">导入</el-dropdown-item>
               </el-dropdown-menu>
            </template>
         </el-dropdown>
         </el-dropdown> -->
      </div>
   </div>
</template>
<script setup lang="ts">
import { useVueFlow } from '@vue-flow/core';
import { useFileDialog } from '@vueuse/core';
import JSONFormat from 'json-format';
import { downloadJSON } from '/@/utils/util';
import { useFileDialog } from '@vueuse/core';
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 } = useVueFlow();
const { files, open, reset, onCancel, onChange } = useFileDialog({
   //   accept: 'image/*', // Set to accept only image files
   // 选择 json文件
   accept: 'application/json',
   directory: false, // Select directories instead of files if set true
});
const backMgr = () => {
   gotoRoute({
      name: 'WorkFlowIndex',
   });
};
const saveFlow = async () => {
   const res = await update_workflow_json_flow({
      agent_id: props.queryId,
      json_flow: JSON.stringify(toObject()),
   });
   ElMessage.success('保存成功!');
};
onChange((file) => {
   console.log(file);
@@ -51,12 +71,11 @@
   reader.onload = (e) => {
      const jsonStr = e.target?.result;
      const json = JSON.parse(jsonStr);
      fromObject(json).then((val)=>{
      }).catch((err)=>{
      });
      fromObject(json)
         .then((val) => {})
         .catch((err) => {});
   };
   reader.readAsText(file[0]);
});
const handleCommand = (command: string | number | object) => {
   const obj = toObject();