Ben Lin
2024-12-28 f9eb1a419834f97a3ab0124b132de4f977b1973b
src/views/tigerprojects/system/lowcode/normal/mainTable.vue
@@ -38,7 +38,7 @@
        @cancel="custCancel"
        :type="cType"
        :entityName="entityName"
        @modalInner="getdtlSlots"
        @modal-inner="getdtlSlots"
      >
        <!-- 用插槽自定义多表单 -->
        <template #[item.name] v-for="item in dtlSlots" :key="item.name">
@@ -66,6 +66,7 @@
      </CustModal>
    </Suspense>
    <normalDrawer @register="registerDrawer" @success="handleSuccess" />
    <ImportExcelModal @register="registerImport" :title="ImportTitle" />
  </div>
</template>
<script lang="ts" setup>
@@ -77,28 +78,33 @@
  import normalDrawer from '../normalDrawer.vue';
  import CustModal from '/@/views/components/CustModal.vue';
  import RouteViewModal from '/@/views/components/RouteViewModal.vue';
  import ImportExcelModal from '/@/views/components/ImportExcelModal.vue';
  import { FlowChartView } from '/@/components/FlowChart';
  import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
  import { useModal } from '/@/components/Modal';
  import { useGo } from '/@/hooks/web/usePage';
  import { DeleteEntity, getEntity, getListByPage } from '/@/api/tigerapi/system';
  import { getListByPage } from '/@/api/tigerapi/system';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
  import { getRoleButtons } from '/@/api/sys/menu';
  import { useUserStore } from '/@/store/modules/user';
  import { useRouter } from 'vue-router';
  import { GenerateActionButton, initRoute, OpenCustModal } from '../data';
  import { afterFetchFn, GenerateActionButton, initRoute, SearchInfoFn } from '../data';
  import LogicFlow from '@logicflow/core';
  import { isFunction } from 'xe-utils';
  import { CustModalParams } from '/@/api/tigerapi/model/systemModel';
  import { useQueryStore } from '/@/store/modules/queryInpage';
  const { t } = useI18n();
  const { currentRoute } = useRouter();
  const route = unref(currentRoute);
  const useQuery = useQueryStore();
  const props = defineProps({
    useTableData: { type: Object as PropType<{}>, default: { table: [] } },
    crudColSlots: { type: Object as PropType<any> },
  });
  const objParams = inject('objParams') as Ref<any>;
  const savedParams = inject('savedParams') as Ref<any>;
  const colSlots = ref(objParams.value['colSlots']);
  const _columns = inject('_columns') as Ref<any[]>;
  const _searchFormSchema = inject('_searchFormSchema') as Ref<any[]>;
@@ -113,6 +119,7 @@
  const [registerRv, { openModal: openRvModal, closeModal: RvcloseModal }] = useModal();
  const [registerCust, { openModal: openCustModal }] = useModal();
  const [registerCrud, { openModal: openCrudModal }] = useModal();
  const [registerImport, { openModal: openImportModal }] = useModal();
  const cType = ref('');
  const formSchemas = ref({}); //弹出框多表单结构
  const routeData = ref({
@@ -134,7 +141,9 @@
  /* 动态import实体名.ts的自定义方法 */
  try {
    custImport.value = await import(`../entityts/${objParams.value['ID']}.ts`);
  } catch (e) {}
  } catch (e) {
    console.log(e);
  }
  const [
    {
      ActionItem: nActionItem,
@@ -145,6 +154,7 @@
      OpenSelectItem: OpenSelectCust,
      GetSelectSuccess,
      CustFunc,
      GetTitle,
    },
    ActionColumn,
  ] = isNullOrUnDef(custImport.value['default'])
@@ -155,6 +165,7 @@
    ? {}
    : KeyFieldValues(objParams.value['CODE'], objParams.value['ID']);
  const dtlSlots = ref<any[]>([]);
  const ImportTitle = GetTitle && isFunction(GetTitle)? ref(GetTitle().importTitle): ref('');
  const useformdata = GetUseForm && isFunction(GetUseForm) ? GetUseForm() : {};
  const useFormData = ref<any>(useformdata);
  /* 自定义模态窗口中表单中插槽渲染按钮打开模态框useModal方法 */
@@ -183,10 +194,14 @@
            }
          : '',
    },
    beforeFetch: (t) => SearchInfoFn(t, route.name, AuthOption.value['BY_ORG'] == 'Y'),
    afterFetch: afterFetch,
    columns: _columns as unknown as BasicColumn[],
    formConfig: {
      labelWidth: 140,
      schemas: _searchFormSchema as unknown as FormSchema[],
      submitFunc: () => Search(), //自定义查询提交按钮的方法,触发查询提交事件
      resetFunc: () => useQuery.resetFunc(route.name, getForm(), AuthOption.value['BY_ORG'] == 'Y'),
    },
    useSearchForm: true,
    showTableSetting: true,
@@ -208,7 +223,8 @@
    () => AuthOption.value,
    (newVal, oldVal) => {
      nextTick(() => {
        if (!isNullOrEmpty(newVal.BY_ORG)) {
        if (!isNullOrEmpty(newVal.BY_ORG) && !isNullOrUnDef(savedParams.value['params'])) {
          getForm().setFieldsValue(savedParams.value['params']);
          setProps({
            searchInfo: {
              TABLE_NAME: objParams.value['ID'],
@@ -230,7 +246,39 @@
    { deep: true, immediate: true },
  );
  onMounted(() => {});
  onMounted(async () => {
    if (!isNullOrUnDef(savedParams) && !isNullOrUnDef(savedParams.value['params'])) {
      getForm().setFieldsValue(savedParams.value['params']);
      reload();
    }
    // if (
    //   !isNullOrUnDef(useQuery.getCurSearchInfo['searchInfo']) &&
    //   useQuery.getCurSearchInfo['name'] == route.name
    // ) {
    //   getForm().resetFields();
    //   const searchInfo = useQuery.getCurSearchInfo['searchInfo'];
    //   await getForm().setFieldsValue(searchInfo);
    // }
  });
  /**
   * @description: 查询提交
   * @return {*}
   */
  async function Search() {
    useQuery.submitFunc(route.name, getForm(), AuthOption.value['BY_ORG'] == 'Y').then(() => {
      reload();
    });
  }
  /**
   * @description: 请求之后对返回值进行处理
   * @param {*} t
   * @return {*}
   */
  function afterFetch(t) {
    afterFetchFn(t, route.name, getForm());
  }
  const currlf = ref(null) as Ref<LogicFlow | null>;
  /**
@@ -264,6 +312,7 @@
      selectVals,
      colSlots,
      ifSave: true,
      sName: objParams.value['sName'],
    };
    /* 根据菜单设置的按钮自动生成操作列中的按钮 */
@@ -301,7 +350,7 @@
  }
  /**
   * @description: 获取新增按钮的行为
   * @description: 获取工具栏中按钮的行为
   * @return {*}
   */
  function handleCreate(fnName: string) {
@@ -318,7 +367,7 @@
    } else {
      /* 如果动态加载的实体类.ts存在,根据.ts文件中的方法来执行操作 */
      const [{ CreateAction }] = custImport.value['default']();
      const result = CreateAction(entityName.value, colSlots.value);
      const result = CreateAction(entityName.value, fnName);
      switch (result.action) {
        case 'go' /* 跳转页面 */:
          // 将对象转换为JSON字符串并保存到sessionStorage
@@ -340,6 +389,9 @@
            ifSave: true, //是否提交表单时保存到数据库,否-暂存|是-保存
          });
          break;
        case 'importModal' /* 打开导入Excel模态窗口 */:
          openImportModal(true, result.params);
          break;
      }
    }
  }