From 3bf0e1e45acfb85fb6054dc55d1c1204a6750998 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期二, 24 九月 2024 23:53:53 +0800
Subject: [PATCH] 通用增删改模态窗口更新,工单维护更新

---
 src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue |  246 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 180 insertions(+), 66 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue b/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue
index c3b5fd0..ff9bca1 100644
--- a/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue
+++ b/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue
@@ -6,11 +6,28 @@
       class="!mt-5"
       v-for="(item, index) in drawers"
     >
-      <BasicTable @register="useTables[item.name]">
+      <BasicTable
+        @register="useTables[item.name]"
+        :beforeEditSubmit="
+          ({ record, index, key, value }) =>
+            beforeEditSubmit({ record, index, key, value }, item.name)
+        "
+        @edit-end="
+          ({ record, index, key, value }) => handleEditEnd({ record, index, key, value }, item.name)
+        "
+      >
         <template #toolbar>
-          <a-button type="primary" @click="handleCreate(index, item)" preIcon="add_02|svg">
-            鏂板
+          <a-button
+            v-if="item.showTbButton"
+            type="primary"
+            v-for="d in buttons.filter((m) => m['BUTTON_TYPE'] == 0)"
+            @click="handleCreate(index, item, d)"
+            :preIcon="d['ICON_URL']"
+            :key="d"
+          >
+            {{ d['FUNC_NAME'] }}
           </a-button>
+          <a-button v-if="item.showTbButton" @click="openImg" type="primary"> 棰勮 </a-button>
         </template>
         <template #action="{ record }">
           <TableAction :actions="createActions(record, index, item)" />
@@ -49,10 +66,17 @@
   import { useI18n } from '/@/hooks/web/useI18n';
   import { Card } from 'ant-design-vue';
   import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
+  import { useRouter } from 'vue-router';
+  import { getRoleButtons } from '/@/api/sys/menu';
+  import { GenerateActionButton } from '../../data';
+  import { CustModalParams } from '/@/api/tigerapi/model/systemModel';
+  import { useWebSocketStore } from '/@/store/modules/websocket';
+  import { useTabs } from '/@/hooks/web/useTabs';
+  import { createImgPreview } from '/@/components/Preview';
 
   const { t } = useI18n();
   const ACard = Card;
-  const emit = defineEmits(['search']);
+  const emit = defineEmits(['search', 'opencust', 'gettables']);
   const props = defineProps({
     colSlots: { type: Array as PropType<any[]> },
     useTableData: { type: Object as PropType<{}>, default: { table: [] } },
@@ -67,6 +91,7 @@
   const keyFieldValues = inject('keyFieldValues') as Ref<Recordable[]>;
 
   const go = useGo();
+  const { currentRoute } = useRouter();
   const [registerItemAdd, { openModal: openItemModal }] = useModal();
   const cType = ref('');
   const dtlSlots = ref([] as any[]);
@@ -82,6 +107,9 @@
       GetUseTables(data: Ref<Recordable[]>, ...args) {},
       GetUseDrawers() {},
       CustInitData(data: Ref<any[]>, keyFieldValues: Ref<{}>, type: string) {},
+      GetNewRow(type: string) {},
+      CreateAction(type: string, ...args) {},
+      CustEditEnd({ record, index, key, value }: Recordable, type, ...args) {},
     } as EntityCustFunctionType,
   ]);
   /* 鍔ㄦ�乮mport瀹炰綋鍚�.ts鐨勮嚜瀹氫箟鏂规硶 */
@@ -98,36 +126,54 @@
       GetUseTables,
       GetUseDrawers,
       CustInitData,
+      CreateAction,
+      CustFunc,
+      GetNewRow,
+      CustEditEnd,
     },
   ] = isNullOrUnDef(custImport.value['default'])
     ? EntityCustFunction.value
     : custImport.value['default']();
+  const buttons = ref<[]>(await getRoleButtons(currentRoute.value.meta.menuCode as string));
   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) => {
-  //     nextTick(() => {
-  //       setProps({
-  //         dataSource: [],
-  //       });
-  //       data.value = newVal;
-  //       setProps({
-  //         dataSource: data,
-  //       });
-  //     });
-  //   },
-  //   { deep: true, immediate: true },
-  // );
+  const webSocketStore = useWebSocketStore();
+  const { refreshPage } = useTabs();
+  watch(
+    () => webSocketStore.socketMessage,
+    (newVal, oldVal) => {
+      console.log(oldVal, newVal);
+      /* 濡傛灉鐩戝惉鍒扮殑鍊间笉涓�鏍凤紝鍒欏埛鏂伴〉闈� */
+      if (
+        newVal != oldVal &&
+        !isNullOrEmpty(oldVal) &&
+        newVal['Data'] == 'Content' &&
+        newVal['IsSuccessed']
+      ) {
+        // init().then(() => {
+        //   refreshPage();
+        // });
+      }
+    },
+    { deep: true, immediate: true },
+  );
 
   /**
    * @description: 鎸傝浇缁勪欢瀹屾垚鏃�
    * @return {*}
    */
   onMounted(async () => {
+    init();
+  });
+
+  /**
+   * @description: 鍒濆鍖栨暟鎹�
+   * @return {*}
+   */
+  async function init() {
     for (const i in drawers.value) {
       let sqlcmd = ' 1 =1 ';
       if (!isNullOrEmpty(keyFieldValues.value[drawers.value[i].code])) {
@@ -152,7 +198,7 @@
         data.value[drawers.value[i].name] = list.Data.Items;
         // 鑷畾涔夊垵濮嬪寲鏁版嵁
         if (CustInitData && isFunction(CustInitData)) {
-          CustInitData(data, keyFieldValues, drawers.value[i].name);
+          CustInitData(data, keyFieldValues, drawers.value[i].name, useTables);
         }
         useTables[drawers.value[i].name][1].setProps({
           dataSource: [],
@@ -161,9 +207,19 @@
           dataSource: data.value[drawers.value[i].name],
         });
         useTables[drawers.value[i].name][1].reload();
+        emit('gettables', useTables);
       }
     }
-  });
+  }
+
+  const imgList = ['http://localhost:8800/files/Template/10浣嶆壒娆℃潯鐮�.png'];
+  function openImg() {
+    const onImgLoad = ({ index, url, dom }) => {
+      console.log(`绗�${index + 1}寮犲浘鐗囧凡鍔犺浇锛孶RL涓猴細${url}`, dom);
+    };
+    // 鍙互浣跨敤createImgPreview杩斿洖鐨� PreviewActions 鏉ユ帶鍒堕瑙堥�昏緫锛屽疄鐜扮被浼煎够鐏墖銆佽嚜鍔ㄦ棆杞箣绫荤殑楠氭搷浣�
+    createImgPreview({ imageList: imgList, defaultWidth: 700, rememberState: true, onImgLoad });
+  }
 
   /**
    * @description: 鐢熸垚鍒楄〃涓搷浣滈」鐨勬寜閽�
@@ -174,7 +230,7 @@
     const params = {
       record,
       isUpdate: true,
-      ifSave: true,
+      ifSave: objParams.value['ifSave'],
       entityName: props.entityName,
       formJson: [], //getFormSchema(`${entityName.value}_Crud`),
       cType,
@@ -186,21 +242,12 @@
       name: item.name, //drawers鍒楄〃閲岄潰鐨刵ame锛岃〃绀烘槸鍝竴涓疄浣擄紝涔熷氨鏄珮绾ц〃鍗曚腑琛ㄦ牸鐨勫悕瀛�
       keyName: item.keyName,
     };
-    const actionItem = [
-      {
-        icon: 'clarity:note-edit-line',
-        onClick: editRecord.bind(null, useDrawers[index][item.name][1].openDrawer, params),
-      },
-      {
-        icon: 'ant-design:delete-outlined',
-        color: 'error',
-        popConfirm: {
-          title: '鏄惁纭鍒犻櫎?',
-          placement: 'left',
-          confirm: deleteRecord.bind(null, useTables[item.name][1].reload, params),
-        },
-      },
-    ];
+    const actionItem = GenerateActionButton(
+      params,
+      buttons,
+      useDrawers[index][item.name][1].openDrawer,
+      useTables[item.name][1].reload(),
+    );
     if (isNullOrUnDef(custImport.value)) {
       return actionItem;
     }
@@ -214,32 +261,6 @@
       useModal,
       go,
     );
-  }
-
-  /**
-   * @description: 鍏敤缂栬緫鏂规硶
-   * @param {Fn} fn
-   * @param {*} params
-   * @return {*}
-   */
-  function editRecord(fn: Fn, params: {}) {
-    fn(true, params);
-  }
-
-  /**
-   * @description: 鍏敤鍒犻櫎鏂规硶
-   * @param {Fn} fn
-   * @param {*} params
-   * @return {*}
-   */
-  function deleteRecord(fn: Fn, params: {}) {
-    console.log(params['record']);
-    //鍒犻櫎
-    DeleteEntity(params['record'], params['entityName']).then((action) => {
-      if (action.IsSuccessed) {
-        fn();
-      }
-    });
   }
 
   /**
@@ -257,22 +278,23 @@
   }
 
   /**
-   * @description: 鏂板鎸夐挳鏂规硶
+   * @description: 鎵撳紑鎶藉眽鏂规硶
    * @param {*} index
    * @param {*} item
    * @return {*}
    */
-  function handleCreate(index, item) {
+  function CreateopenDrawer(index, item) {
     validate().then((res) => {
       const Keys = Object.getOwnPropertyNames(useFormData.value);
       for (const i in Keys) {
         keyFieldValues.value[item['code']] = objParams.value['IsID']
           ? res[Keys[i]]['ID']
           : res[Keys[i]][item['code']];
+        console.log(i);
       }
       useDrawers[index][item['name']][1].openDrawer(true, {
         isUpdate: false,
-        ifSave: true,
+        ifSave: objParams.value['ifSave'],
         entityName: item['name'], //props.entityName,
         // formJson: GetCrudForm(item, data), //鑾峰彇澧炲垹鏀硅〃鍗曞瓧娈�
         crudColSlots: props.crudColSlots,
@@ -282,6 +304,65 @@
         keyName: item['keyName'],
       });
     });
+  }
+
+  /**
+   * @description: 鏂板鎸夐挳鏂规硶
+   * @param {*} index
+   * @param {*} item
+   * @return {*}
+   */
+  function handleCreate(index, item, d) {
+    const _cruds = GetCrudForm();
+    let isExistSql = '';
+    for (const i in _cruds) {
+      if (_cruds[i].isexist == 'Y') {
+        isExistSql = _cruds[i].field;
+      }
+    }
+
+    if (isNullOrUnDef(custImport.value['default'])) {
+      CreateopenDrawer(index, item);
+    } else {
+      const result = CreateAction(item.name);
+      /* 鏍规嵁涓婚〉闈㈣烦杞紶杩囨潵鐨勫弬鏁扮‘瀹氭柊澧炴寜閽殑鎵ц鏂规硶 */
+      switch (result.action) {
+        case 'go':
+          sessionStorage.removeItem(`${result.params.Name}_update_params`);
+          // 灏嗗璞¤浆鎹负JSON瀛楃涓插苟淇濆瓨鍒皊essionStorage
+          sessionStorage.setItem(
+            `${result.params.Name}_update_params`,
+            encodeURI(JSON.stringify(result.params)),
+          );
+          go(
+            `/${result.url}/${encodeURI(JSON.stringify({ sName: `${result.params.Name}_update`, Name: result.params.Name }))}`,
+          );
+          break;
+        case 'drawer':
+          CreateopenDrawer(index, item);
+          break;
+        case 'edit':
+          const params: CustModalParams = {
+            mValues: {},
+            others: keyFieldValues.value,
+            cType: item.name,
+            values: GetNewRow(item.name),
+            initFnName: '',
+            FnName: item.FnName,
+            data: data,
+          };
+          /* 鑷畾涔夋柟娉� */
+          CustFunc(params);
+          useTables[item.name][1].setProps({
+            dataSource: [],
+          });
+          useTables[item.name][1].setProps({
+            dataSource: data.value[item.name],
+          });
+          useTables[item.name][1].reload();
+          break;
+      }
+    }
   }
 
   /**
@@ -381,4 +462,37 @@
         });
     } catch (e) {}
   }
+
+  /**
+   * @description: 鍗曞厓鏍肩紪杈戝畬鎴愬悗浜嬩欢
+   * @param {*} record
+   * @param {*} index
+   * @param {*} key
+   * @param {*} value
+   * @param {*} name
+   * @return {*}
+   */
+  function handleEditEnd({ record, index, key, value }: Recordable, name) {
+    console.log(record, index, key, value);
+    data.value[name][index] = record;
+    /* 鍗曞厓鏍肩紪杈戝畬鎴愬悗濡傛灉鏈夎嚜瀹氫箟鏂规硶锛屽氨璋冪敤 */
+    if (CustEditEnd && isFunction(CustEditEnd)) {
+      CustEditEnd({ record, index, key, value }, name, useTables, data);
+    }
+    return false;
+  }
+
+  /**
+   * @description: 鍗曞厓鏍兼彁浜や簨浠�
+   * @param {*} record
+   * @param {*} index
+   * @param {*} key
+   * @param {*} value
+   * @param {*} name
+   * @return {*}
+   */
+  async function beforeEditSubmit({ record, index, key, value }, name) {
+    console.log('鍗曞厓鏍兼暟鎹鍦ㄥ噯澶囨彁浜�', { record, index, key, value });
+    return true;
+  }
 </script>

--
Gitblit v1.9.3