From 0c81362850314afd2a6cb5f5d6b332d7ad33058b Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期二, 22 十月 2024 23:29:47 +0800
Subject: [PATCH] 模板生成预览

---
 src/views/tigerprojects/system/lowcode/normal/mainTable.vue |  164 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 133 insertions(+), 31 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/normal/mainTable.vue b/src/views/tigerprojects/system/lowcode/normal/mainTable.vue
index ea56742..d4e5502 100644
--- a/src/views/tigerprojects/system/lowcode/normal/mainTable.vue
+++ b/src/views/tigerprojects/system/lowcode/normal/mainTable.vue
@@ -2,6 +2,7 @@
   <div>
     <BasicTable @register="registerTable">
       <template #toolbar>
+        <!-- 鏍规嵁鑿滃崟璁剧疆鐨勬寜閽紝鑷姩鐢熸垚 -->
         <a-button
           type="primary"
           v-for="item in buttons.filter((m) => m['BUTTON_TYPE'] == 0)"
@@ -25,7 +26,7 @@
           preIcon="search|svg"
         />
         <GeneralModal
-          @register="registerItemAdd"
+          @register="useModalInTableForm[item]"
           @success="(d, u) => handleItemSuccess(d, u, item)"
         />
       </template>
@@ -80,23 +81,28 @@
   import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
   import { useModal } from '/@/components/Modal';
   import { useGo } from '/@/hooks/web/usePage';
-  import { DeleteEntity, getEntity, getListByPage } from '/@/api/tigerapi/system';
+  import { getListByPage } from '/@/api/tigerapi/system';
   import { useI18n } from '/@/hooks/web/useI18n';
   import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
   import { getRoleButtons } from '/@/api/sys/menu';
   import { useUserStore } from '/@/store/modules/user';
   import { useRouter } from 'vue-router';
-  import { GenerateActionButton, initRoute, OpenCustModal } from '../data';
+  import { GenerateActionButton, initRoute } from '../data';
   import LogicFlow from '@logicflow/core';
   import { isFunction } from 'xe-utils';
+  import { CustModalParams } from '/@/api/tigerapi/model/systemModel';
+  import { useQueryStore } from '/@/store/modules/queryInpage';
 
   const { t } = useI18n();
   const { currentRoute } = useRouter();
+  const route = unref(currentRoute);
+  const useQuery = useQueryStore();
   const props = defineProps({
     useTableData: { type: Object as PropType<{}>, default: { table: [] } },
     crudColSlots: { type: Object as PropType<any> },
   });
   const objParams = inject('objParams') as Ref<any>;
+  const savedParams = inject('savedParams') as Ref<any>;
   const colSlots = ref(objParams.value['colSlots']);
   const _columns = inject('_columns') as Ref<any[]>;
   const _searchFormSchema = inject('_searchFormSchema') as Ref<any[]>;
@@ -108,9 +114,9 @@
   const entityName = ref(objParams.value['ID']);
   const go = useGo();
   const [registerDrawer, { openDrawer }] = useDrawer();
-  const [registerItemAdd, { openModal: openItemModal }] = useModal();
   const [registerRv, { openModal: openRvModal, closeModal: RvcloseModal }] = useModal();
   const [registerCust, { openModal: openCustModal }] = useModal();
+  const [registerCrud, { openModal: openCrudModal }] = useModal();
   const cType = ref('');
   const formSchemas = ref({}); //寮瑰嚭妗嗗琛ㄥ崟缁撴瀯
   const routeData = ref({
@@ -126,6 +132,7 @@
       OpenSelectItem(openItemModal: Fn, ...args) {},
       GetSelectSuccess(d, u, ...args) {},
       GetUseForm(...args) {},
+      CustFunc(param: CustModalParams) {},
     } as EntityCustFunctionType,
   ]);
   /* 鍔ㄦ�乮mport瀹炰綋鍚�.ts鐨勮嚜瀹氫箟鏂规硶 */
@@ -141,6 +148,7 @@
       GetCustData,
       OpenSelectItem: OpenSelectCust,
       GetSelectSuccess,
+      CustFunc,
     },
     ActionColumn,
   ] = isNullOrUnDef(custImport.value['default'])
@@ -153,9 +161,14 @@
   const dtlSlots = ref<any[]>([]);
   const useformdata = GetUseForm && isFunction(GetUseForm) ? GetUseForm() : {};
   const useFormData = ref<any>(useformdata);
-  /* 琛ㄥ崟涓彃妲芥覆鏌撴寜閽墦寮�妯℃�佹useModal鏂规硶 */
+  /* 鑷畾涔夋ā鎬佺獥鍙d腑琛ㄥ崟涓彃妲芥覆鏌撴寜閽墦寮�妯℃�佹useModal鏂规硶 */
   const modals = GetUseModals && isFunction(GetUseModals) ? GetUseModals() : { useModalData: {} };
   const useModalData = ref(modals['useModalData']);
+  /* 琛ㄦ牸鍐呯殑鎻掓Ы娓叉煋鐨勫脊鍑洪�夋嫨妗嗗垪琛� */
+  const useModalInTableForm = ref<any>({});
+  colSlots.value.map((x) => {
+    useModalInTableForm.value[x] = useModal();
+  });
   /* 鑾峰彇鑷畾涔夋暟鎹� */
   const custData = GetCustData && isFunction(GetCustData) ? GetCustData() : { isCustEl: {} };
   const isCustEl = ref(custData['isCustEl']);
@@ -174,24 +187,37 @@
             }
           : '',
     },
+    beforeFetch: SearchInfoFn,
+    afterFetch: afterFetchFn,
     columns: _columns as unknown as BasicColumn[],
     formConfig: {
       labelWidth: 140,
       schemas: _searchFormSchema as unknown as FormSchema[],
+      submitFunc: () => Search(), //鑷畾涔夋煡璇㈡彁浜ゆ寜閽殑鏂规硶锛岃Е鍙戞煡璇㈡彁浜や簨浠�
+      resetFunc: () => useQuery.resetFunc(route.name, getForm()),
     },
     useSearchForm: true,
     showTableSetting: true,
     bordered: true,
     canResize: true,
     showIndexColumn: false,
-    actionColumn: ActionColumn, //鑷畾涔夋搷浣滃垪
+    actionColumn: ActionColumn
+      ? ActionColumn
+      : {
+          width: 120,
+          title: '鎿嶄綔',
+          dataIndex: 'action',
+          slots: { customRender: 'action' },
+          fixed: 'right',
+        }, //鑷畾涔夋搷浣滃垪
   });
 
   watch(
     () => AuthOption.value,
     (newVal, oldVal) => {
       nextTick(() => {
-        if (!isNullOrEmpty(newVal.BY_ORG)) {
+        if (!isNullOrEmpty(newVal.BY_ORG) && !isNullOrUnDef(savedParams.value['params'])) {
+          getForm().setFieldsValue(savedParams.value['params']);
           setProps({
             searchInfo: {
               TABLE_NAME: objParams.value['ID'],
@@ -213,7 +239,67 @@
     { deep: true, immediate: true },
   );
 
-  onMounted(() => {});
+  onMounted(async () => {
+    if (!isNullOrUnDef(savedParams) && !isNullOrUnDef(savedParams.value['params'])) {
+      getForm().setFieldsValue(savedParams.value['params']);
+      reload();
+    }
+    // if (
+    //   !isNullOrUnDef(useQuery.getCurSearchInfo['searchInfo']) &&
+    //   useQuery.getCurSearchInfo['name'] == route.name
+    // ) {
+    //   getForm().resetFields();
+    //   const searchInfo = useQuery.getCurSearchInfo['searchInfo'];
+    //   await getForm().setFieldsValue(searchInfo);
+    // }
+  });
+
+  /**
+   * @description: 鏌ヨ鎻愪氦
+   * @return {*}
+   */
+  async function Search() {
+    useQuery.submitFunc(route.name, getForm()).then(() => {
+      reload();
+    });
+  }
+
+  /**
+   * @description: 璋冪敤api鍓嶏紝鍙傛暟鏁寸悊
+   * @param {*} t
+   * @return {*}
+   */
+  function SearchInfoFn(t) {
+    if (
+      !isNullOrUnDef(useQuery.getCurSearchInfo) &&
+      useQuery.getCurSearchInfo.some((q) => q.name == route.name)
+    ) {
+      const curSearchInfo = useQuery.getCurSearchInfo.filter((q) => q.name == route.name);
+      const Keys = Object.getOwnPropertyNames(curSearchInfo[0].searchInfo);
+      for (const k in Keys) {
+        if (Keys[k] != 'page' && Keys[k] != 'pageSize') {
+          t[Keys[k]] = curSearchInfo[0].searchInfo[Keys[k]];
+        }
+      }
+      useQuery.setCurSearchInfo({ name: route.name, searchInfo: t });
+    }
+    return t;
+  }
+
+  /**
+   * @description: 璇锋眰涔嬪悗瀵硅繑鍥炲�艰繘琛屽鐞�
+   * @param {*} t
+   * @return {*}
+   */
+  function afterFetchFn(t) {
+    if (
+      !isNullOrUnDef(useQuery.getCurSearchInfo) &&
+      useQuery.getCurSearchInfo.some((q) => q.name == route.name)
+    ) {
+      const curSearchInfo = useQuery.getCurSearchInfo.filter((q) => q.name == route.name);
+      getForm().setFieldsValue(curSearchInfo[0].searchInfo);
+    }
+  }
 
   const currlf = ref(null) as Ref<LogicFlow | null>;
   /**
@@ -222,7 +308,7 @@
    * @return {*}
    */
   async function init(lf, rotId) {
-    initRoute(lf, rotId, routeData, currlf);
+    initRoute(lf, rotId, routeData, currlf, null);
   }
 
   /**
@@ -246,12 +332,16 @@
       currlf,
       selectVals,
       colSlots,
+      ifSave: true,
+      sName: objParams.value['sName'],
     };
 
+    /* 鏍规嵁鑿滃崟璁剧疆鐨勬寜閽嚜鍔ㄧ敓鎴愭搷浣滃垪涓殑鎸夐挳 */
     const actionItem = GenerateActionButton(params, buttons, openDrawer, reload);
     if (isNullOrUnDef(custImport.value['default'])) {
       return actionItem;
     }
+    /* 鏍规嵁鍔ㄦ�佸姞杞界殑瀹炰綋绫诲悕.ts涓殑ActionItem鏂规硶锛屾覆鏌撴搷浣滃垪涓殑鎸夐挳鏂规硶 */
     return nActionItem(
       params,
       actionItem,
@@ -263,6 +353,7 @@
       go,
       setProps,
       openCustModal,
+      openCrudModal,
     );
   }
 
@@ -285,18 +376,21 @@
    */
   function handleCreate(fnName: string) {
     if (isNullOrUnDef(custImport.value['default'])) {
+      /* 濡傛灉鍔ㄦ�佸姞杞界殑瀹炰綋绫�.ts涓嶅瓨鍦紝鍒欑洿鎺ユ墦寮�渚ц竟妗� */
       openDrawer(true, {
-        isUpdate: false,
-        entityName: entityName.value,
-        formJson: _crudFormSchema.value,
-        crudColSlots: objParams.value['crudColSlots'],
-        isExistSql: isExistSql.value,
+        isUpdate: false, //鏄柊澧炶繕鏄紪杈戯紝false-鏂板|true-缂栬緫
+        entityName: entityName.value, //瀹炰綋绫诲悕
+        formJson: _crudFormSchema.value, //鏂板缂栬緫鐨勮〃鍗曠粨鏋�
+        crudColSlots: objParams.value['crudColSlots'], //鏂板缂栬緫鐨勮〃鍗曚腑鐨勬彃妲藉垪琛�
+        isExistSql: isExistSql.value, //鏄惁瀛樺湪妫�鏌ql锛屾瘮濡�: XXX_CODE = '12345'
+        ifSave: true, //鏄惁鎻愪氦琛ㄥ崟鏃朵繚瀛樺埌鏁版嵁搴擄紝鍚�-鏆傚瓨|鏄�-淇濆瓨
       });
     } else {
+      /* 濡傛灉鍔ㄦ�佸姞杞界殑瀹炰綋绫�.ts瀛樺湪锛屾牴鎹�.ts鏂囦欢涓殑鏂规硶鏉ユ墽琛屾搷浣� */
       const [{ CreateAction }] = custImport.value['default']();
-      const result = CreateAction(fnName);
+      const result = CreateAction(entityName.value, colSlots.value);
       switch (result.action) {
-        case 'go':
+        case 'go' /* 璺宠浆椤甸潰 */:
           // 灏嗗璞¤浆鎹负JSON瀛楃涓插苟淇濆瓨鍒皊essionStorage
           sessionStorage.setItem(
             `${result.params.Name}_params`,
@@ -306,13 +400,14 @@
             `/${result.url}/${encodeURI(JSON.stringify({ sName: result.params.Name, Name: result.params.Name }))}`,
           );
           break;
-        case 'drawer':
+        case 'drawer' /* 鎵撳紑渚ц竟妗� */:
           openDrawer(true, {
-            isUpdate: false,
-            entityName: entityName.value,
-            formJson: _crudFormSchema.value,
-            crudColSlots: objParams.value['crudColSlots'],
-            isExistSql: isExistSql.value,
+            isUpdate: false, //鏄柊澧炶繕鏄紪杈戯紝false-鏂板|true-缂栬緫
+            entityName: entityName.value, //瀹炰綋绫诲悕
+            formJson: _crudFormSchema.value, //鏂板缂栬緫鐨勮〃鍗曠粨鏋�
+            crudColSlots: objParams.value['crudColSlots'], //鏂板缂栬緫鐨勮〃鍗曚腑鐨勬彃妲藉垪琛�
+            isExistSql: isExistSql.value, //鏄惁瀛樺湪妫�鏌ql锛屾瘮濡�: XXX_CODE = '12345'
+            ifSave: true, //鏄惁鎻愪氦琛ㄥ崟鏃朵繚瀛樺埌鏁版嵁搴擄紝鍚�-鏆傚瓨|鏄�-淇濆瓨
           });
           break;
       }
@@ -326,6 +421,11 @@
    * @return {*}
    */
   function handleSuccess(d, u) {
+    if (CustFunc && isFunction(CustFunc)) {
+      CustFunc({
+        values: d,
+      });
+    }
     reload();
   }
 
@@ -344,7 +444,7 @@
       )
         .then((m) => {
           const [{ GetSelectSuccess: GetSelectSuccess2 }] = m.default();
-          getForm().setFieldsValue(GetSelectSuccess2(d, u));
+          getForm().setFieldsValue(GetSelectSuccess2(d, u, objParams.value['ID']));
         })
         .catch(() => {
           getForm().setFieldsValue({
@@ -367,10 +467,10 @@
       )
         .then((m) => {
           const [{ OpenSelectItem }] = m.default();
-          OpenSelectItem(openItemModal);
+          OpenSelectItem(useModalInTableForm.value[item][1].openModal);
         })
         .catch(() => {
-          openItemModal(true, {
+          useModalInTableForm.value[item][1].openModal(true, {
             title: '鐗╂枡鍒楄〃',
             schemas: [
               {
@@ -410,7 +510,7 @@
    * @description: 寮瑰嚭妗嗙‘瀹氳繑鍥�
    * @param {*} d
    * @return {*}
-   */  
+   */
   function custSuccess(d) {
     reload();
   }
@@ -419,8 +519,10 @@
    * @description: 寮瑰嚭妗嗗彇娑堣繑鍥�
    * @param {*} reload
    * @return {*}
-   */  
-  function custCancel() {reload();}
+   */
+  function custCancel() {
+    reload();
+  }
 
   /**
    * @description: 鍚勮〃鍗曞唴寮瑰嚭閫夋嫨妗嗛�夋嫨鎴愬姛鍚庢柟娉�
@@ -436,11 +538,11 @@
       selectVals.value = values; //淇濆瓨寮瑰嚭妗嗛�夋嫨鐨勭粨鏋�
       let _val = {};
       d.returnFieldName.map((x) => {
-          _val[x] = values[x];
-        });
+        _val[x] = values[x];
+      });
       useFormData.value[item][1].setFieldsValue(_val);
       /* 閽堝宸ュ崟鐨勬柟娉� */
-      if (d.returnFieldName.filter((x) => x == 'ROUTE_CODE') && item == 'prodinfo' ) {
+      if (d.returnFieldName.filter((x) => x == 'ROUTE_CODE') && item == 'prodinfo') {
         routeData.value = {
           nodes: [],
           edges: [],

--
Gitblit v1.9.3