From 04259fe9c84d819791cab926b959cab8dc6584b6 Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期二, 02 七月 2024 13:57:56 +0800 Subject: [PATCH] 高级表单多子表更新 --- src/views/tigerprojects/system/lowcode/high/dtl.vue | 193 ++++++++++++++++++++++++++++------------------- 1 files changed, 114 insertions(+), 79 deletions(-) diff --git a/src/views/tigerprojects/system/lowcode/high/dtl.vue b/src/views/tigerprojects/system/lowcode/high/dtl.vue index 1a893df..f7b1691 100644 --- a/src/views/tigerprojects/system/lowcode/high/dtl.vue +++ b/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, + ]); + /* 鍔ㄦ�乮mport瀹炰綋鍚�.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: undefined, - }, //鑷畾涔夋搷浣滃垪 - }); + ] = 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 @@ /* 鍔ㄦ�乮mport瀹炰綋鍚�.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'], }); }); -- Gitblit v1.9.3