<template>
|
<div>
|
<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">
|
<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, onMounted, ref, watch } from 'vue';
|
import { BasicTable, TableAction } from '/@/components/Table';
|
import { useForm } from '/@/components/Form/index';
|
import GeneralModal from '/@/views/components/GeneralModal.vue';
|
import normalDrawer from '../normalDrawer.vue';
|
import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
|
import { useModal } from '/@/components/Modal';
|
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 emit = defineEmits(['search']);
|
const props = defineProps({
|
colSlots: { type: Array as PropType<any[]> },
|
useTableData: { type: Object as PropType<{}>, default: { table: [] } },
|
entityName: { type: String },
|
crudColSlots: { type: Object as PropType<any> },
|
});
|
/* 主页面注入的变量 */
|
const objParams = inject('objParams') as Ref<any>;
|
const data = inject('data') as Ref<any>;
|
const _useTables = inject('useTables') as Ref<any>;
|
const useFormData = inject('useFormData') as Ref<{}>;
|
const keyFieldValues = inject('keyFieldValues') as Ref<Recordable[]>;
|
|
const go = useGo();
|
const [registerItemAdd, { openModal: openItemModal }] = useModal();
|
const cType = ref('');
|
const dtlSlots = ref([] as any[]);
|
const useModalData = ref({}); //表单中插槽渲染按钮打开模态框useModal方法
|
const custImport = ref<any[]>([]);
|
const EntityCustFunction = ref([
|
{
|
ActionItem(params, data, ...args) {},
|
EditOperation(data, d, u, item) {},
|
GetCrudForm(type: string | undefined, ...args) {},
|
KeyFieldValues(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,
|
GetCrudForm,
|
KeyFieldValues,
|
GetTitle,
|
GetUseTables,
|
GetUseDrawers,
|
},
|
] = isNullOrUnDef(custImport.value['default'])
|
? EntityCustFunction.value
|
: custImport.value['default']();
|
keyFieldValues.value = KeyFieldValues(objParams.value['CODE'], objParams.value['ID']); //获取一些其他有需要提供的值,这里是主页面跳转过来时带的关键字段值
|
const drawers = ref<any[]>(objParams.value['drawers']); //是右侧边框列表,里面的name表示是哪一个实体,也就是高级表单中表格的名字,很多方法需要以这个名字为key
|
const useTables = GetUseTables(data, emit); //高级表单中各个表格(Table)的useTable方法实现列表
|
const useDrawers = GetUseDrawers(); //高级表单中各个表格(Table)的右侧边框(Drawer)的useDrawer方法实现列表
|
_useTables.value = useTables; //把useTable的列表响应到从主页面注入的_useTables,这样主页面能拿到useTable的结果,从而可以使用各个表格的内置方法
|
// watch(
|
// () => props.dataSource,
|
// (newVal, oldVal) => {
|
// nextTick(() => {
|
// setProps({
|
// dataSource: [],
|
// });
|
// data.value = newVal;
|
// setProps({
|
// dataSource: data,
|
// });
|
// });
|
// },
|
// { deep: true, immediate: true },
|
// );
|
|
/**
|
* @description: 挂载组件完成时
|
* @return {*}
|
*/
|
onMounted(async () => {
|
for (const i in drawers.value) {
|
let sqlcmd = ' 1 =1 ';
|
if (!isNullOrEmpty(keyFieldValues.value[drawers.value[i].code])) {
|
sqlcmd += ` And ${drawers.value[i].code} = '${keyFieldValues.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();
|
}
|
}
|
});
|
|
/**
|
* @description: 生成列表中操作项的按钮
|
* @param {*} record
|
* @return {*}
|
*/
|
function createActions(record, index, item) {
|
const params = {
|
record,
|
isUpdate: true,
|
ifSave: true,
|
entityName: props.entityName,
|
formJson: GetCrudForm(item, data), //getFormSchema(`${entityName.value}_Crud`),
|
cType,
|
dtlSlots,
|
useModalData,
|
useFormData,
|
crudColSlots: props.crudColSlots,
|
data,
|
name: item, //drawers列表里面的name,表示是哪一个实体,也就是高级表单中表格的名字
|
};
|
const actionItem = [
|
{
|
icon: 'clarity:note-edit-line',
|
onClick: editRecord.bind(null, useDrawers[index][item][1].openDrawer, params),
|
},
|
{
|
icon: 'ant-design:delete-outlined',
|
color: 'error',
|
popConfirm: {
|
title: '是否确认删除?',
|
placement: 'left',
|
confirm: deleteRecord.bind(null, useTables[item][1].reload, params),
|
},
|
},
|
];
|
if (isNullOrUnDef(custImport.value)) {
|
return actionItem;
|
}
|
return nActionItem(
|
params,
|
actionItem,
|
useDrawers[index][item][1].openDrawer,
|
useTables[item][1].reload,
|
null,
|
useForm,
|
useModal,
|
go,
|
useTables[item][1].setProps,
|
);
|
}
|
|
/**
|
* @description: 公用编辑方法
|
* @param {Fn} fn
|
* @param {*} params
|
* @return {*}
|
*/
|
function editRecord(fn: Fn, params: {}) {
|
fn(true, params);
|
}
|
|
/**
|
* @description: 公用删除方法
|
* @param {Fn} fn
|
* @param {*} params
|
* @return {*}
|
*/
|
function deleteRecord(fn: Fn, params: {}) {
|
console.log(params['record']);
|
//删除
|
DeleteEntity(params['record'], params['entityName']).then((action) => {
|
if (action.IsSuccessed) {
|
fn();
|
}
|
});
|
}
|
|
/**
|
* @description: 验证表单
|
* @return {*}
|
*/
|
async function validate() {
|
let validates = {};
|
const Keys = Object.getOwnPropertyNames(useFormData.value);
|
let i;
|
for (i = 0; i < Keys.length; i++) {
|
validates[Keys[i]] = await useFormData.value[Keys[i]][1].validate();
|
}
|
return validates;
|
}
|
|
/**
|
* @description: 新增按钮方法
|
* @param {*} index
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleCreate(index, item) {
|
validate().then((res) => {
|
const Keys = Object.getOwnPropertyNames(useFormData.value);
|
for (const t in drawers.value) {
|
for (const i in Keys) {
|
keyFieldValues.value[drawers.value[t]['code']] = objParams.value['IsID']
|
? res[Keys[i]]['ID']
|
: res[Keys[i]][drawers.value[t]['code']];
|
}
|
useDrawers[index][item][1].openDrawer(true, {
|
isUpdate: false,
|
ifSave: true,
|
entityName: drawers.value[t]['name'], //props.entityName,
|
formJson: GetCrudForm(item, data), //获取增删改表单字段
|
crudColSlots: props.crudColSlots,
|
keyFieldValues: keyFieldValues.value,
|
});
|
}
|
});
|
}
|
|
/**
|
* @description: 新增编辑返回成功方法
|
* @param {*} d
|
* @param {*} u
|
* @param {*} item 页面上循环抽屉列表传入的实体名字,作为各表格相关方法的key,从而调用各表格相关的方法,如:useTables[item][1].setProps
|
* @return {*}
|
*/
|
function handleSuccess(d, u, item) {
|
if (!isNullOrUnDef(custImport.value)) {
|
/* 自定义编辑方法,根据实体名去调用 */
|
EditOperation(data, d, u, item);
|
useTables[item][1].setProps({
|
dataSource: [],
|
});
|
useTables[item][1].setProps({
|
dataSource: data.value[item],
|
});
|
useTables[item][1].reload();
|
}
|
}
|
|
/**
|
* @description: 弹出选择框选择成功后事件
|
* @param {*} d
|
* @param {*} u
|
* @param {*} item 页面上循环抽屉列表传入的实体名字,作为各表格相关方法的key,从而调用各表格相关的方法,如:useTables[item][1].getForm()
|
* @return {*}
|
*/
|
function handleItemSuccess(d, u, item) {
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
import(
|
`../entityts/${useTables[item][1].getForm().getFieldsValue()[`${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`]}.ts`
|
)
|
.then((m) => {
|
const [{ GetSelectSuccess }] = m.default();
|
useTables[item][1].getForm().setFieldsValue(GetSelectSuccess(d, u));
|
})
|
.catch(() => {
|
useTables[item][1].getForm().setFieldsValue({
|
ITEM_CODE: d.values['val'],
|
});
|
});
|
} catch (e) {}
|
}
|
|
/**
|
* @description: 弹出选择框
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleSelectItem(item) {
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
import(
|
`../entityts/${props.useTableData['table'][1].getForm().getFieldsValue()[`${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`]}.ts`
|
)
|
.then((m) => {
|
const [{ OpenSelectItem }] = m.default();
|
OpenSelectItem(openItemModal);
|
})
|
.catch(() => {
|
openItemModal(true, {
|
title: '物料列表',
|
schemas: [
|
{
|
field: 'ITEM_CODE',
|
component: 'Input',
|
label: '物料编码',
|
colProps: {
|
span: 12,
|
},
|
},
|
],
|
ItemColumns: [
|
{
|
title: t('物料编码'),
|
dataIndex: 'ITEM_CODE',
|
resizable: true,
|
sorter: true,
|
width: 200,
|
},
|
{
|
title: t('物料名称'),
|
dataIndex: 'ITEM_NAME',
|
resizable: true,
|
sorter: true,
|
width: 180,
|
},
|
],
|
tableName: 'BAS_ITEM',
|
rowKey: 'ITEM_CODE',
|
searchInfo: { TABLE_NAME: 'BAS_ITEM' },
|
});
|
});
|
} catch (e) {}
|
}
|
</script>
|