From 697c405ac874da346e74df40266763370355154d Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期六, 08 三月 2025 15:40:25 +0800
Subject: [PATCH] ASN单

---
 src/views/components/CustModal.vue |  167 ++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 122 insertions(+), 45 deletions(-)

diff --git a/src/views/components/CustModal.vue b/src/views/components/CustModal.vue
index b4653f4..4470946 100644
--- a/src/views/components/CustModal.vue
+++ b/src/views/components/CustModal.vue
@@ -1,9 +1,18 @@
+<!--
+ * @Description: 鑷畾涔夊脊鍑烘锛屽彲浠ヨ嚜瀹氫箟澶氫釜琛ㄥ崟
+ * @Author: Ben Lin
+ * @version: 
+ * @Date: 2024-06-05 15:46:07
+ * @LastEditors: Ben Lin
+ * @LastEditTime: 2024-09-11 23:38:35
+-->
 <template>
   <BasicModal
     v-bind="$attrs"
     @register="registerModal"
     :title="title"
     @ok="handleSuccess"
+    @cancel="handleCancel"
     :width="width"
   >
     <a-layout>
@@ -22,64 +31,102 @@
   </BasicModal>
 </template>
 <script lang="ts" setup>
-  import { ref, unref, nextTick, watch } from 'vue';
+  import { ref, unref, nextTick, watch, Ref } from 'vue';
   import { BasicModal, useModalInner } from '/@/components/Modal';
   import { FormSchema } from '/@/components/Form/index';
-  import { custFunction } from './data';
   import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
   import { Layout, LayoutContent, Card } from 'ant-design-vue';
-  import { isNamedExportBindings } from 'typescript';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import { useI18n } from '/@/hooks/web/useI18n';
+  import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
+  import { CustModalParams } from '/@/api/tigerapi/model/systemModel';
 
+  const { t } = useI18n();
+  const { notification, createErrorModal } = useMessage();
   const ALayout = Layout;
   const ACard = Card;
   const ALayoutContent = LayoutContent;
-  const emit = defineEmits(['success', 'register']);
+  const emit = defineEmits(['success', 'register', 'modalInner', 'cancel']);
   const isUpdate = ref(true);
   const cType = ref('');
   const title = ref('');
   const width = ref('');
   const FnName = ref('');
-  const dtlSlots = ref([] as any[]);
+  const mValues = ref<Recordable>({});
+  const initFnName = ref({});
   const formSchema = ref([] as FormSchema[]);
   const formElName = ref([]);
-  const useFormData = ref({});
+  const useFormData = ref<any>({});
   const props = defineProps({
-    detailSlots: { type: Array, default: [] },
+    entityName: { type: String },
   });
-  watch(
-    () => props.detailSlots,
-    (v) => {
-      if (v !== dtlSlots.value) {
-        dtlSlots.value = v;
-      }
-    },
-    { deep: true },
-  );
 
-  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
-    await nextTick();
+  const custImport = ref<any[]>([]);
+  const EntityCustFunction = ref([
+    {
+      CustFunc(param: CustModalParams) {},
+    } as EntityCustFunctionType,
+  ]);
+  /* 鍔ㄦ�乮mport瀹炰綋鍚�.ts鐨勮嚜瀹氫箟鏂规硶 */
+  try {
+    custImport.value = await import(
+      `../tigerprojects/system/lowcode/entityts/${props.entityName}.ts`
+    );
+  } catch (e) {}
+  const [{ CustFunc, GetDtlSlots }] = isNullOrUnDef(custImport.value['default'])
+    ? EntityCustFunction.value
+    : custImport.value['default']();
+  const dtlSlots = ref<any[]>([]);
+  // watch(
+  //   () => props.detailSlots,
+  //   (v) => {
+  //     if (v !== dtlSlots.value) {
+  //       // dtlSlots.value = v;
+  //     }
+  //   },
+  //   { deep: true },
+  // );
+
+  const [registerModal, { setModalProps, closeModal }] = useModalInner((data) => {
     formSchema.value = [];
     setModalProps({ confirmLoading: false });
-    isUpdate.value = !!data?.isUpdate;
-    cType.value = data?.ctype;
-    title.value = data?.title;
-    width.value = data?.width;
-    formElName.value = data?.formElName;
-    useFormData.value = data?.formEl;
-    formElName.value.forEach((name) => {
-      if (!isNullOrUnDef(useFormData.value[name])) {
-        useFormData.value[name][1].resetFields();
-        if (unref(isUpdate)) {
-          useFormData.value[name][1].setFieldsValue({
-            ...data,
-          });
+    isUpdate.value = !!data?.isUpdate; //鏄惁鏇存柊
+    cType.value = data?.ctype; //鏄摢涓〉闈�
+    dtlSlots.value = GetDtlSlots(cType.value);
+    title.value = data?.title; //寮规鏍囬
+    width.value = data?.width; //寮规瀹藉害
+    formElName.value = data?.formElName; //寮规涓〃鍗曞悕瀛楁暟缁�
+    useFormData.value = data?.formEl; //寮规涓〃鍗曞疄渚嬫暟缁�
+    FnName.value = data?.fnName; //淇濆瓨鏁版嵁鏂规硶
+    mValues.value = data?.values; //涓昏〃鍗曚紶杩囨潵鐨勬暟鎹�
+
+    emit('modalInner', dtlSlots.value, async () => {
+      await nextTick();
+      /* 寰幆琛ㄥ崟鍚嶆暟缁勶紝鎿嶄綔鍚勮〃鍗曞瓧娈� */
+      formElName.value.forEach((name) => {
+        if (!isNullOrUnDef(useFormData.value[name])) {
+          useFormData.value[name][1]['resetFields']();
+          if (unref(isUpdate)) {
+            useFormData.value[name][1]['setFieldsValue']({
+              ...mValues.value,
+            });
+          }
         }
-      }
+      });
     });
-    //鍒濆鍖栨柟娉曡嚜瀹氫箟
-    if (!isNullOrEmpty(data?.FnName)) {
-      FnName.value = data?.FnName;
-      custFunction(unref(isUpdate.value), FnName.value, cType.value);
+    /* 鍒濆鍖栨柟娉曡嚜瀹氫箟 */
+    if (!isNullOrEmpty(data?.initFnName)) {
+      initFnName.value = data?.initFnName;
+      let param: CustModalParams = {
+        cType: cType.value,
+        values: unref(isUpdate.value),
+        mValues: mValues.value,
+        others: data?.others,
+        FnName: initFnName.value[cType.value],
+        initFnName: '',
+        data: ref<any[]>([])
+      };
+      CustFunc(param);
     }
   });
 
@@ -91,24 +138,54 @@
   //   { deep: true },
   // );
 
+  /**
+   * @description: 寮规纭畾鎸夐挳鏂规硶
+   * @return {*}
+   */
   async function handleSuccess() {
     try {
       var values = {} as any;
+      //寰幆琛ㄥ崟鍚嶆暟缁勶紝楠岃瘉鍚勮〃鍗曟暟鎹悎娉曟�э紝鍚堟硶鍒欒繑鍥炲悇琛ㄥ崟鏁版嵁锛岃繑鍥炲�煎彲浠ョ敤values['琛ㄥ崟鍚�']鑾峰彇琛ㄥ崟鏁版嵁
       for (let name of formElName.value) {
-        values[name] = await useFormData.value[name][1].validate();
+        if (!isNullOrEmpty(useFormData.value[name])) {
+          values[name] = await useFormData.value[name][1].validate();
+        }
       }
       setModalProps({ confirmLoading: true });
-
-      closeModal();
-      emit('success', {
-        isUpdate: isUpdate.value,
-        fnName: 'handleSubmit',
+      //璋冪敤鑷畾涔変繚瀛樻柟娉曚繚瀛樻暟鎹�
+      values['mValues'] = mValues.value;
+      const action = await CustFunc({
         cType: cType.value,
-        formElName: formElName.value,
-        values,
-      });
+        values: values,
+        FnName: FnName.value,
+      } as unknown as CustModalParams);
+      if (action.IsSuccessed) {
+        closeModal();
+        //鎴愬姛浜嬩欢锛屽皢鏁版嵁杩斿洖鍘熼〉闈�
+        emit('success', {
+          isUpdate: isUpdate.value,
+          fnName: 'handleSubmit',
+          cType: cType.value,
+          formElName: formElName.value,
+          values,
+        });
+      } else {
+        createErrorModal({
+          title: t('璀﹀憡'),
+          content: t(action.LocaleMsg),
+          getContainer: () => document.body,
+        });
+      }
     } finally {
       setModalProps({ confirmLoading: false });
     }
   }
+
+  /**
+   * @description: 鍙栨秷鎸夐挳瑙﹀彂鍙栨秷浜嬩欢
+   * @return {*}
+   */
+  function handleCancel() {
+    emit('cancel');
+  }
 </script>

--
Gitblit v1.9.3