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

@@ -78,7 +78,7 @@ export function deleteCustomer(id: number) {
/** 导出客户 */
export function exportCustomer(params: any) {
return requestClient.download('/license/customer/export-excel', params);
return requestClient.download('/license/customer/export-excel', { params });
}
/** 下载导入模板 */

View File

@@ -122,7 +122,7 @@ export function deleteLicense(id: number) {
/** 导出License */
export function exportLicense(params: any) {
return requestClient.download('/license/license/export-excel', params);
return requestClient.download('/license/license/export-excel', { params });
}
/** License SN是否唯一 */

View File

@@ -76,7 +76,7 @@ export function deleteProject(id: number) {
/** 导出项目 */
export function exportProject(params: any) {
return requestClient.download('/license/project/export-excel', params);
return requestClient.download('/license/project/export-excel', { params });
}
/** 下载导入模板 */

View File

@@ -36,3 +36,10 @@ export function getExpiryLicensePage(params: PageParam) {
{ params },
);
}
/** 导出 */
export function exportExpire(params: any) {
return requestClient.download('/license/report/expire/export-excel', {
params,
});
}

View File

@@ -45,3 +45,17 @@ export function getProgressByStaffPage(params: PageParam) {
{ params },
);
}
/** 导出 */
export function exportProject(params: any) {
return requestClient.download('/license/report/project/export-excel', {
params,
});
}
/** 导出 */
export function exportStaff(params: any) {
return requestClient.download('/license/report/staff/export-excel', {
params,
});
}

View File

@@ -7,6 +7,7 @@ import { Page, 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 {
@@ -65,19 +66,15 @@ async function onDelete(row: CustomerApi.Customer) {
}
/** 导出表格 */
async function onExport() {
const data = await exportCustomer(await gridApi.formApi.getValues());
async function onExport(body: any) {
const formValues = await gridApi.formApi.getValues();
const data = await exportCustomer({ ...body, ...formValues });
downloadFileFromBlobPart({
fileName: `${$t('customer.customer')}.xlsx`,
fileName: `${body.filename}.xlsx`,
source: data,
});
}
/** 导入客户 */
function handleImport() {
importModalApi.open();
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -105,6 +102,46 @@ const [Grid, gridApi] = useVbenVxeGrid({
return 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: {
ajax: {
query: async ({ page }, formValues) => {
@@ -123,6 +160,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
toolbarConfig: {
refresh: { code: 'query' },
search: true,
export: true,
},
} as VxeTableGridOptions<CustomerApi.Customer>,
});
@@ -144,20 +182,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['license:customer:create'],
onClick: onCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['license:customer:export'],
onClick: onExport,
},
// {
// label: $t('ui.actionTitle.import', [$t('customer.customer')]),
// type: 'primary',
// icon: ACTION_ICON.UPLOAD,
// auth: ['license:customer:import'],
// onClick: handleImport,
// },
]"
/>
</template>

View File

@@ -8,6 +8,7 @@ import { Page, 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 {
@@ -119,9 +120,13 @@ async function onDelete(row: LicenseApi.License) {
}
/** 导出表格 */
async function onExport() {
const data = await exportLicense(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: 'License.xlsx', source: data });
async function onExport(body: any) {
const formValues = await gridApi.formApi.getValues();
const data = await exportLicense({ ...body, ...formValues });
downloadFileFromBlobPart({
fileName: `${body.filename}.xlsx`,
source: data,
});
}
/** 导入用户 */
@@ -147,6 +152,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 `License数据${dayjs().format('YYYYMMDDHHmmss')}`;
},
sheetName() {
return `License列表`;
},
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: {
@@ -172,6 +217,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
toolbarConfig: {
refresh: { code: 'query' },
search: true,
export: true,
},
} as VxeTableGridOptions<LicenseApi.License>,
});
@@ -194,13 +240,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['license:license:apply'],
onClick: onCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['license:license:export'],
onClick: onExport,
},
{
label: $t('ui.actionTitle.import', ['License']),
type: 'primary',

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>

View File

@@ -1,12 +1,26 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { downloadFileFromBlobPart } from '@vben/utils';
import dayjs from 'dayjs';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getExpiryLicensePage } from '#/api/report/expire';
import { exportExpire, getExpiryLicensePage } from '#/api/report/expire';
import { useExpiringGridColumns, useExpiringGridFormSchema } from '../data';
const [Grid] = useVbenVxeGrid({
/** 导出表格 */
async function onExport(body: any) {
const formValues = await gridApi.formApi.getValues();
const data = await exportExpire({ ...body, ...formValues, isExpired: false });
downloadFileFromBlobPart({
fileName: `${body.filename}.xlsx`,
source: data,
});
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useExpiringGridFormSchema(),
submitOnEnter: true,
@@ -30,11 +44,10 @@ const [Grid] = useVbenVxeGrid({
pagerConfig: {
enabled: true,
},
exportConfig: {},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
// export: true,
export: true,
},
height: 'auto',
rowConfig: {
@@ -52,6 +65,46 @@ const [Grid] = useVbenVxeGrid({
virtualYConfig: {
enabled: false,
},
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);
},
},
headerCellStyle: { backgroundColor: '#fafafa' },
} as VxeTableGridOptions<any>,
});

View File

@@ -1,12 +1,26 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { downloadFileFromBlobPart } from '@vben/utils';
import dayjs from 'dayjs';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getExpiryLicensePage } from '#/api/report/expire';
import { exportExpire, getExpiryLicensePage } from '#/api/report/expire';
import { useExpiredGridColumns, useExpiredGridFormSchema } from '../data';
const [Grid] = useVbenVxeGrid({
/** 导出表格 */
async function onExport(body: any) {
const formValues = await gridApi.formApi.getValues();
const data = await exportExpire({ ...body, ...formValues, isExpired: true });
downloadFileFromBlobPart({
fileName: `${body.filename}.xlsx`,
source: data,
});
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useExpiredGridFormSchema(),
submitOnEnter: true,
@@ -30,11 +44,10 @@ const [Grid] = useVbenVxeGrid({
pagerConfig: {
enabled: true,
},
exportConfig: {},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
// export: true,
export: true,
},
height: 'auto',
rowConfig: {
@@ -52,6 +65,46 @@ const [Grid] = useVbenVxeGrid({
virtualYConfig: {
enabled: false,
},
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);
},
},
headerCellStyle: { backgroundColor: '#fafafa' },
} as VxeTableGridOptions<any>,
});

View File

@@ -1,12 +1,26 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { downloadFileFromBlobPart } from '@vben/utils';
import dayjs from 'dayjs';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getProgressByStaffPage } from '#/api/report/progress';
import { exportStaff, getProgressByStaffPage } from '#/api/report/progress';
import { useStaffGridColumns, useStaffGridFormSchema } from '../data';
const [Grid] = useVbenVxeGrid({
/** 导出表格 */
async function onExport(body: any) {
const formValues = await gridApi.formApi.getValues();
const data = await exportStaff({ ...body, ...formValues });
downloadFileFromBlobPart({
fileName: `${body.filename}.xlsx`,
source: data,
});
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useStaffGridFormSchema(),
submitOnEnter: true,
@@ -29,11 +43,10 @@ const [Grid] = useVbenVxeGrid({
pagerConfig: {
enabled: true,
},
exportConfig: {},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
// export: true,
export: true,
},
height: 'auto',
rowConfig: {
@@ -51,6 +64,46 @@ const [Grid] = useVbenVxeGrid({
virtualYConfig: {
enabled: false,
},
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);
},
},
headerCellStyle: { backgroundColor: '#fafafa' },
spanMethod({ row, rowIndex, column, visibleData }) {
const spanFields = ['projectName', 'customerName', 'author'];

View File

@@ -1,12 +1,26 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { downloadFileFromBlobPart } from '@vben/utils';
import dayjs from 'dayjs';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getProgressByProjectPage } from '#/api/report/progress';
import { exportProject, getProgressByProjectPage } from '#/api/report/progress';
import { useProjectGridColumns, useProjectGridFormSchema } from '../data';
const [Grid] = useVbenVxeGrid({
/** 导出表格 */
async function onExport(body: any) {
const formValues = await gridApi.formApi.getValues();
const data = await exportProject({ ...body, ...formValues });
downloadFileFromBlobPart({
fileName: `${body.filename}.xlsx`,
source: data,
});
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useProjectGridFormSchema(),
submitOnEnter: true,
@@ -29,11 +43,10 @@ const [Grid] = useVbenVxeGrid({
pagerConfig: {
enabled: true,
},
exportConfig: {},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
// export: true,
export: true,
},
height: 'auto',
rowConfig: {
@@ -51,6 +64,46 @@ const [Grid] = useVbenVxeGrid({
virtualYConfig: {
enabled: false,
},
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);
},
},
headerCellStyle: { backgroundColor: '#fafafa' },
spanMethod({ row, rowIndex, column, visibleData }) {
const spanFields = ['projectName', 'customerName'];