Ben Lin
2024-10-24 5a813f3b28f3cbf1db3a3657ccf83267c6e0d315
src/views/tigerprojects/system/lowcode/normal/mainTable.vue
@@ -2,6 +2,7 @@
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <!-- 根据菜单设置的按钮,自动生成 -->
        <a-button
          type="primary"
          v-for="item in buttons.filter((m) => m['BUTTON_TYPE'] == 0)"
@@ -80,24 +81,28 @@
  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[]>;
@@ -111,6 +116,7 @@
  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerRv, { openModal: openRvModal, closeModal: RvcloseModal }] = useModal();
  const [registerCust, { openModal: openCustModal }] = useModal();
  const [registerCrud, { openModal: openCrudModal }] = useModal();
  const cType = ref('');
  const formSchemas = ref({}); //弹出框多表单结构
  const routeData = ref({
@@ -132,7 +138,9 @@
  /* 动态import实体名.ts的自定义方法 */
  try {
    custImport.value = await import(`../entityts/${objParams.value['ID']}.ts`);
  } catch (e) {}
  } catch (e) {
    console.log(e)
  }
  const [
    {
      ActionItem: nActionItem,
@@ -181,10 +189,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,
@@ -206,7 +218,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'],
@@ -228,7 +241,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>;
  /**
@@ -237,7 +282,7 @@
   * @return {*}
   */
  async function init(lf, rotId) {
    initRoute(lf, rotId, routeData, currlf);
    initRoute(lf, rotId, routeData, currlf, null);
  }
  /**
@@ -261,12 +306,16 @@
      currlf,
      selectVals,
      colSlots,
      ifSave: true,
      sName: objParams.value['sName'],
    };
    /* 根据菜单设置的按钮自动生成操作列中的按钮 */
    const actionItem = GenerateActionButton(params, buttons, openDrawer, reload);
    if (isNullOrUnDef(custImport.value['default'])) {
      return actionItem;
    }
    /* 根据动态加载的实体类名.ts中的ActionItem方法,渲染操作列中的按钮方法 */
    return nActionItem(
      params,
      actionItem,
@@ -278,6 +327,7 @@
      go,
      setProps,
      openCustModal,
      openCrudModal,
    );
  }
@@ -300,18 +350,21 @@
   */
  function handleCreate(fnName: string) {
    if (isNullOrUnDef(custImport.value['default'])) {
      /* 如果动态加载的实体类.ts不存在,则直接打开侧边框 */
      openDrawer(true, {
        isUpdate: false,
        entityName: entityName.value,
        formJson: _crudFormSchema.value,
        crudColSlots: objParams.value['crudColSlots'],
        isExistSql: isExistSql.value,
        isUpdate: false, //是新增还是编辑,false-新增|true-编辑
        entityName: entityName.value, //实体类名
        formJson: _crudFormSchema.value, //新增编辑的表单结构
        crudColSlots: objParams.value['crudColSlots'], //新增编辑的表单中的插槽列表
        isExistSql: isExistSql.value, //是否存在检查sql,比如: XXX_CODE = '12345'
        ifSave: true, //是否提交表单时保存到数据库,否-暂存|是-保存
      });
    } else {
      /* 如果动态加载的实体类.ts存在,根据.ts文件中的方法来执行操作 */
      const [{ CreateAction }] = custImport.value['default']();
      const result = CreateAction(entityName.value, colSlots.value);
      switch (result.action) {
        case 'go':
        case 'go' /* 跳转页面 */:
          // 将对象转换为JSON字符串并保存到sessionStorage
          sessionStorage.setItem(
            `${result.params.Name}_params`,
@@ -321,13 +374,14 @@
            `/${result.url}/${encodeURI(JSON.stringify({ sName: result.params.Name, Name: result.params.Name }))}`,
          );
          break;
        case 'drawer':
        case 'drawer' /* 打开侧边框 */:
          openDrawer(true, {
            isUpdate: false,
            entityName: entityName.value,
            formJson: _crudFormSchema.value,
            crudColSlots: objParams.value['crudColSlots'],
            isExistSql: isExistSql.value,
            isUpdate: false, //是新增还是编辑,false-新增|true-编辑
            entityName: entityName.value, //实体类名
            formJson: _crudFormSchema.value, //新增编辑的表单结构
            crudColSlots: objParams.value['crudColSlots'], //新增编辑的表单中的插槽列表
            isExistSql: isExistSql.value, //是否存在检查sql,比如: XXX_CODE = '12345'
            ifSave: true, //是否提交表单时保存到数据库,否-暂存|是-保存
          });
          break;
      }