From 2069d53e9be24adec3c8d6717fd7317555bd9a52 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期二, 02 七月 2024 23:02:51 +0800
Subject: [PATCH] 高级表单优化

---
 src/views/tigerprojects/system/lowcode/entityts/MES_SHIFT.ts |  747 +++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 533 insertions(+), 214 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/entityts/MES_SHIFT.ts b/src/views/tigerprojects/system/lowcode/entityts/MES_SHIFT.ts
index 751365f..be4ec99 100644
--- a/src/views/tigerprojects/system/lowcode/entityts/MES_SHIFT.ts
+++ b/src/views/tigerprojects/system/lowcode/entityts/MES_SHIFT.ts
@@ -4,21 +4,24 @@
  * @version:
  * @Date: 2024-06-19 20:34:27
  * @LastEditors: Ben Lin
- * @LastEditTime: 2024-07-01 12:33:25
+ * @LastEditTime: 2024-07-02 19:41:38
  */
 
-import { Ref, h, unref } from 'vue';
+import { Ref, h, ref, unref } from 'vue';
 import { DeleteEntity, GetEnum, getEntity } from '/@/api/tigerapi/system';
-import { ActionItem, BasicColumn } from '/@/components/Table';
+import { ActionItem, BasicColumn, FormSchema, useTable } from '/@/components/Table';
 import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
 import { buildUUID } from '/@/utils/uuid';
 import { useUserStore } from '/@/store/modules/user';
 import { formatToDateTime } from '/@/utils/dateUtil';
 import { Tag } from 'ant-design-vue';
 import { useLocale } from '/@/locales/useLocale';
+import { useDrawer } from '/@/components/Drawer';
+import { EditOperation, Search } from '../data';
 
 const { getLocale } = useLocale();
 function _default() {
+  let _data = ref<any>({});
   const ActionColumn: BasicColumn = {
     width: 80,
     title: '鎿嶄綔',
@@ -59,186 +62,15 @@
       const param = { ID: 'MES_SHIFT_SYS', colSlots: [], crudColSlots: [] };
       return `/MES_SHIFT_SYS/LC/${encodeURI(JSON.stringify(param))}`;
     },
-    GetBaseColumns: () => {
-      return [
-        {
-          title: '鐝缂栫爜',
-          dataIndex: 'SFT_CODE',
-          // ifShow: false,
-          width: 180,
-        },
-        {
-          title: '鐝鍚嶇О',
-          dataIndex: 'SFT_NAME',
-        },
-        {
-          title: '鐝埗缂栫爜',
-          dataIndex: 'SFTS_CODE',
-        },
-        {
-          title: '鐝寮�濮嬫椂闂�',
-          dataIndex: 'SFT_BEGIN',
-        },
-        {
-          title: '鐝缁撴潫鏃堕棿',
-          dataIndex: 'SFT_END',
-        },
-        {
-          title: '鏄惁璺ㄥぉ',
-          dataIndex: 'IS_ACROSS_DAY',
-          customRender: ({ record }) => {
-            const type = record.IS_ACROSS_DAY;
-            var text = '';
-            var color = 'green';
-            switch (type) {
-              case 'Y':
-                text = '鏄�';
-                break;
-              case 'N':
-                color = 'blue';
-                text = '鍚�';
-                break;
-            }
-            return h(Tag, { color: color }, () => text);
-          },
-        },
-        {
-          title: '澶囨敞',
-          dataIndex: 'REMARK',
-        },
-        {
-          title: '鏇存柊鏃堕棿',
-          dataIndex: 'UPDATE_TIME',
-        },
-        {
-          title: '鏇存柊浜�',
-          dataIndex: 'UPDATE_USER',
-        },
-      ];
+    GetBaseColumns: (type: string) => {
+      return baseColumns[type];
     },
-    GetSearchForm: () => {
-      return [
-        {
-          field: 'SFT_CODE',
-          label: '鐝缂栫爜',
-          component: 'Input',
-          colProps: {
-            span: 8,
-          },
-        },
-        {
-          label: '鐝鍚嶇О',
-          field: 'SFT_NAME',
-          component: 'Input',
-          colProps: {
-            span: 8,
-          },
-        },
-      ];
+    GetSearchForm: (type: string) => {
+      return searchForms[type];
     },
-    GetCrudForm: () => {
-      return [
-        {
-          field: 'SFT_CODE',
-          label: '鐝缂栫爜',
-          component: 'Input',
-          required: true,
-          colProps: {
-            span: 24,
-          },
-        },
-        {
-          label: '鐝鍚嶇О',
-          field: 'SFT_NAME',
-          component: 'Input',
-          required: true,
-          colProps: {
-            span: 24,
-          },
-        },
-        {
-          label: '鐝埗缂栫爜',
-          field: 'SFTS_CODE',
-          component: 'ApiSelect',
-          colProps: {
-            span: 24,
-          },
-          componentProps: {
-            api: getEntity,
-            params: { entityName: 'MES_SHIFT_SYS', sqlcmd: ' 1=1 ' },
-            resultField: 'Data.Items',
-            labelField: 'SFTS_NAME',
-            valueField: 'SFTS_CODE',
-          },
-          dynamicDisabled: ({ values }) => {
-            return true;
-          },
-        },
-        {
-          label: '鐝寮�濮嬫椂闂�',
-          field: 'SFT_BEGIN',
-          component: 'Input',
-          colProps: {
-            span: 24,
-          },
-        },
-        {
-          label: '鐝缁撴潫鏃堕棿',
-          field: 'SFT_END',
-          component: 'Input',
-          colProps: {
-            span: 24,
-          },
-        },
-        {
-          label: '鏄惁璺ㄥぉ',
-          field: 'IS_ACROSS_DAY',
-          component: 'Select',
-          required: true,
-          colProps: {
-            span: 24,
-          },
-          componentProps: {
-            options: [
-              {
-                label: '鏄�',
-                value: 'Y',
-                key: 'Y',
-              },
-              {
-                label: '鍚�',
-                value: 'N',
-                key: 'N',
-              },
-            ],
-          },
-        },
-        // {
-        //   field: 'LOGIN_TIME',
-        //   label: '鐧诲綍鏃堕棿',
-        //   defaultValue: '',
-        //   component: 'RangePicker',
-        //   ifShow: true,
-        //   colProps: { span: 8 },
-        // },
-        {
-          label: '澶囨敞',
-          field: 'REMARK',
-          component: 'Input',
-          colProps: {
-            span: 24,
-          },
-        },
-        {
-          label: 'ID',
-          field: 'ID',
-          component: 'Input',
-          colProps: {
-            span: 24,
-          },
-          show: false,
-        },
-      ];
+    GetCrudForm: (type: string, ...args) => {
+      _data = args[0];
+      return crudForms[type];
     },
     /**
      * @description: 鑾峰彇涓讳俊鎭�
@@ -328,6 +160,97 @@
         // { name: 'rotinfo', slots: ['add'], preIcons: { add: 'search|svg' }, title: '宸ヨ壓淇℃伅' },
       ];
     },
+    /**
+     * @description: 鑾峰彇鍙充晶杈规use鏂规硶
+     * @return {*}
+     */
+    GetUseDrawers: () => {
+      return [
+        {
+          MES_SHIFT: useDrawer(),
+        },
+        { MES_SHIFT_PRD: useDrawer() },
+      ];
+    },
+    /**
+     * @description: 鑾峰彇琛ㄦ牸use鍒楄〃
+     * @param {string} type
+     * @param {array} args
+     * @return {*}
+     */
+    GetUseTables: (data: Ref<{}>, ...args) => {
+      // _data = data;
+      return {
+        MES_SHIFT: useTable({
+          title: '鍒楄〃淇℃伅',
+          dataSource: data.value['MES_SHIFT'],
+          columns: baseColumns['MES_SHIFT'],
+          maxHeight: 230,
+          formConfig: {
+            labelWidth: 140,
+            schemas: searchForms['MES_SHIFT'],
+            submitFunc: () => Search('MES_SHIFT', data, args[0]), //鑷畾涔夋煡璇㈡彁浜ゆ寜閽殑鏂规硶锛岃Е鍙戞煡璇㈡彁浜や簨浠�
+          },
+          useSearchForm: true,
+          showTableSetting: true,
+          bordered: true,
+          canResize: true,
+          showIndexColumn: false,
+          actionColumn: {
+            width: 130,
+            title: '鎿嶄綔',
+            dataIndex: 'action',
+            slots: { customRender: 'action' },
+            fixed: 'right',
+          }, //鑷畾涔夋搷浣滃垪
+        }),
+        MES_SHIFT_PRD: useTable({
+          title: '鍒楄〃淇℃伅',
+          dataSource: data.value['MES_SHIFT_PRD'],
+          columns: baseColumns['MES_SHIFT_PRD'],
+          maxHeight: 260,
+          formConfig: {
+            labelWidth: 140,
+            schemas: searchForms['MES_SHIFT_PRD'],
+            submitFunc: () => Search('MES_SHIFT_PRD', data, args[0]), //鑷畾涔夋煡璇㈡彁浜ゆ寜閽殑鏂规硶锛岃Е鍙戞煡璇㈡彁浜や簨浠�
+          },
+          useSearchForm: true,
+          showTableSetting: true,
+          bordered: true,
+          canResize: true,
+          showIndexColumn: false,
+          actionColumn: {
+            width: 130,
+            title: '鎿嶄綔',
+            dataIndex: 'action',
+            slots: { customRender: 'action' },
+            fixed: 'right',
+          }, //鑷畾涔夋搷浣滃垪
+        }),
+      };
+    },
+    /**
+     * @description: 琛ㄦ牸鏌ヨ鍥炶皟锛岀埗缁勪欢涓�氳繃瀛愮粍浠惰Е鍙戠殑浜嬩欢鑾峰彇浼犲叆鐨勫�硷紝鍋氬叿浣撶殑鏌ヨ閫昏緫瀹炵幇
+     * @param {*} d
+     * @return {*}
+     */
+    FormSearch: (d) => {
+      let data = {} as any;
+      switch (d.type) {
+        case 'MES_SHIFT':
+          data = d.data.value[d.type].filter(
+            (item) =>
+              item.SFT_CODE.includes(d.values.SFT_CODE) || item.SFT_NAME == d.values.SFT_NAME,
+          );
+          if (isNullOrEmpty(d.values.SFT_CODE) && isNullOrEmpty(d.values.SFT_NAME)) {
+            data = d.data.value[d.type];
+          }
+          break;
+        case 'MES_SHIFT_PRD':
+          break;
+      }
+      return data;
+    },
     OthersValues: (val: string, id: string) => {
       return { SFTS_CODE: val };
     } /**
@@ -337,38 +260,22 @@
      * @param {*} u
      * @return {*}
      */,
-    EditOperation: (data: Ref<any[]>, d, u) => {
-      if (u.isUpdate) {
-        //鏇存柊
-        var _data = data.value.map((item) => {
-          if (item['ID'] == d.ID)
-            return {
-              ...item,
-              SFT_CODE: d.SFT_CODE,
-              SFT_NAME: d.SFT_NAME,
-              SFT_BEGIN: d.SFT_BEGIN,
-              SFT_END: d.SFT_END,
-              IS_ACROSS_DAY: d.IS_ACROSS_DAY,
-              REMARK: d.REMARK,
-            };
-          return item;
-        });
-        data.value = _data;
-      } else {
-        //鏂板
-        d.ID = buildUUID();
-        d.CREATE_USER = useUserStore().getUserInfo.userId as string;
-        d.UPDATE_TIME = formatToDateTime(new Date());
-        d.UPDATE_USER = useUserStore().getUserInfo.userId as string;
-        var _data2: any[] = [];
-        if (!isNullOrEmpty(data.value)) {
-          _data2 = data.value.map((item) => {
-            return item;
-          });
-        }
-        _data2.push(d);
-        data.value = _data2;
-      }
+    EditOperation: (data: Ref<any[]>, d, u, item) => {
+       //鏇存柊
+       var _data = data.value[item].map((item) => {
+        if (item['ID'] == d.ID)
+          return {
+            ...item,
+            SFT_CODE: d.SFT_CODE,
+            SFT_NAME: d.SFT_NAME,
+            SFT_BEGIN: d.SFT_BEGIN,
+            SFT_END: d.SFT_END,
+            IS_ACROSS_DAY: d.IS_ACROSS_DAY,
+            REMARK: d.REMARK,
+          };
+        return item;
+      });
+      EditOperation(data,d, u, item, _data);
     },
     /**
      * @description: 鑾峰彇鏍囬淇℃伅
@@ -379,10 +286,15 @@
       return {
         pageTitle: '鐝埗绠$悊',
         pageContent: '杩欓噷鍙互娣诲姞鍜屼慨鏀圭彮鍒跺拰鐝鍙婃椂娈点��',
-        baseTableTitle: '鐝绠$悊',
+        tableTitle: {
+          MES_SHIFT: '鐝绠$悊',
+          MES_SHIFT_PRD: '鏃舵绠$悊',
+        },
       };
     },
   };
+
+  /* 浠ヤ笅鏄唴閮ㄦ柟娉曪紝涓峞xport */
 
   /**
    * @description: 鑷畾涔夊垹闄ゆ柟娉�
@@ -410,6 +322,413 @@
     }
   }
 
+  /**
+   * @description: 琛ㄦ牸鍩烘湰瀛楁
+   * @return {*}
+   */
+  const baseColumns = {
+    MES_SHIFT: [
+      {
+        title: '鐝缂栫爜',
+        dataIndex: 'SFT_CODE',
+        // ifShow: false,
+        width: 180,
+      },
+      {
+        title: '鐝鍚嶇О',
+        dataIndex: 'SFT_NAME',
+      },
+      {
+        title: '鐝埗缂栫爜',
+        dataIndex: 'SFTS_CODE',
+      },
+      {
+        title: '鐝寮�濮嬫椂闂�',
+        dataIndex: 'SFT_BEGIN',
+      },
+      {
+        title: '鐝缁撴潫鏃堕棿',
+        dataIndex: 'SFT_END',
+      },
+      {
+        title: '鏄惁璺ㄥぉ',
+        dataIndex: 'IS_ACROSS_DAY',
+        customRender: ({ record }) => {
+          const type = record.IS_ACROSS_DAY;
+          var text = '';
+          var color = 'green';
+          switch (type) {
+            case 'Y':
+              text = '鏄�';
+              break;
+            case 'N':
+              color = 'blue';
+              text = '鍚�';
+              break;
+          }
+          return h(Tag, { color: color }, () => text);
+        },
+      },
+      {
+        title: '澶囨敞',
+        dataIndex: 'REMARK',
+      },
+      {
+        title: '鏇存柊鏃堕棿',
+        dataIndex: 'UPDATE_TIME',
+      },
+      {
+        title: '鏇存柊浜�',
+        dataIndex: 'UPDATE_USER',
+      },
+    ],
+    MES_SHIFT_PRD: [
+      {
+        title: '鏃舵缂栫爜',
+        dataIndex: 'PRD_CODE',
+        // ifShow: false,
+        width: 180,
+      },
+      {
+        title: '鏃舵鍚嶇О',
+        dataIndex: 'PRD_NAME',
+      },
+      {
+        title: '鐝缂栫爜',
+        dataIndex: 'SFT_CODE',
+      },
+      {
+        title: '鏃舵寮�濮嬫椂闂�',
+        dataIndex: 'PRD_BEGIN',
+      },
+      {
+        title: '鏃舵缁撴潫鏃堕棿',
+        dataIndex: 'PRD_END',
+      },
+      {
+        title: '鏄惁璺ㄥぉ',
+        dataIndex: 'IS_ACROSS',
+        customRender: ({ record }) => {
+          const type = record.IS_ACROSS;
+          var text = '';
+          var color = 'green';
+          switch (type) {
+            case 'Y':
+              text = '鏄�';
+              break;
+            case 'N':
+              color = 'blue';
+              text = '鍚�';
+              break;
+          }
+          return h(Tag, { color: color }, () => text);
+        },
+      },
+      {
+        title: '鏄惁浼戞伅鏃舵',
+        dataIndex: 'IS_REST',
+        customRender: ({ record }) => {
+          const type = record.IS_REST;
+          var text = '';
+          var color = 'green';
+          switch (type) {
+            case 'Y':
+              text = '鏄�';
+              break;
+            case 'N':
+              color = 'blue';
+              text = '鍚�';
+              break;
+          }
+          return h(Tag, { color: color }, () => text);
+        },
+      },
+      {
+        title: '鏃舵鎺掑簭',
+        dataIndex: 'SEQ',
+      },
+      {
+        title: '澶囨敞',
+        dataIndex: 'REMARK',
+      },
+      {
+        title: '鏇存柊鏃堕棿',
+        dataIndex: 'UPDATE_TIME',
+      },
+      {
+        title: '鏇存柊浜�',
+        dataIndex: 'UPDATE_USER',
+      },
+    ],
+  };
+
+  /**
+   * @description: 鏌ヨ瀛楁
+   * @return {*}
+   */
+  const searchForms = {
+    MES_SHIFT: [
+      {
+        field: 'SFT_CODE',
+        label: '鐝缂栫爜',
+        component: 'Input',
+        colProps: {
+          span: 8,
+        },
+      },
+      {
+        label: '鐝鍚嶇О',
+        field: 'SFT_NAME',
+        component: 'Input',
+        colProps: {
+          span: 8,
+        },
+      },
+    ] as FormSchema[],
+    MES_SHIFT_PRD: [
+      {
+        field: 'PRD_CODE',
+        label: '鏃舵缂栫爜',
+        component: 'Input',
+        colProps: {
+          span: 8,
+        },
+      },
+      {
+        label: '鏃舵鍚嶇О',
+        field: 'PRD_NAME',
+        component: 'Input',
+        colProps: {
+          span: 8,
+        },
+      },
+    ] as FormSchema[],
+  };
+
+  const crudForms = {
+    MES_SHIFT: [
+      {
+        field: 'SFT_CODE',
+        label: '鐝缂栫爜',
+        component: 'Input',
+        required: true,
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: '鐝鍚嶇О',
+        field: 'SFT_NAME',
+        component: 'Input',
+        required: true,
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: '鐝埗缂栫爜',
+        field: 'SFTS_CODE',
+        component: 'ApiSelect',
+        colProps: {
+          span: 24,
+        },
+        componentProps: {
+          api: getEntity,
+          params: { entityName: 'MES_SHIFT_SYS', sqlcmd: ' 1=1 ' },
+          resultField: 'Data.Items',
+          labelField: 'SFTS_NAME',
+          valueField: 'SFTS_CODE',
+        },
+        dynamicDisabled: ({ values }) => {
+          return true;
+        },
+      },
+      {
+        label: '鐝寮�濮嬫椂闂�',
+        field: 'SFT_BEGIN',
+        component: 'Input',
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: '鐝缁撴潫鏃堕棿',
+        field: 'SFT_END',
+        component: 'Input',
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: '鏄惁璺ㄥぉ',
+        field: 'IS_ACROSS_DAY',
+        component: 'Select',
+        required: true,
+        colProps: {
+          span: 24,
+        },
+        componentProps: {
+          options: [
+            {
+              label: '鏄�',
+              value: 'Y',
+              key: 'Y',
+            },
+            {
+              label: '鍚�',
+              value: 'N',
+              key: 'N',
+            },
+          ],
+        },
+      },
+      // {
+      //   field: 'LOGIN_TIME',
+      //   label: '鐧诲綍鏃堕棿',
+      //   defaultValue: '',
+      //   component: 'RangePicker',
+      //   ifShow: true,
+      //   colProps: { span: 8 },
+      // },
+      {
+        label: '澶囨敞',
+        field: 'REMARK',
+        component: 'Input',
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: 'ID',
+        field: 'ID',
+        component: 'Input',
+        colProps: {
+          span: 24,
+        },
+        show: false,
+      },
+    ],
+    MES_SHIFT_PRD: [
+      {
+        field: 'PRD_CODE',
+        label: '鏃舵缂栫爜',
+        component: 'Input',
+        required: true,
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: '鏃舵鍚嶇О',
+        field: 'PRD_NAME',
+        component: 'Input',
+        required: true,
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: '鐝缂栫爜',
+        field: 'SFT_CODE',
+        component: 'Select',
+        colProps: {
+          span: 24,
+        },
+        componentProps: () => {
+          const options = _data.value['MES_SHIFT'].map((entity) => ({
+            value: entity.SFT_CODE,
+            label: entity.SFT_NAME,
+          }));
+          return {
+            options: options,
+          };
+        },
+        // dynamicDisabled: ({ values }) => {
+        //   return true;
+        // },
+      },
+      {
+        label: '鏃舵寮�濮嬫椂闂�',
+        field: 'PRD_BEGIN',
+        component: 'Input',
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: '鏃舵缁撴潫鏃堕棿',
+        field: 'PRD_END',
+        component: 'Input',
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: '鏄惁璺ㄥぉ',
+        field: 'IS_ACROSS',
+        component: 'Select',
+        required: true,
+        colProps: {
+          span: 24,
+        },
+        componentProps: {
+          options: [
+            {
+              label: '鏄�',
+              value: 'Y',
+              key: 'Y',
+            },
+            {
+              label: '鍚�',
+              value: 'N',
+              key: 'N',
+            },
+          ],
+        },
+      },
+      {
+        label: '鏄惁浼戞伅鏃舵',
+        field: 'IS_REST',
+        component: 'Select',
+        required: true,
+        colProps: {
+          span: 24,
+        },
+        componentProps: {
+          options: [
+            {
+              label: '鏄�',
+              value: 'Y',
+              key: 'Y',
+            },
+            {
+              label: '鍚�',
+              value: 'N',
+              key: 'N',
+            },
+          ],
+        },
+      },
+      {
+        label: '澶囨敞',
+        field: 'REMARK',
+        component: 'Input',
+        colProps: {
+          span: 24,
+        },
+      },
+      {
+        label: 'ID',
+        field: 'ID',
+        component: 'Input',
+        colProps: {
+          span: 24,
+        },
+        show: false,
+      },
+    ],
+  };
+
   return [methods, ActionColumn];
 }
 

--
Gitblit v1.9.3