<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { QcReportTemplateApi } from '#/api/mes/qc/report/template';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
import { DICT_TYPE } from '@vben/constants';
|
import { getDictOptions } from '@vben/hooks';
|
|
import { message, Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
copyTemplate,
|
deleteTemplate,
|
getTemplatePage,
|
} from '#/api/mes/qc/report/template';
|
import { $t } from '#/locales';
|
import { router } from '#/router';
|
|
import { useGridColumns, useGridFormSchema } from './data';
|
import Form from './modules/form.vue';
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
const pageSizeOptions = getDictOptions(DICT_TYPE.QC_REPORT_PAGE_SIZE, 'string');
|
const orientationOptions = getDictOptions(
|
DICT_TYPE.QC_REPORT_ORIENTATION,
|
'string',
|
);
|
|
function getDictLabel(options: typeof pageSizeOptions, value?: string): string {
|
return options.find((item) => item.value === value)?.label ?? value ?? '';
|
}
|
|
function getPageSetting(row: QcReportTemplateApi.Template): string {
|
const size = getDictLabel(pageSizeOptions, row.pageSize);
|
const orientation = getDictLabel(orientationOptions, row.orientation);
|
return [size, orientation].filter(Boolean).join(' / ');
|
}
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 创建报告模板 */
|
function handleCreate() {
|
formModalApi.setData(null).open();
|
}
|
|
/** 编辑报告模板 */
|
function handleEdit(row: QcReportTemplateApi.Template) {
|
formModalApi.setData(row).open();
|
}
|
|
/** 进入模板设计器 */
|
function handleDesign(row: QcReportTemplateApi.Template) {
|
router.push({
|
name: 'QcReportTemplateDesigner',
|
query: { id: row.id },
|
});
|
}
|
|
/** 复制报告模板 */
|
async function handleCopy(row: QcReportTemplateApi.Template) {
|
const hideLoading = message.loading({
|
content: `正在复制【${row.templateName}】...`,
|
duration: 0,
|
});
|
try {
|
await copyTemplate(row.id!);
|
message.success(`【${row.templateName}】复制成功`);
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 删除报告模板 */
|
async function handleDelete(row: QcReportTemplateApi.Template) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting', [row.templateName]),
|
duration: 0,
|
});
|
try {
|
await deleteTemplate(row.id!);
|
message.success($t('ui.actionMessage.deleteSuccess', [row.templateName]));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
return await getTemplatePage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<QcReportTemplateApi.Template>,
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<FormModal @success="handleRefresh" />
|
|
<Grid table-title="报告模板列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: $t('ui.actionTitle.create', ['报告模板']),
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['qc-report:template:create'],
|
onClick: handleCreate,
|
},
|
]"
|
/>
|
</template>
|
<template #pageSetting="{ row }">
|
{{ getPageSetting(row) }}
|
</template>
|
<template #currentVersion="{ row }">
|
<Tag v-if="row.currentVersion" color="green">
|
{{ row.currentVersion }}
|
</Tag>
|
<span v-else class="text-gray-400">未发布</span>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: '设计',
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['qc-report:template:update'],
|
onClick: handleDesign.bind(null, row),
|
},
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['qc-report:template:update'],
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '复制',
|
type: 'link',
|
icon: ACTION_ICON.COPY,
|
auth: ['qc-report:template:create'],
|
onClick: handleCopy.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['qc-report:template:delete'],
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [row.templateName]),
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|