From 4a1a5b96689ce49cba56f7b668d73ed5edc7ff2c Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 01 五月 2024 14:24:52 +0800
Subject: [PATCH] 工艺路线更新

---
 src/views/tigerprojects/mes/eng/route/index.vue |  229 ++++++++++++--------------------------------------------
 1 files changed, 51 insertions(+), 178 deletions(-)

diff --git a/src/views/tigerprojects/mes/eng/route/index.vue b/src/views/tigerprojects/mes/eng/route/index.vue
index 624facf..44ebc95 100644
--- a/src/views/tigerprojects/mes/eng/route/index.vue
+++ b/src/views/tigerprojects/mes/eng/route/index.vue
@@ -3,11 +3,12 @@
     <Layout class="h-full">
       <LayoutContent :style="{ overflow: 'initial' }">
         <FlowChart
-          :data="demoData"
+          :data="routeData"
           @save-data="handleSave"
           @add-lf="handleAddlf"
           @select-node="handleSelect"
           @click-blank="clickBlank"
+          @init="init"
         />
       </LayoutContent>
       <LayoutSider
@@ -37,10 +38,10 @@
 <script lang="ts" setup>
   import { FlowChart } from '/@/components/FlowChart';
   import { PageWrapper } from '/@/components/Page';
-  import { SaveRouteData } from '/@/api/tigerapi/mes/router';
+  import { SaveRouteData, getRouteData } from '/@/api/tigerapi/mes/router';
   import { useModal } from '/@/components/Modal';
   import RouteModal from './RouteModal.vue';
-  import { ref, unref, Ref, provide, reactive } from 'vue';
+  import { onMounted, ref, unref, Ref, provide, reactive, nextTick } from 'vue';
   import { Layout, LayoutContent, LayoutSider } from 'ant-design-vue';
   import {
     RouteData,
@@ -60,10 +61,14 @@
   import { useMessage } from '/@/hooks/web/useMessage';
   import { useI18n } from '/@/hooks/web/useI18n';
   import { isNullOrEmpty } from '/@/utils/is';
+  import { useRoute } from 'vue-router';
+  import { useTabs } from '/@/hooks/web/useTabs';
 
   const [registerDrawer, { openDrawer }] = useDrawer();
   const [registerModal, { openModal }] = useModal();
   const { t } = useI18n();
+  const route = useRoute();
+  const { setTitle } = useTabs();
   const { notification, createErrorModal } = useMessage();
   const routeConfig = reactive({
     // 琛ㄥ崟閰嶇疆
@@ -77,183 +82,16 @@
     activeKey: 1,
   } as IRouteConfig);
   const currRoute = ref({} as MES_ROUTE);
-  // const schemas: FormSchema[] = [
-  //   {
-  //     field: 'func_type',
-  //     label: '灞炴�ч〉',
-  //     component: 'RadioButtonGroup',
-  //     defaultValue: '0',
-  //     componentProps: {
-  //       options: [
-  //         { label: '宸ヨ壓娴佺▼', value: '0' },
-  //         { label: '宸ュ簭', value: '1' },
-  //       ],
-  //     },
-  //     colProps: { lg: 24, md: 24 },
-  //   },
-  //   {
-  //     field: 'OPER_CODE',
-  //     component: 'ApiSelect',
-  //     label: '閫夋嫨宸ュ簭',
-  //     componentProps: {
-  //       api: getOperAllList,
-  //       // params: {
-  //       //   id: 1,
-  //       // },
-  //       resultField: 'items',
-  //       labelField: 'OPER_NAME',
-  //       valueField: 'OPER_CODE',
-  //       // not request untill to select
-  //       immediate: false,
-  //       onChange: (e) => {
-  //         console.log('selected:', e);
-  //       },
-  //       // atfer request callback
-  //       onOptionsChange: (options) => {
-  //         console.log('get options', options.length, options);
-  //       },
-  //     },
-  //     ifShow: ({ values }) => isOper(values.func_type),
-  //   },
-  //   {
-  //     field: 'field2',
-  //     component: 'Input',
-  //     label: '宸ュ簭绫诲瀷',
-  //     // componentProps:{},
-  //     // can func
-  //     componentProps: ({ schema, formModel }) => {
-  //       console.log('form:', schema);
-  //       console.log('formModel:', formModel);
-  //       return {
-  //         placeholder: '娴嬭瘯',
-  //         onChange: (e: any) => {
-  //           console.log(e);
-  //         },
-  //       };
-  //     },
-  //     renderComponentContent: () => {
-  //       return {
-  //         prefix: () => '宸ュ簭',
-  //         suffix: () => '绫诲瀷',
-  //       };
-  //     },
-  //     ifShow: ({ values }) => isOper(values.func_type),
-  //   },
-  //   {
-  //     field: 'field3',
-  //     component: 'Select',
-  //     label: '宸ュ簭琛屼负',
-  //     componentProps: {
-  //       options: [
-  //         {
-  //           label: '瀛樺偍杩囩▼',
-  //           value: '1',
-  //           key: '1',
-  //         },
-  //         {
-  //           label: '鏉$爜瑙勫垯',
-  //           value: '2',
-  //           key: '2',
-  //         },
-  //         {
-  //           label: '琛屼负涓�',
-  //           value: '3',
-  //           key: '3',
-  //         },
-  //         {
-  //           label: '琛屼负浜�',
-  //           value: '4',
-  //           key: '4',
-  //         },
-  //         {
-  //           label: '琛屼负涓�',
-  //           value: '5',
-  //           key: '5',
-  //         },
-  //       ],
-  //     },
-  //     ifShow: ({ values }) => isOper(values.func_type),
-  //   },
-  //   {
-  //     field: 'field4',
-  //     component: 'Switch',
-  //     label: '鏄惁璁$畻鐩撮�氱巼',
-  //     colProps: {
-  //       span: 16,
-  //     },
-  //     labelWidth: 200,
-  //     ifShow: ({ values }) => isOper(values.func_type),
-  //   },
-  //   {
-  //     field: 'field5',
-  //     component: 'Switch',
-  //     label: '鏄惁鍙烦绔�',
-  //     colProps: {
-  //       span: 16,
-  //     },
-  //     labelWidth: 200,
-  //     ifShow: ({ values }) => isOper(values.func_type),
-  //   },
-  //   {
-  //     field: 'ROT_CODE',
-  //     label: '宸ヨ壓璺嚎缂栫爜',
-  //     required: true,
-  //     component: 'Input',
-  //     colProps: { span: 16 },
-  //     ifShow: ({ values }) => isRute(values.func_type),
-  //   },
-  //   {
-  //     field: 'ROT_NAME',
-  //     label: '宸ヨ壓璺嚎鍚嶇О',
-  //     required: true,
-  //     component: 'Input',
-  //     colProps: { span: 16 },
-  //     ifShow: ({ values }) => isRute(values.func_type),
-  //   },
-  //   {
-  //     field: 'ROT_TYPE',
-  //     label: '宸ヨ壓璺嚎绫诲瀷',
-  //     required: true,
-  //     component: 'Input',
-  //     colProps: { span: 16 },
-  //     ifShow: ({ values }) => isRute(values.func_type),
-  //   },
-  //   {
-  //     field: 'ROT_VER',
-  //     label: '宸ヨ壓璺嚎鐗堟湰',
-  //     required: true,
-  //     component: 'Input',
-  //     colProps: { span: 16 },
-  //     ifShow: ({ values }) => isRute(values.func_type),
-  //   },
-  //   {
-  //     field: 'IS_ACTIVE',
-  //     label: '鏄惁鍚敤',
-  //     required: true,
-  //     component: 'Select',
-  //     colProps: { span: 16 },
-  //     componentProps: {
-  //       options: [
-  //         {
-  //           label: '鏄�',
-  //           value: 'Y',
-  //           key: 'Y',
-  //         },
-  //         {
-  //           label: '鍚�',
-  //           value: 'N',
-  //           key: 'N',
-  //         },
-  //       ],
-  //     },
-  //     ifShow: ({ values }) => isRute(values.func_type),
-  //   },
-  // ];
-  const demoData = ref({});
+  const routeData = ref({
+    nodes: [],
+    edges: [],
+  });
   provide<Ref<IRouteConfig>>('routeConfig', routeConfig);
   provide<Ref<MES_ROUTE>>('mesRoute', currRoute);
   const selectnode = ref({} as node);
+  const currRotId = ref(route.params?.id);
 
+  console.log(currRotId.value);
   // const demoData1 = ref({
   //   nodes: [
   //     {
@@ -374,6 +212,32 @@
   //   ],
   // });
 
+  if (!isNullOrEmpty(currRotId.value)) {
+    setTitle('璁捐锛氬伐鑹鸿矾绾�' + currRotId.value);
+  }
+
+  async function init(lf) {
+    //閫氳繃宸ヨ壓璺嚎ID鑾峰彇鍥惧舰鏁版嵁锛屽苟娓叉煋
+    var _data = await getRouteData(currRotId.value);
+    console.log('缁勪欢宸叉寕杞�', _data);
+    currRoute.value = _data.Data.route;
+    _data.Data.nodes.forEach((n) => {
+      n.node.properties = JSON.parse(n.node.properties);
+      routeData.value.nodes.push(n.node);
+    });
+    console.log('111', routeData.value);
+    _data.Data.edges.forEach((e) => {
+      e.edge.properties = JSON.parse(e.edge.properties);
+      routeData.value.edges.push(e.edge);
+    });
+    _data.Data.acts.forEach((act) => {
+      act.node.properties = JSON.parse(act.node.properties);
+      routeData.value.nodes.push(act.node);
+    });
+    console.log('init', unref(lf).getGraphData(), JSON.parse(JSON.stringify(routeData.value)));
+    unref(lf).render(routeData.value);
+  }
+
   async function handleSave(lf) {
     console.log('handleSave', unref(lf).getGraphData().nodes[0]);
     if (isNullOrEmpty(currRoute.value.ROT_CODE)) {
@@ -385,7 +249,7 @@
     } else {
       var _routeData: RouteData = {
         route: {
-          ID: buildUUID(),
+          ID: currRoute.value.ID,
           CREATE_TIME: new Date(),
           CREATE_USER: useUserStore().getUserInfo.userId as string,
           UPDATE_TIME: new Date(),
@@ -446,6 +310,14 @@
             SAPL_CODE: '',
             LABEL_CODE: '',
           };
+          var pnode = [n];
+          while (pnode[0].properties.operType == 'Action') {
+            pnode = unref(lf).getNodeIncomingNode(pnode[0].id);
+            if (pnode[0].properties.operType != 'Action') {
+              act.NODE_ID = pnode[0].id;
+              break;
+            }
+          }
           _routeData.acts.push(act);
         } else {
           var node: MES_ROUTE_NODE = {
@@ -569,8 +441,9 @@
     routeConfig.activeKey = 1;
   }
 
-  function modalSuccess(lfInstance, route) {
+  async function modalSuccess(lfInstance, route) {
     unref(lfInstance).render({});
     currRoute.value = route;
+    currRotId.value = currRoute.value.ID;
   }
 </script>

--
Gitblit v1.9.3