From 44ef538691b8be0fd925ca80c49157bad14962e8 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期六, 06 七月 2024 22:01:26 +0800
Subject: [PATCH] 一些优化

---
 src/views/tigerprojects/system/lowcode/high/dtl.vue |  107 +++++++++++++++++++++++++++++++----------------------
 1 files changed, 63 insertions(+), 44 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/high/dtl.vue b/src/views/tigerprojects/system/lowcode/high/dtl.vue
index f7b1691..cca9b51 100644
--- a/src/views/tigerprojects/system/lowcode/high/dtl.vue
+++ b/src/views/tigerprojects/system/lowcode/high/dtl.vue
@@ -8,15 +8,14 @@
     >
       <BasicTable @register="useTables[item.name]">
         <template #toolbar>
-          <a-button type="primary" @click="handleCreate(index, item.name)" preIcon="add_02|svg">
+          <a-button type="primary" @click="handleCreate(index, item)" preIcon="add_02|svg">
             鏂板
           </a-button>
         </template>
         <template #action="{ record }">
-          <TableAction :actions="createActions(record, index, item.name)" />
+          <TableAction :actions="createActions(record, index, item)" />
         </template>
         <template #[item]="{ field }" v-for="item in colSlots" :key="item">
-          <!-- <template #form-BAS_REASON3aadd="{ field }"> -->
           <a-button
             v-if="field"
             class="mt-1 ml-1"
@@ -38,12 +37,12 @@
   </div>
 </template>
 <script lang="ts" setup>
-  import { Ref, inject, nextTick, onMounted, ref, watch } from 'vue';
-  import { BasicTable, useTable, TableAction } from '/@/components/Table';
-  import { BasicForm, useForm } from '/@/components/Form/index';
+  import { Ref, inject, onMounted, ref, watch } from 'vue';
+  import { BasicTable, TableAction } from '/@/components/Table';
+  import { useForm } from '/@/components/Form/index';
   import GeneralModal from '/@/views/components/GeneralModal.vue';
   import normalDrawer from '../normalDrawer.vue';
-  import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
+  import { isFunction, isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
   import { useModal } from '/@/components/Modal';
   import { useGo } from '/@/hooks/web/usePage';
   import { DeleteEntity, getEntity } from '/@/api/tigerapi/system';
@@ -53,35 +52,36 @@
 
   const { t } = useI18n();
   const ACard = Card;
+  const emit = defineEmits(['search']);
   const props = defineProps({
     colSlots: { type: Array as PropType<any[]> },
     useTableData: { type: Object as PropType<{}>, default: { table: [] } },
     entityName: { type: String },
     crudColSlots: { type: Object as PropType<any> },
   });
+  /* 涓婚〉闈㈡敞鍏ョ殑鍙橀噺 */
   const objParams = inject('objParams') as Ref<any>;
   const data = inject('data') as Ref<any>;
+  const _useTables = inject('useTables') as Ref<any>;
   const useFormData = inject('useFormData') as Ref<{}>;
-  const others = inject('others') as Ref<Recordable[]>;
+  const keyFieldValues = inject('keyFieldValues') as Ref<Recordable[]>;
+
   const go = useGo();
   const [registerItemAdd, { openModal: openItemModal }] = useModal();
   const cType = ref('');
   const dtlSlots = ref([] as any[]);
-  const selectVals = ref({});
-  const baseCards = ref([] as any[]);
   const useModalData = ref({}); //琛ㄥ崟涓彃妲芥覆鏌撴寜閽墦寮�妯℃�佹useModal鏂规硶
   const custImport = ref<any[]>([]);
   const EntityCustFunction = ref([
     {
       ActionItem(params, data, ...args) {},
       EditOperation(data, d, u, item) {},
-      GetBaseColumns(type: string | undefined) {},
-      GetSearchForm(type: string | undefined) {},
       GetCrudForm(type: string | undefined, ...args) {},
-      OthersValues(val, id) {},
+      KeyFieldValues(val, id) {},
       GetTitle(type: string | undefined) {},
       GetUseTables(data: Ref<Recordable[]>, ...args) {},
       GetUseDrawers() {},
+      CustInitData(data: Ref<any[]>, keyFieldValues: Ref<{}>, type: string) {},
     } as EntityCustFunctionType,
   ]);
   /* 鍔ㄦ�乮mport瀹炰綋鍚�.ts鐨勮嚜瀹氫箟鏂规硶 */
@@ -92,21 +92,21 @@
     {
       ActionItem: nActionItem,
       EditOperation,
-      GetBaseColumns,
-      GetSearchForm,
       GetCrudForm,
-      OthersValues,
+      KeyFieldValues,
       GetTitle,
       GetUseTables,
       GetUseDrawers,
+      CustInitData,
     },
   ] = isNullOrUnDef(custImport.value['default'])
     ? EntityCustFunction.value
     : custImport.value['default']();
-  others.value = OthersValues(objParams['CODE'], objParams['ID']);
-  const drawers = ref<any[]>(objParams['drawers']);
-  const useTables = GetUseTables(data);
-  const useDrawers = GetUseDrawers();
+  keyFieldValues.value = KeyFieldValues(objParams.value['CODE'], objParams.value['ID']); //鑾峰彇涓�浜涘叾浠栨湁闇�瑕佹彁渚涚殑鍊硷紝杩欓噷鏄富椤甸潰璺宠浆杩囨潵鏃跺甫鐨勫叧閿瓧娈靛��
+  const drawers = ref<any[]>(objParams.value['drawers']); //鏄彸渚ц竟妗嗗垪琛紝閲岄潰鐨刵ame琛ㄧず鏄摢涓�涓疄浣擄紝涔熷氨鏄珮绾ц〃鍗曚腑琛ㄦ牸鐨勫悕瀛楋紝寰堝鏂规硶闇�瑕佷互杩欎釜鍚嶅瓧涓簁ey
+  const useTables = GetUseTables(data, emit); //楂樼骇琛ㄥ崟涓悇涓〃鏍�(Table)鐨剈seTable鏂规硶瀹炵幇鍒楄〃
+  const useDrawers = GetUseDrawers(); //楂樼骇琛ㄥ崟涓悇涓〃鏍�(Table)鐨勫彸渚ц竟妗�(Drawer)鐨剈seDrawer鏂规硶瀹炵幇鍒楄〃
+  _useTables.value = useTables; //鎶妘seTable鐨勫垪琛ㄥ搷搴斿埌浠庝富椤甸潰娉ㄥ叆鐨刜useTables锛岃繖鏍蜂富椤甸潰鑳芥嬁鍒皍seTable鐨勭粨鏋滐紝浠庤�屽彲浠ヤ娇鐢ㄥ悇涓〃鏍肩殑鍐呯疆鏂规硶
   // watch(
   //   () => props.dataSource,
   //   (newVal, oldVal) => {
@@ -123,18 +123,31 @@
   //   { deep: true, immediate: true },
   // );
 
+  /**
+   * @description: 鎸傝浇缁勪欢瀹屾垚鏃�
+   * @return {*}
+   */
   onMounted(async () => {
     for (const i in drawers.value) {
       let sqlcmd = ' 1 =1 ';
-      if (!isNullOrEmpty(others.value[drawers.value[i].code])) {
-        sqlcmd += ` And ${drawers.value[i].code} = '${others.value[drawers.value[i].code]}'`;
+      if (!isNullOrEmpty(keyFieldValues.value[drawers.value[i].code])) {
+        sqlcmd += ` And ${drawers.value[i].code} = '${keyFieldValues.value[drawers.value[i].code]}'`;
+      }
+      /* type: all-琛ㄧず闇�瑕乧ode鐨勬墍鏈夌殑鍊� */
+      if (drawers.value[i]['type'] == 'all' && data.value[drawers.value[i]['keyName']].length > 0) {
+        sqlcmd += ` And ${drawers.value[i]['code']} in (${data.value[drawers.value[i]['keyName']].map((value) => `'${value[drawers.value[i]['code']]}'`).join(',')})`;
       }
       const list = await getEntity({
         sqlcmd: sqlcmd,
-        entityName: drawers.value[i].name,
+        entityName: isNullOrEmpty(drawers.value[i].dataType)? drawers.value[i].name: drawers.value[i].dataType,
+        order: drawers.value[i].order,
       });
       if (!isNullOrEmpty(list.Data) && !isNullOrEmpty(list.Data.Items)) {
         data.value[drawers.value[i].name] = list.Data.Items;
+        // 鑷畾涔夊垵濮嬪寲鏁版嵁
+        if (CustInitData && isFunction(CustInitData)) {
+          CustInitData(data, keyFieldValues, drawers.value[i].name);
+        }
         useTables[drawers.value[i].name][1].setProps({
           dataSource: [],
         });
@@ -151,24 +164,26 @@
    * @param {*} record
    * @return {*}
    */
-  function createActions(record,index, item) {
+  function createActions(record, index, item) {
     const params = {
       record,
       isUpdate: true,
       ifSave: true,
       entityName: props.entityName,
-      formJson: GetCrudForm(item), //getFormSchema(`${entityName.value}_Crud`),
+      formJson: [], //getFormSchema(`${entityName.value}_Crud`),
       cType,
       dtlSlots,
       useModalData,
       useFormData,
       crudColSlots: props.crudColSlots,
       data,
+      name: item.name, //drawers鍒楄〃閲岄潰鐨刵ame锛岃〃绀烘槸鍝竴涓疄浣擄紝涔熷氨鏄珮绾ц〃鍗曚腑琛ㄦ牸鐨勫悕瀛�
+      keyName: item.keyName,
     };
     const actionItem = [
       {
         icon: 'clarity:note-edit-line',
-        onClick: editRecord.bind(null, useDrawers[index][item][1].openDrawer, params),
+        onClick: editRecord.bind(null, useDrawers[index][item.name][1].openDrawer, params),
       },
       {
         icon: 'ant-design:delete-outlined',
@@ -176,24 +191,22 @@
         popConfirm: {
           title: '鏄惁纭鍒犻櫎?',
           placement: 'left',
-          confirm: deleteRecord.bind(null, useTables[item][1].reload, params),
+          confirm: deleteRecord.bind(null, useTables[item.name][1].reload, params),
         },
       },
     ];
     if (isNullOrUnDef(custImport.value)) {
       return actionItem;
     }
-    const [{ ActionItem }] = custImport.value['default']();
-    return ActionItem(
+    return nActionItem(
       params,
       actionItem,
-      useDrawers[index][item][1].openDrawer,
-      useTables[item][1].reload,
+      useDrawers[index][item.name][1].openDrawer,
+      useTables,
       null,
       useForm,
       useModal,
       go,
-      useTables[item][1].setProps,
     );
   }
 
@@ -237,25 +250,30 @@
     return validates;
   }
 
+  /**
+   * @description: 鏂板鎸夐挳鏂规硶
+   * @param {*} index
+   * @param {*} item
+   * @return {*}
+   */
   function handleCreate(index, item) {
     validate().then((res) => {
       const Keys = Object.getOwnPropertyNames(useFormData.value);
-      let i;
-      for (i = 0; i < Keys.length; i++) {
-        others.value[objParams['pCode']] = objParams['IsID']
+      for (const i in Keys) {
+        keyFieldValues.value[item['code']] = objParams.value['IsID']
           ? res[Keys[i]]['ID']
-          : res[Keys[i]][objParams['pCode']] == '0' ||
-              isNullOrUnDef(res[Keys[i]][objParams['pCode']])
-            ? res[Keys[i]][objParams['mCode']]
-            : res[Keys[i]][objParams['pCode']];
+          : res[Keys[i]][item['code']];
       }
-      useDrawers[index][item][1].openDrawer(true, {
+      useDrawers[index][item['name']][1].openDrawer(true, {
         isUpdate: false,
         ifSave: true,
-        entityName: props.entityName,
-        formJson: GetCrudForm(item), //getFormSchema(`${entityName.value}_Crud`),
+        entityName: item['name'], //props.entityName,
+        // formJson: GetCrudForm(item, data), //鑾峰彇澧炲垹鏀硅〃鍗曞瓧娈�
         crudColSlots: props.crudColSlots,
-        others: others.value,
+        keyFieldValues: keyFieldValues.value,
+        data,
+        name: item['name'], //drawers鍒楄〃閲岄潰鐨刵ame锛岃〃绀烘槸鍝竴涓疄浣擄紝涔熷氨鏄珮绾ц〃鍗曚腑琛ㄦ牸鐨勫悕瀛�
+        keyName: item['keyName'],
       });
     });
   }
@@ -264,6 +282,7 @@
    * @description: 鏂板缂栬緫杩斿洖鎴愬姛鏂规硶
    * @param {*} d
    * @param {*} u
+   * @param {*} item 椤甸潰涓婂惊鐜娊灞夊垪琛ㄤ紶鍏ョ殑瀹炰綋鍚嶅瓧锛屼綔涓哄悇琛ㄦ牸鐩稿叧鏂规硶鐨刱ey锛屼粠鑰岃皟鐢ㄥ悇琛ㄦ牸鐩稿叧鐨勬柟娉曪紝濡傦細useTables[item][1].setProps
    * @return {*}
    */
   function handleSuccess(d, u, item) {
@@ -284,7 +303,7 @@
    * @description: 寮瑰嚭閫夋嫨妗嗛�夋嫨鎴愬姛鍚庝簨浠�
    * @param {*} d
    * @param {*} u
-   * @param {*} item
+   * @param {*} item 椤甸潰涓婂惊鐜娊灞夊垪琛ㄤ紶鍏ョ殑瀹炰綋鍚嶅瓧锛屼綔涓哄悇琛ㄦ牸鐩稿叧鏂规硶鐨刱ey锛屼粠鑰岃皟鐢ㄥ悇琛ㄦ牸鐩稿叧鐨勬柟娉曪紝濡傦細useTables[item][1].getForm()
    * @return {*}
    */
   function handleItemSuccess(d, u, item) {

--
Gitblit v1.9.3