YangYuGang
2025-03-08 8cae1dcd8d2bde01880ac4b70bdda4e61df3c7ef
src/views/components/CustModal.vue
@@ -4,7 +4,7 @@
 * @version: 
 * @Date: 2024-06-05 15:46:07
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-18 15:42:20
 * @LastEditTime: 2024-09-11 23:38:35
-->
<template>
  <BasicModal
@@ -12,6 +12,7 @@
    @register="registerModal"
    :title="title"
    @ok="handleSuccess"
    @cancel="handleCancel"
    :width="width"
  >
    <a-layout>
@@ -45,7 +46,7 @@
  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('');
@@ -53,12 +54,10 @@
  const FnName = ref('');
  const mValues = ref<Recordable>({});
  const initFnName = ref({});
  const dtlSlots = ref([] as any[]);
  const formSchema = ref([] as FormSchema[]);
  const formElName = ref([]);
  const useFormData = ref<any>({});
  const props = defineProps({
    detailSlots: { type: Array, default: [] },
    entityName: { type: String },
  });
@@ -70,46 +69,52 @@
  ]);
  /* 动态import实体名.ts的自定义方法 */
  try {
    custImport.value = await import(`../tigerprojects/system/lowcode/entityts/${props.entityName}.ts`);
    custImport.value = await import(
      `../tigerprojects/system/lowcode/entityts/${props.entityName}.ts`
    );
  } catch (e) {}
  const [{ CustFunc }] = isNullOrUnDef(custImport.value['default'])
  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 },
  // );
  watch(
    () => props.detailSlots,
    (v) => {
      if (v !== dtlSlots.value) {
        dtlSlots.value = v;
      }
    },
    { deep: true },
  );
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    await nextTick();
  const [registerModal, { setModalProps, closeModal }] = useModalInner((data) => {
    formSchema.value = [];
    setModalProps({ confirmLoading: false });
    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; //主表单传过来的数据
    //循环表单名数组,操作各表单字段
    formElName.value.forEach((name) => {
      if (!isNullOrUnDef(useFormData.value[name])) {
        useFormData.value[name][1]['resetFields']();
        if (unref(isUpdate)) {
          useFormData.value[name][1]['setFieldsValue']({
            ...mValues.value,
          });
    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?.initFnName)) {
      initFnName.value = data?.initFnName;
      let param: CustModalParams = {
@@ -118,6 +123,8 @@
        mValues: mValues.value,
        others: data?.others,
        FnName: initFnName.value[cType.value],
        initFnName: '',
        data: ref<any[]>([])
      };
      CustFunc(param);
    }
@@ -173,4 +180,12 @@
      setModalProps({ confirmLoading: false });
    }
  }
  /**
   * @description: 取消按钮触发取消事件
   * @return {*}
   */
  function handleCancel() {
    emit('cancel');
  }
</script>