Ben Lin
2024-07-02 04259fe9c84d819791cab926b959cab8dc6584b6
src/views/tigerprojects/system/lowcode/high/dtl.vue
@@ -1,35 +1,46 @@
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate" preIcon="add_02|svg"> 新增 </a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="createActions(record)" />
      </template>
      <template #[item]="{ field }" v-for="item in colSlots" :key="item">
        <!-- <template #form-BAS_REASON3aadd="{ field }"> -->
        <a-button
          v-if="field"
          class="mt-1 ml-1"
          size="small"
          @click="handleSelectItem(item)"
          preIcon="search|svg"
        />
        <GeneralModal
          @register="registerItemAdd"
          @success="(d, u) => handleItemSuccess(d, u, item)"
        />
      </template>
    </BasicTable>
    <normalDrawer @register="registerDrawer" @success="handleSuccess" />
    <a-card
      :title="GetTitle()['tableTitle'][item.name]"
      :bordered="false"
      class="!mt-5"
      v-for="(item, index) in drawers"
    >
      <BasicTable @register="useTables[item.name]">
        <template #toolbar>
          <a-button type="primary" @click="handleCreate(index, item.name)" preIcon="add_02|svg">
            新增
          </a-button>
        </template>
        <template #action="{ record }">
          <TableAction :actions="createActions(record, index, item.name)" />
        </template>
        <template #[item]="{ field }" v-for="item in colSlots" :key="item">
          <!-- <template #form-BAS_REASON3aadd="{ field }"> -->
          <a-button
            v-if="field"
            class="mt-1 ml-1"
            size="small"
            @click="handleSelectItem(item)"
            preIcon="search|svg"
          />
          <GeneralModal
            @register="registerItemAdd"
            @success="(d, u) => handleItemSuccess(d, u, item)"
          />
        </template>
      </BasicTable>
      <normalDrawer
        @register="useDrawers[index][item.name]"
        @success="(d, u) => handleSuccess(d, u, item.name)"
      />
    </a-card>
  </div>
</template>
<script lang="ts" setup>
  import { Ref, inject, nextTick, onMounted, ref, watch } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { useDrawer } from '/@/components/Drawer';
  import GeneralModal from '/@/views/components/GeneralModal.vue';
  import normalDrawer from '../normalDrawer.vue';
  import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
@@ -37,9 +48,11 @@
  import { useGo } from '/@/hooks/web/usePage';
  import { DeleteEntity, getEntity } from '/@/api/tigerapi/system';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { Card } from 'ant-design-vue';
  import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
  const { t } = useI18n();
  const ACard = Card;
  const props = defineProps({
    colSlots: { type: Array as PropType<any[]> },
    useTableData: { type: Object as PropType<{}>, default: { table: [] } },
@@ -47,43 +60,53 @@
    crudColSlots: { type: Object as PropType<any> },
  });
  const objParams = inject('objParams') as Ref<any>;
  const data = inject('data') as Ref<Recordable[]>;
  const data = inject('data') as Ref<any>;
  const useFormData = inject('useFormData') as Ref<{}>;
  const others = inject('others') as Ref<Recordable[]>;
  const go = useGo();
  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerItemAdd, { openModal: openItemModal }] = useModal();
  const cType = ref('');
  const dtlSlots = ref([] as any[]);
  const selectVals = ref({});
  const baseCards = ref([] as any[]);
  const otherCards = ref([] as any[]);
  const useModalData = ref({}); //表单中插槽渲染按钮打开模态框useModal方法
  const custImport = ref<any[]>(await import(`../entityts/${props.entityName}.ts`));
  const [{ EditOperation, GetBaseColumns, GetSearchForm, GetCrudForm, OthersValues }] =
    custImport.value['default']();
  others.value = OthersValues(objParams['CODE'], objParams['ID']);
  const [registerTable, { getForm, reload, setProps }] = useTable({
    title: '列表信息',
    dataSource: data,
    columns: GetBaseColumns(),
    formConfig: {
      labelWidth: 140,
      schemas: GetSearchForm(),
  const custImport = ref<any[]>([]);
  const EntityCustFunction = ref([
    {
      ActionItem(params, data, ...args) {},
      EditOperation(data, d, u, item) {},
      GetBaseColumns(type: string | undefined) {},
      GetSearchForm(type: string | undefined) {},
      GetCrudForm(type: string | undefined, ...args) {},
      OthersValues(val, id) {},
      GetTitle(type: string | undefined) {},
      GetUseTables(data: Ref<Recordable[]>, ...args) {},
      GetUseDrawers() {},
    } as EntityCustFunctionType,
  ]);
  /* 动态import实体名.ts的自定义方法 */
  try {
    custImport.value = await import(`../entityts/${props.entityName}.ts`);
  } catch (e) {}
  const [
    {
      ActionItem: nActionItem,
      EditOperation,
      GetBaseColumns,
      GetSearchForm,
      GetCrudForm,
      OthersValues,
      GetTitle,
      GetUseTables,
      GetUseDrawers,
    },
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    canResize: true,
    showIndexColumn: false,
    actionColumn: {
      width: 130,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    }, //自定义操作列
  });
  ] = isNullOrUnDef(custImport.value['default'])
    ? EntityCustFunction.value
    : custImport.value['default']();
  others.value = OthersValues(objParams['CODE'], objParams['ID']);
  const drawers = ref<any[]>(objParams['drawers']);
  const useTables = GetUseTables(data);
  const useDrawers = GetUseDrawers();
  // watch(
  //   () => props.dataSource,
  //   (newVal, oldVal) => {
@@ -100,15 +123,27 @@
  //   { deep: true, immediate: true },
  // );
  onMounted(() => {
    getEntity({
      sqlcmd: ` ${objParams['pCode']} = '${others.value[objParams['pCode']]}'`,
      entityName: props.entityName as string,
    }).then((res) => {
      if (!isNullOrEmpty(res.Data.Items)) {
        data.value = res.Data.Items;
  onMounted(async () => {
    for (const i in drawers.value) {
      let sqlcmd = ' 1 =1 ';
      if (!isNullOrEmpty(others.value[drawers.value[i].code])) {
        sqlcmd += ` And ${drawers.value[i].code} = '${others.value[drawers.value[i].code]}'`;
      }
    });
      const list = await getEntity({
        sqlcmd: sqlcmd,
        entityName: drawers.value[i].name,
      });
      if (!isNullOrEmpty(list.Data) && !isNullOrEmpty(list.Data.Items)) {
        data.value[drawers.value[i].name] = list.Data.Items;
        useTables[drawers.value[i].name][1].setProps({
          dataSource: [],
        });
        useTables[drawers.value[i].name][1].setProps({
          dataSource: data.value[drawers.value[i].name],
        });
        useTables[drawers.value[i].name][1].reload();
      }
    }
  });
  /**
@@ -116,13 +151,13 @@
   * @param {*} record
   * @return {*}
   */
  function createActions(record) {
  function createActions(record,index, item) {
    const params = {
      record,
      isUpdate: true,
      ifSave: true,
      entityName: props.entityName,
      formJson: GetCrudForm(), //getFormSchema(`${entityName.value}_Crud`),
      formJson: GetCrudForm(item), //getFormSchema(`${entityName.value}_Crud`),
      cType,
      dtlSlots,
      useModalData,
@@ -133,7 +168,7 @@
    const actionItem = [
      {
        icon: 'clarity:note-edit-line',
        onClick: editRecord.bind(null, openDrawer, params),
        onClick: editRecord.bind(null, useDrawers[index][item][1].openDrawer, params),
      },
      {
        icon: 'ant-design:delete-outlined',
@@ -141,7 +176,7 @@
        popConfirm: {
          title: '是否确认删除?',
          placement: 'left',
          confirm: deleteRecord.bind(null, reload, params),
          confirm: deleteRecord.bind(null, useTables[item][1].reload, params),
        },
      },
    ];
@@ -152,13 +187,13 @@
    return ActionItem(
      params,
      actionItem,
      openDrawer,
      reload,
      useDrawers[index][item][1].openDrawer,
      useTables[item][1].reload,
      null,
      useForm,
      useModal,
      go,
      setProps,
      useTables[item][1].setProps,
    );
  }
@@ -202,7 +237,7 @@
    return validates;
  }
  function handleCreate() {
  function handleCreate(index, item) {
    validate().then((res) => {
      const Keys = Object.getOwnPropertyNames(useFormData.value);
      let i;
@@ -214,11 +249,11 @@
            ? res[Keys[i]][objParams['mCode']]
            : res[Keys[i]][objParams['pCode']];
      }
      openDrawer(true, {
      useDrawers[index][item][1].openDrawer(true, {
        isUpdate: false,
        ifSave: true,
        entityName: props.entityName,
        formJson: GetCrudForm(), //getFormSchema(`${entityName.value}_Crud`),
        formJson: GetCrudForm(item), //getFormSchema(`${entityName.value}_Crud`),
        crudColSlots: props.crudColSlots,
        others: others.value,
      });
@@ -231,17 +266,17 @@
   * @param {*} u
   * @return {*}
   */
  function handleSuccess(d, u) {
  function handleSuccess(d, u, item) {
    if (!isNullOrUnDef(custImport.value)) {
      /* 自定义编辑方法,根据实体名去调用 */
      EditOperation(data, d, u);
      setProps({
      EditOperation(data, d, u, item);
      useTables[item][1].setProps({
        dataSource: [],
      });
      setProps({
        dataSource: data,
      useTables[item][1].setProps({
        dataSource: data.value[item],
      });
      reload();
      useTables[item][1].reload();
    }
  }
@@ -256,14 +291,14 @@
    /* 动态import实体名.ts的自定义方法 */
    try {
      import(
        `../entityts/${getForm().getFieldsValue()[`${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`]}.ts`
        `../entityts/${useTables[item][1].getForm().getFieldsValue()[`${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`]}.ts`
      )
        .then((m) => {
          const [{ GetSelectSuccess }] = m.default();
          getForm().setFieldsValue(GetSelectSuccess(d, u));
          useTables[item][1].getForm().setFieldsValue(GetSelectSuccess(d, u));
        })
        .catch(() => {
          getForm().setFieldsValue({
          useTables[item][1].getForm().setFieldsValue({
            ITEM_CODE: d.values['val'],
          });
        });