feat: 各模块支持导出

This commit is contained in:
caiyuchao
2025-09-15 18:34:33 +08:00
parent 9deb38593e
commit 9a876040fa
12 changed files with 393 additions and 73 deletions

View File

@@ -9,6 +9,7 @@ import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { message } from 'ant-design-vue';
import dayjs from 'dayjs';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
@@ -76,19 +77,15 @@ async function onDelete(row: ProjectApi.Project) {
}
/** 导出表格 */
async function onExport() {
const data = await exportProject(await gridApi.formApi.getValues());
async function onExport(body: any) {
const formValues = await gridApi.formApi.getValues();
const data = await exportProject({ ...body, ...formValues });
downloadFileFromBlobPart({
fileName: `${$t('project.project')}.xlsx`,
fileName: `${body.filename}.xlsx`,
source: data,
});
}
/** 导入项目 */
function handleImport() {
importModalApi.open();
}
/** 表格操作按钮的回调函数 */
function onActionClick({ code, row }: OnActionClickParams<ProjectApi.Project>) {
switch (code) {
@@ -125,6 +122,46 @@ const [Grid, gridApi] = useVbenVxeGrid({
customConfig: {
storage: true,
},
exportConfig: {
remote: true,
type: 'xlsx',
types: ['xlsx'],
mode: 'all',
modes: [
{ label: '导出全部数据', value: 'all' },
{ label: '导出当前页数据', value: 'current' },
],
filename() {
return `项目数据${dayjs().format('YYYYMMDDHHmmss')}`;
},
sheetName() {
return `项目列表`;
},
slots: {
parameter: 'exportParameter',
},
async exportMethod({ options, $grid }) {
const proxyInfo = $grid?.getProxyInfo();
// 处理条件参数
const body = {
filename: options.filename,
sheetName: options.sheetName,
isHeader: options.isHeader,
original: options.original,
mode: options.mode,
pageNo: proxyInfo ? proxyInfo.pager.currentPage : null,
pageSize: proxyInfo ? proxyInfo.pager.pageSize : null,
ids:
options.mode === 'selected'
? options.data.map((item) => item.id)
: [],
includeFields: options.columns.map((column) => {
return column.field;
}),
};
await onExport(body);
},
},
proxyConfig: {
sort: true,
ajax: {
@@ -150,6 +187,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
toolbarConfig: {
refresh: { code: 'query' },
search: true,
export: true,
},
} as VxeTableGridOptions<ProjectApi.Project>,
});
@@ -172,20 +210,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['license:project:create'],
onClick: onCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['license:project:export'],
onClick: onExport,
},
// {
// label: $t('ui.actionTitle.import', [$t('project.project')]),
// type: 'primary',
// icon: ACTION_ICON.UPLOAD,
// auth: ['license:project:import'],
// onClick: handleImport,
// },
]"
/>
</template>