<template>
|
<div>
|
<BasicTable @register="registerTable">
|
<template #toolbar>
|
<a-button
|
type="primary"
|
@click="handleCreate(item['DO_METHOD'])"
|
:preIcon="item['ICON_URL']"
|
v-for="item in buttons.filter((m) => m['BUTTON_TYPE'] == 0)"
|
:key="item"
|
>
|
{{ item['FUNC_NAME'] }}
|
</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" />
|
</div>
|
</template>
|
<script lang="ts" setup>
|
import { Ref, inject, nextTick, onMounted, ref, watch } from 'vue';
|
import {
|
BasicTable,
|
useTable,
|
TableAction,
|
BasicColumn,
|
FormSchema,
|
ActionItem,
|
PopConfirm,
|
} 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';
|
import { useModal } from '/@/components/Modal';
|
import { useGo } from '/@/hooks/web/usePage';
|
import { DeleteEntity, getEntity, 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 { useRouter } from 'vue-router';
|
|
const { t } = useI18n();
|
const { currentRoute } = useRouter();
|
const props = defineProps({
|
colSlots: { type: Array as PropType<any[]> },
|
useTableData: { type: Object as PropType<{}>, default: { table: [] } },
|
crudColSlots: { type: Object as PropType<any> },
|
});
|
const objParams = inject('objParams') as Ref<any>;
|
const _columns = inject('_columns') as Ref<any[]>;
|
const _searchFormSchema = inject('_searchFormSchema') as Ref<any[]>;
|
const _crudFormSchema = inject('_crudFormSchema') as Ref<any[]>;
|
const buttons = ref<[]>(await getRoleButtons(currentRoute.value.meta.menuCode as string));
|
const isExistSql = inject('isExistSql') as Ref<string>;
|
const keyFieldValues = inject('keyFieldValues') as Ref<Recordable[]>;
|
const entityName = ref(objParams['ID']);
|
const go = useGo();
|
const [registerDrawer, { openDrawer }] = useDrawer();
|
const [registerItemAdd, { openModal: openItemModal }] = useModal();
|
const cType = ref('');
|
const dtlSlots = ref([] as any[]);
|
const formSchemas = ref({}); //弹出框多表单结构
|
const useModalData = ref({}); //表单中插槽渲染按钮打开模态框useModal方法
|
const useFormData = ref({});
|
const custImport = ref<any[]>([]);
|
const EntityCustFunction = ref([
|
{
|
ActionItem(params, data, ...args) {},
|
KeyFieldValues(val, id) {},
|
} as EntityCustFunctionType,
|
]);
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
custImport.value = await import(`../entityts/${objParams['ID']}.ts`);
|
} catch (e) {}
|
const [
|
{
|
ActionItem: nActionItem,
|
KeyFieldValues,
|
},
|
] = isNullOrUnDef(custImport.value['default'])
|
? EntityCustFunction.value
|
: custImport.value['default']();
|
keyFieldValues.value = isNullOrUnDef(KeyFieldValues)
|
? {}
|
: KeyFieldValues(objParams['CODE'], objParams['ID']);
|
const [registerTable, { getForm, reload, setProps }] = useTable({
|
title: '列表信息',
|
api: getListByPage,
|
searchInfo: { TABLE_NAME: objParams['ID'] },
|
columns: _columns as unknown as BasicColumn[],
|
formConfig: {
|
labelWidth: 140,
|
schemas: _searchFormSchema as unknown as FormSchema[],
|
},
|
useSearchForm: true,
|
showTableSetting: true,
|
bordered: true,
|
canResize: true,
|
showIndexColumn: false,
|
actionColumn: {
|
width: 130,
|
title: '操作',
|
dataIndex: 'action',
|
slots: { customRender: 'action' },
|
fixed: undefined,
|
}, //自定义操作列
|
});
|
|
onMounted(() => {});
|
|
/**
|
* @description: 生成列表中操作项的按钮
|
* @param {*} record
|
* @return {*}
|
*/
|
function createActions(record) {
|
const params = {
|
record,
|
isUpdate: true,
|
entityName: objParams['ID'],
|
formJson: _crudFormSchema.value,
|
cType,
|
dtlSlots,
|
formSchemas,
|
useModalData,
|
useFormData,
|
crudColSlots: objParams['crudColSlots'],
|
};
|
|
const actionItem = GenerateActionButton(params);
|
if (isNullOrUnDef(custImport.value['default'])) {
|
return actionItem;
|
}
|
return nActionItem(
|
params,
|
actionItem,
|
openDrawer,
|
reload,
|
null,
|
useForm,
|
useModal,
|
go,
|
setProps,
|
);
|
}
|
|
/**
|
* @description: 获取权限按钮列表
|
* @param {*} params
|
* @return {*}
|
*/
|
function GenerateActionButton(params: any) {
|
let actionItem = [] as ActionItem[];
|
buttons.value.map((x) => {
|
if (x['BUTTON_TYPE'] == 1) {
|
let url = '';
|
let color = undefined as 'success' | 'error' | 'warning' | undefined;
|
let _click = null as any;
|
let _popConfirm = undefined as PopConfirm | undefined;
|
if (x['DO_METHOD'] == 'Edit') {
|
url = 'clarity:note-edit-line';
|
_click = editRecord.bind(null, openDrawer, params);
|
} else {
|
_click = x['ICON_URL'];
|
if (x['DO_METHOD'] == 'Delete') {
|
url = 'ant-design:delete-outlined';
|
color = 'error';
|
_popConfirm = {
|
title: '是否确认删除?',
|
placement: 'left',
|
confirm: deleteRecord.bind(null, reload, params),
|
};
|
}
|
}
|
actionItem.push({
|
icon: isNullOrEmpty(x['ICON_URL']) ? url : x['ICON_URL'],
|
onClick: _click,
|
color: color,
|
popConfirm: _popConfirm,
|
});
|
}
|
});
|
return actionItem;
|
}
|
|
/**
|
* @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 {*}
|
*/
|
function handleCreate(fnName: string) {
|
if (isNullOrUnDef(custImport.value['default'])) {
|
openDrawer(true, {
|
isUpdate: false,
|
entityName: entityName.value,
|
formJson: _crudFormSchema.value,
|
crudColSlots: objParams['crudColSlots'],
|
isExistSql: isExistSql.value,
|
});
|
} else {
|
const [{ CreateAction }] = custImport.value['default']();
|
const result = CreateAction(fnName);
|
switch (result.action) {
|
case 'go':
|
// 将对象转换为JSON字符串并保存到sessionStorage
|
sessionStorage.setItem(`${result.params.Name}_params`, encodeURI(JSON.stringify(result.params)));
|
go(`/${result.url}/${encodeURI(JSON.stringify({ sName: result.params.Name, Name: result.params.Name }))}`);
|
break;
|
case 'drawer':
|
openDrawer(true, {
|
isUpdate: false,
|
entityName: entityName.value,
|
formJson: _crudFormSchema.value,
|
crudColSlots: objParams['crudColSlots'],
|
isExistSql: isExistSql.value,
|
});
|
break;
|
}
|
}
|
}
|
|
/**
|
* @description: 新增编辑返回成功方法
|
* @param {*} d
|
* @param {*} u
|
* @return {*}
|
*/
|
function handleSuccess(d, u) {
|
reload();
|
}
|
|
/**
|
* @description: 弹出选择框选择成功后事件
|
* @param {*} d
|
* @param {*} u
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleItemSuccess(d, u, item) {
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
import(
|
`../entityts/${getForm().getFieldsValue()[`${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`]}.ts`
|
)
|
.then((m) => {
|
const [{ GetSelectSuccess }] = m.default();
|
getForm().setFieldsValue(GetSelectSuccess(d, u));
|
})
|
.catch(() => {
|
getForm().setFieldsValue({
|
ITEM_CODE: d.values['val'],
|
});
|
});
|
} catch (e) {}
|
}
|
|
/**
|
* @description: 弹出选择框
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleSelectItem(item) {
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
import(
|
`../entityts/${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>
|