feat: 追溯码支持批量导出 Excel/CSV(按筛选或所选)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 18:51:32 +08:00
co-authored by Cursor
parent 631982d980
commit 94d3ce18de
7 changed files with 120 additions and 22 deletions
+32 -7
View File
@@ -41,10 +41,12 @@
<template #icon><n-icon :component="FolderOutline" /></template>
{{ t('pages.traceCode.manageGroups') }}
</n-button>
<n-button v-if="auth.canWrite && query.batchId" @click="exportBatch">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('pages.traceCode.exportBatch') }}
</n-button>
<n-dropdown v-if="auth.canWrite" trigger="click" :options="exportOptions" @select="onExport">
<n-button>
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('common.action.export') }}
</n-button>
</n-dropdown>
<n-button v-if="auth.canWrite" type="primary" @click="genModal = true">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.traceCode.generate') }}
@@ -278,9 +280,32 @@ function showQr(r: any) {
qrUrl.value = r.url;
qrModal.value = true;
}
async function exportBatch() {
if (!query.batchId) return;
await downloadFile('/trace-codes/export', `trace-codes-${query.batchId}.xlsx`, { batchId: query.batchId });
const exportOptions = computed(() => {
const cur = t('pages.traceCode.exportCurrent');
const opts: Array<{ label: string; key: string; type?: string }> = [
{ label: `Excel · ${cur}`, key: 'filter:xlsx' },
{ label: `CSV · ${cur}`, key: 'filter:csv' },
];
if (checkedKeys.value.length) {
const sel = t('pages.traceCode.selected', { n: checkedKeys.value.length });
opts.push({ label: `Excel · ${sel}`, key: 'selected:xlsx' });
opts.push({ label: `CSV · ${sel}`, key: 'selected:csv' });
}
return opts;
});
async function onExport(key: string) {
const [scope, format] = key.split(':');
const params: Record<string, unknown> = { format };
if (scope === 'selected') {
params.ids = checkedKeys.value.map(String).join(',');
} else {
if (query.groupId) params.groupId = query.groupId;
if (query.batchId) params.batchId = query.batchId;
if (query.status) params.status = query.status;
if (query.keyword) params.keyword = query.keyword;
}
await downloadFile('/trace-codes/export', `trace-codes.${format}`, params);
}
/* 批量操作 */