From 1b419ccf217dbcace15987f1c0fe26b9e15d1d4b Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 16 十月 2024 10:26:56 +0800
Subject: [PATCH] 工艺绑定优化

---
 src/views/tigerprojects/system/lowcode/composition/Config.vue |  201 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 125 insertions(+), 76 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/composition/Config.vue b/src/views/tigerprojects/system/lowcode/composition/Config.vue
index 3228b16..77d33d0 100644
--- a/src/views/tigerprojects/system/lowcode/composition/Config.vue
+++ b/src/views/tigerprojects/system/lowcode/composition/Config.vue
@@ -4,66 +4,72 @@
  * @version: 
  * @Date: 2024-06-24 23:44:31
  * @LastEditors: Ben Lin
- * @LastEditTime: 2024-08-04 15:33:56
+ * @LastEditTime: 2024-09-29 16:23:30
 -->
 <template>
-  <Card :title="GetTitle(props.configType)['configTitle']">
+  <Card :title="GetTitle(configType)['configTitle']">
     <BasicForm
       @register="useForms[d]"
       @submit="customSubmitFunc"
       v-for="d in Object.keys(useForms)"
       :key="d"
-      v-show="d == props.configType"
+      v-show="d == configType"
     >
-      <template #[item]="{ field }" v-for="item in GetCrudColSlots()" :key="item">
+      <template #[item.name]="{ field }" v-for="item in GetCrudColSlots()" :key="item.name">
         <a-button
           v-if="field"
           class="mt-1 ml-1"
           size="small"
-          @click="handleSelectItem(item)"
-          preIcon="search|svg"
+          @click="SelectItemInForm(item.name)"
+          :preIcon="item.icon"
         />
         <GeneralModal
-          @register="useModalData[item][0]"
-          @success="(d, u) => handleItemSuccess(d, u, item)"
+          @register="useModalData[item.name][0]"
+          @success="(d, u) => SelectInFormSuccess(d, u, item.name)"
         />
+        <GeneralCrudModal @register="useModalsCrudInForm[item.name][0]"></GeneralCrudModal>
       </template>
     </BasicForm>
   </Card>
   <Card
-    :title="GetTitle(props.configType)['tableTitle']"
+    :title="GetTitle(configType, item)['tableTitle']"
     :bordered="false"
     class="!mt-5"
-    v-if="showOtherTable"
+    v-for="item in OtherTables"
+    :key="item"
+    v-show="showOtherTable[item]"
   >
-    <BasicTable @register="useTables['Table']">
+    <BasicTable @register="useTables[item][0]" v-if="showOtherTable[item]">
       <template #action="{ record }">
-        <TableAction :actions="createActions(record)" />
+        <TableAction :actions="createActions(record, item)" />
       </template>
     </BasicTable>
+    <normalDrawer @register="useDrawers[item][0]" @success="(d, u) => EditSuccess(d, u, item)" />
+    <GeneralCrudModal @register="useModalsCrud[item][0]"></GeneralCrudModal>
   </Card>
-  <normalDrawer @register="registerDrawer" @success="handleSuccess" />
 </template>
 <script lang="ts" setup>
-  import { Ref, inject, nextTick, onMounted, ref, unref, watch } from 'vue';
+  import { Ref, inject, nextTick, onMounted, ref, toRef, toRefs, unref, watch } from 'vue';
   import { BasicForm } from '/@/components/Form/index';
   import { BasicTable, TableAction } from '/@/components/Table';
   import { Card } from 'ant-design-vue';
   import GeneralModal from '/@/views/components/GeneralModal.vue';
+  import GeneralCrudModal from '/@/views/components/GeneralCrudModal.vue';
   import { useI18n } from '/@/hooks/web/useI18n';
   import { isFunction, isNullOrUnDef } from '/@/utils/is';
   import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
   import { editRecord } from '../data';
   import { useDrawer } from '/@/components/Drawer';
   import normalDrawer from '../normalDrawer.vue';
+  import { useModal } from '/@/components/Modal';
 
   const { t } = useI18n();
   const emit = defineEmits(['success', 'register']);
   const props = defineProps({
     configType: { type: String },
-    OtherTableName: { type: String },
   });
-  const showOtherTable = ref(false);
+  const configType = toRef(props, 'configType');
+  const showOtherTable = ref<any>({}); //鏄剧ず琛ㄦ牸甯冨皵瀵硅薄
   const objParams = inject('objParams') as Ref<any>;
   const custImport = ref<any[]>([]);
   const EntityCustFunction = ref([
@@ -101,16 +107,27 @@
       GetUseTables,
       GetUseForm,
       CustFunc,
+      GetUseCrudModals,
+      ActionItem,
     },
   ] = isNullOrUnDef(custImport.value['default'])
     ? EntityCustFunction.value
     : custImport.value['default']();
 
-  const [registerDrawer, { openDrawer }] = useDrawer();
   const useModalData = ref(GetUseModals());
   const data = ref({});
   const useTables = ref(GetUseTables(data, emit));
   const useForms = ref(GetUseForm());
+  const useDrawers = ref({});
+  const useModalsCrud = ref({});
+  const useModalsCrudInForm = ref(GetUseCrudModals());
+  const OtherTables = ref(objParams.value['OtherTableName']);
+  /* 寰幆鑷畾涔夎〃鏍煎悕鍒楄〃锛屽垵濮嬪寲鏄剧ず琛ㄦ牸甯冨皵瀵硅薄 */
+  objParams.value['OtherTableName'].forEach((x) => {
+    showOtherTable.value[x] = false;
+    useDrawers.value[x] = useDrawer();
+    useModalsCrud.value[x] = useModal();
+  });
 
   /* 娉ㄥ叆閫変腑鑺傜偣鏁版嵁 */
   const selectedNodes = inject('selectedNodes') as Ref<any>;
@@ -129,25 +146,27 @@
             setProps({
               schemas: GetCrudForm(newVal[0].type),
             });
-            showOtherTable.value = result.isShow;
             /* 鏄剧ず鍏朵粬琛ㄦ牸 */
-            if (showOtherTable.value) {
-              showOtherTable.value = false;
-              data.value['Table'] = result['Table'];
-              data.value['Action'] = result['Action']
-              setTimeout(() => {
-                showOtherTable.value = true;
-              }, 10);
+            const name = result['name'];
+            if (showOtherTable.value[name]) {
+              showOtherTable.value[name] = false;
+              data.value[name] = result[name];
+              data.value['Action'] = result['Action'];
               useTables.value = GetUseTables(data, emit);
               setTimeout(() => {
-                // useTables.value['Table'][1].setProps({
-                //   dataSource: [],
-                // });
-                // useTables.value['Table'][1].setProps({
-                //   dataSource: data.value['Table'],
-                // });
-                useTables.value['Table'][1].reload();
+                showOtherTable.value[name] = true;
               }, 10);
+              setTimeout(() => {
+                if (!isNullOrUnDef(name)) {
+                  // useTables.value[name][1].setProps({
+                  //   dataSource: [],
+                  // });
+                  // useTables.value[name][1].setProps({
+                  //   dataSource: data.value[name],
+                  // });
+                  useTables.value[name][1].reload();
+                }
+              }, 1000);
             }
           });
         }
@@ -161,23 +180,31 @@
     const nodes = selectedNodes.value;
     nodeChange({ useForms, objParams, selectedNodes: nodes }).then((result) => {
       showOtherTable.value = result.isShow;
-      data.value['Action'] = result['Action'];
-      if (showOtherTable.value) {
-        data.value['Table'] = result['Table'];
-        useTables.value['Table'][1].setProps({
-          dataSource: [],
-        });
-        useTables.value['Table'][1].setProps({
-          dataSource: result['Table'],
-        });
-        useTables.value['Table'][1].reload();
+      data.value[configType.value as string] = result[configType.value as string];
+      useTables.value = GetUseTables(data, emit);
+      if (showOtherTable.value[result['name']]) {
+        data.value[result['name']] = result[result['name']];
+        // useTables.value[result['name']][1].setProps({
+        //   dataSource: [],
+        // });
+        // useTables.value[result['name']][1].setProps({
+        //   dataSource: result[result['name']],
+        // });
+        if (!isNullOrUnDef(result['name'])) {
+          useTables.value[result['name']][1].reload();
+        }
       }
     });
   });
 
+  /**
+   * @description: 鑷畾涔夋彁浜ゆ柟娉�
+   * @param {*} values
+   * @return {*}
+   */
   async function customSubmitFunc(values) {
     try {
-      SubmitFunc(values, props.configType, emit);
+      SubmitFunc(values, configType.value, emit);
       // values.AUTH_PROD = useUserStore().getUserInfo.prodCode;
       // values.FACTORY = useUserStore().getUserInfo.prodCode;
       // const apiAction = SaveEntity(values, true, 'MES_PROD_ACTION');
@@ -188,34 +215,41 @@
       // });
     } catch (e) {}
   }
+
   /**
    * @description: 鐢熸垚鍒楄〃涓搷浣滈」鐨勬寜閽�
    * @param {*} record
    * @return {*}
    */
-  function createActions(record) {
+  function createActions(record, name) {
     const params = {
       record,
       isUpdate: true,
-      entityName: objParams.value['OtherTableName'],
-      formJson: GetCrudForm(props.OtherTableName),
+      entityName: name,
+      formJson: GetCrudForm(name),
       ifSave: objParams.value['ifSave'],
       // cType,
       // dtlSlots,
       // formSchemas,
       // useModalData,
       // useFormData,
-      crudColSlots: objParams.value['crudColSlots'],
+      crudColSlots: objParams.value['crudColSlots'][name],
     };
 
     const actionItem = [
       {
         icon: 'clarity:note-edit-line',
-        onClick: editRecord.bind(null, openDrawer, params),
+        onClick: editRecord.bind(null, useDrawers.value[name][1].openDrawer, params),
         name: undefined,
       },
     ];
-    return actionItem;
+    return ActionItem(
+      params,
+      actionItem,
+      useModalsCrud.value[name][1].openModal,
+      useTables.value[name][1].reload(),
+      objParams.value['CODE'],
+    );
   }
 
   /**
@@ -224,31 +258,31 @@
    * @param {*} u
    * @return {*}
    */
-  function handleSuccess(d, u) {
+  function EditSuccess(d, u, item) {
     if (CustFunc && isFunction(CustFunc)) {
-      CustFunc(
-        {
-          ctype: objParams.value['OtherTableName'],
-          values: d,
-          data: data,
-        },
-      ).then(() => {
+      CustFunc({
+        ctype: item,
+        values: d,
+        data: data,
+      }).then(() => {
         /* 鏄剧ず鍏朵粬琛ㄦ牸 */
-        if (showOtherTable.value) {
-          showOtherTable.value = false;
+        if (showOtherTable.value[item]) {
+          showOtherTable.value[item] = false;
           setTimeout(() => {
-            showOtherTable.value = true;
+            showOtherTable.value[item] = true;
           }, 10);
           useTables.value = GetUseTables(data, emit);
           setTimeout(() => {
-            useTables.value['Table'][1].reload();
-            useForms.value['Action'][1].resetFields();
-            useForms.value['Action'][1].setFieldsValue(data.value['Action'][0]);
+            useTables.value[item][1].reload();
+            useForms.value[configType.value as string][1].resetFields();
+            useForms.value[configType.value as string][1].setFieldsValue(
+              data.value[configType.value as string][0],
+            );
           }, 10);
         }
       });
     }
-    useTables.value['Table'][1].reload();
+    useTables.value[item][1].reload();
   }
 
   /**
@@ -256,8 +290,15 @@
    * @param {*} item
    * @return {*}
    */
-  function handleSelectItem(item) {
-    OpenSelectItem(useModalData.value[item][1].openModal, item);
+  function SelectItemInForm(item) {
+    const record = useForms.value[configType.value][1].getFieldsValue();
+    OpenSelectItem(
+      useModalData.value[item][1].openModal,
+      item,
+      useModalsCrudInForm.value[item][1].openModal,
+      record,
+      objParams.value['CODE'],
+    );
   }
 
   /**
@@ -267,18 +308,26 @@
    * @param {*} item
    * @return {*}
    */
-  function handleItemSuccess(d, u, item) {
+  function SelectInFormSuccess(d, u, item) {
     GetSelectSuccess(d, u, item).then((result) => {
-      useForms.value[props.configType][1].setFieldsValue(result['value']);
+      useForms.value[configType.value][1].setFieldsValue(result['value']);
+      if (!isNullOrUnDef(data.value[configType.value as string])) {
+        data.value[configType.value as string].map((x) => {
+          Object.getOwnPropertyNames(result['value']).forEach((key) => {
+            x[key] = result['value'][key];
+          });
+        });
+      }
       showOtherTable.value = result['isShow'];
-      if (showOtherTable.value) {
-        useTables.value['Table'][1].setProps({
-          dataSource: [],
-        });
-        useTables.value['Table'][1].setProps({
-          dataSource: result['data'],
-        });
-        useTables.value['Table'][1].reload();
+      data.value[result.name] = result['data'];
+      /* 閲嶆柊useTable锛屽惁鍒欐暟鎹笉鍒锋柊 */
+      useTables.value = GetUseTables(data, emit);
+      if (showOtherTable.value[result.name]) {
+        showOtherTable.value[result.name] = false;
+        setTimeout(() => {
+          showOtherTable.value[result.name] = true;
+        }, 10);
+        useTables.value[result.name][1].reload();
       }
     });
   }

--
Gitblit v1.9.3