From ce374a9f4920a2d0e5ebe81a9872436088db6d55 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期五, 07 三月 2025 15:57:34 +0800
Subject: [PATCH] 高级页面主Form日期字段转换格式,否则出错

---
 src/views/tigerprojects/system/lowcode/high/baseForm.vue |  138 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 122 insertions(+), 16 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/high/baseForm.vue b/src/views/tigerprojects/system/lowcode/high/baseForm.vue
index c44a330..f76faba 100644
--- a/src/views/tigerprojects/system/lowcode/high/baseForm.vue
+++ b/src/views/tigerprojects/system/lowcode/high/baseForm.vue
@@ -4,7 +4,7 @@
  * @version: 
  * @Date: 2024-06-23 17:21:29
  * @LastEditors: Ben Lin
- * @LastEditTime: 2024-07-03 21:57:32
+ * @LastEditTime: 2024-08-01 10:40:57
 -->
 <template>
   <a-card
@@ -13,15 +13,32 @@
     v-for="(item, index) in _baseCards"
     :key="item.name"
   >
-    <BasicForm @register="useFormData[item.name][0]" />
+    <BasicForm @register="useFormData[item.name][0]">
+      <template #[l]="{ field }" v-for="l in colSlots" :key="l">
+        <a-button
+          v-if="field"
+          class="mt-1 ml-1"
+          size="small"
+          @click="handleSelectItem(l)"
+          preIcon="search|svg"
+        />
+        <GeneralModal @register="useModals[l]" @success="(d, u) => handleItemSuccess(d, u, l)" />
+      </template>
+    </BasicForm>
   </a-card>
 </template>
 <script lang="ts" setup>
   import { Ref, inject, nextTick, onMounted, ref, watch } from 'vue';
   import { BasicForm, useForm } from '/@/components/Form/index';
+  import GeneralModal from '/@/views/components/GeneralModal.vue';
   import { Card } from 'ant-design-vue';
   import { getEntity } from '/@/api/tigerapi/system';
-  import { isNullOrEmpty } from '/@/utils/is';
+  import { isNullOrEmpty, isNullOrUnDef, isTimeViaRegExp8601 } from '/@/utils/is';
+  import { useI18n } from '/@/hooks/web/useI18n';
+  import { isFunction } from 'xe-utils';
+import { dateUtil } from '/@/utils/dateUtil';
+
+  const { t } = useI18n();
   const props = defineProps({
     entityName: { type: String },
   });
@@ -29,21 +46,19 @@
   const objParams = inject('objParams') as Ref<any>;
   const useFormData = inject('useFormData') as Ref<{}>;
   const baseCards = inject('baseCards') as Ref<any>;
-  const custImport = ref<any[]>(
-    await import(`../entityts/${props.entityName}.ts`),
-  );
-  const [
-    {
-      GetBaseForm,
-      GetBaseCards,
-    },
-  ] = custImport.value['default']();
+  const custImport = ref<any[]>(await import(`../entityts/${props.entityName}.ts`));
+  const [{ GetBaseForm, GetBaseCards, GetUseModals }] = custImport.value['default']();
   const formSchemas = ref({
-    BaseForm: GetBaseForm(),
-  }); //寮瑰嚭妗嗘垨楂樼骇椤甸潰澶氳〃鍗曠粨鏋�
+    BaseForm: GetBaseForm(props.entityName, objParams.value['IsEdit']),
+  });
+  const colSlots = ref<any[]>(objParams.value['colSlotsInHigh']);
+  const useModals =
+    GetUseModals && isFunction(GetUseModals) ? ref<any>(GetUseModals()) : ref<any>({});
+
+  //寮瑰嚭妗嗘垨楂樼骇椤甸潰澶氳〃鍗曠粨鏋�
   useFormData.value = {
     BaseForm: useForm({
-      labelWidth: 120,
+      labelWidth: 160,
       schemas: formSchemas.value['BaseForm'],
       actionColOptions: {
         span: 24,
@@ -59,11 +74,102 @@
     getEntity({
       sqlcmd: ` ID = '${objParams.value['ID']}'`,
       entityName: _baseCards.value[0]['entityName'],
-      order: ''
+      order: '',
     }).then((res) => {
       if (!isNullOrEmpty(res.Data.Items)) {
+        /* 寰幆瀛楁鍚嶏紝鍒ゆ柇濡傛灉鏄椂闂寸殑灏辫浆鎹㈡垚dayjs鏍煎紡锛屽惁鍒欐椂闂撮�夋嫨鍣ㄤ細鍑洪敊 */
+      const Keys = Object.getOwnPropertyNames(res.Data.Items);
+      for (const k in Keys) {
+        if (!isNullOrUnDef(res.Data.Items[Keys[k]]) && isTimeViaRegExp8601(res.Data.Items[Keys[k]])) {
+          res.Data.Items[Keys[k]] = dateUtil(res.Data.Items[Keys[k]]); //杞崲鎴恉ayjs鏍煎紡
+        }
+      }
         useFormData.value[_baseCards.value[0]['name']][1].setFieldsValue(res.Data.Items[0]);
+      } else {
+        useFormData.value[_baseCards.value[0]['name']][1].setFieldsValue({
+          ID: objParams.value['ID'],
+        });
       }
     });
   });
+
+  /**
+   * @description: 寮瑰嚭閫夋嫨妗嗛�夋嫨鎴愬姛鍚庝簨浠�
+   * @param {*} d
+   * @param {*} u
+   * @param {*} item 椤甸潰涓婂惊鐜娊灞夊垪琛ㄤ紶鍏ョ殑瀹炰綋鍚嶅瓧锛屼綔涓哄悇琛ㄦ牸鐩稿叧鏂规硶鐨刱ey锛屼粠鑰岃皟鐢ㄥ悇琛ㄦ牸鐩稿叧鐨勬柟娉曪紝濡傦細useFormData.value[_baseCards.value[0]['name']][1].getForm()
+   * @return {*}
+   */
+  function handleItemSuccess(d, u, item) {
+    /* 鍔ㄦ�乮mport瀹炰綋鍚�.ts鐨勮嚜瀹氫箟鏂规硶 */
+    try {
+      import(
+        `../entityts/${useFormData.value[_baseCards.value[0]['name']][1].getFieldsValue()[`${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`]}.ts`
+      )
+        .then((m) => {
+          const [{ GetSelectSuccess }] = m.default();
+          useFormData.value[_baseCards.value[0]['name']][1].setFieldsValue(GetSelectSuccess(d, u));
+        })
+        .catch(() => {
+          useFormData.value[_baseCards.value[0]['name']][1].setFieldsValue({
+            ITEM_CODE: d.values['val'],
+          });
+        });
+    } catch (e) {}
+  }
+
+  /**
+   * @description: 寮瑰嚭閫夋嫨妗�
+   * @param {*} item
+   * @return {*}
+   */
+  function handleSelectItem(item) {
+    /* 鍔ㄦ�乮mport瀹炰綋鍚�.ts鐨勮嚜瀹氫箟鏂规硶 */
+    const name =
+      useFormData.value[_baseCards.value[0]['name']][1].getFieldsValue()[
+        `${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`
+      ];
+    const openModal = useModals.value[item][1].openModal;
+    try {
+      import(`../entityts/${name}.ts`)
+        .then((m) => {
+          const [{ OpenSelectItem }] = m.default();
+          OpenSelectItem(openModal);
+        })
+        .catch(() => {
+          openModal(true, {
+            title: '鐗╂枡鍒楄〃',
+            schemas: [
+              {
+                field: 'ITEM_CODE',
+                component: 'Input',
+                label: '鐗╂枡缂栫爜',
+                colProps: {
+                  span: 12,
+                },
+              },
+            ],
+            ItemColumns: [
+              {
+                title: t('鐗╂枡缂栫爜'),
+                dataIndex: 'ITEM_CODE',
+                resizable: true,
+                sorter: true,
+                width: 200,
+              },
+              {
+                title: t('鐗╂枡鍚嶇О'),
+                dataIndex: 'ITEM_NAME',
+                resizable: true,
+                sorter: true,
+                width: 180,
+              },
+            ],
+            tableName: 'BAS_ITEM',
+            rowKey: 'ITEM_CODE',
+            searchInfo: { TABLE_NAME: 'BAS_ITEM' },
+          });
+        });
+    } catch (e) {}
+  }
 </script>

--
Gitblit v1.9.3