refactor(views): 替换导出功能为组合式函数以提升复用性

将租户套餐和租户管理页面的导出功能从 commonDownloadExcel 工具函数迁移至 useBlobExport 组合式函数。此重构统一了导出逻辑,自动处理加载状态和文件名构建,并移除了手动控制台日志语句,提高了代码的可维护性和一致性。
This commit is contained in:
dap
2026-01-28 19:36:41 +08:00
parent 1ff118c2e0
commit 35d67ad71c
2 changed files with 24 additions and 13 deletions

View File

@@ -26,7 +26,7 @@ import {
} from '#/api/system/tenant';
import { ApiSwitch } from '#/components/global';
import { useTenantStore } from '#/store/tenant';
import { commonDownloadExcel } from '#/utils/file/download';
import { useBlobExport } from '#/utils/file/export';
import { columns, querySchema } from './data';
import tenantDrawer from './tenant-drawer.vue';
@@ -122,8 +122,14 @@ function handleMultiDelete() {
});
}
function handleDownloadExcel() {
commonDownloadExcel(tenantExport, '租户数据', tableApi.formApi.form.values);
const { exportBlob, exportLoading, buildExportFileName } =
useBlobExport(tenantExport);
async function handleExport() {
// 构建表单请求参数
const formValues = await tableApi.formApi.getValues();
// 文件名
const fileName = buildExportFileName('租户数据');
exportBlob({ data: formValues, fileName });
}
/**
@@ -159,7 +165,6 @@ function handleSyncTenantConfig() {
}
async function handleChangeStatus(checked: boolean, row: Tenant) {
console.log(checked);
await tenantStatusChange({
id: row.id,
tenantId: row.tenantId,
@@ -208,7 +213,9 @@ const handleMenuClick: DropdownEmits['menuClick'] = (e) => {
<a-button
v-access:code="['system:tenant:export']"
@click="handleDownloadExcel"
:loading="exportLoading"
:disabled="exportLoading"
@click="handleExport"
>
{{ $t('pages.common.export') }}
</a-button>

View File

@@ -20,7 +20,7 @@ import {
packageRemove,
} from '#/api/system/tenant-package';
import { ApiSwitch } from '#/components/global';
import { commonDownloadExcel } from '#/utils/file/download';
import { useBlobExport } from '#/utils/file/export';
import { columns, querySchema } from './data';
import tenantPackageDrawer from './tenant-package-drawer.vue';
@@ -104,12 +104,14 @@ function handleMultiDelete() {
});
}
function handleDownloadExcel() {
commonDownloadExcel(
packageExport,
'租户套餐数据',
tableApi.formApi.form.values,
);
const { exportBlob, exportLoading, buildExportFileName } =
useBlobExport(packageExport);
async function handleExport() {
// 构建表单请求参数
const formValues = await tableApi.formApi.getValues();
// 文件名
const fileName = buildExportFileName('租户套餐数据');
exportBlob({ data: formValues, fileName });
}
/**
@@ -137,7 +139,9 @@ async function handleChangeStatus(checked: boolean, row: TenantPackage) {
<Space>
<a-button
v-access:code="['system:tenantPackage:export']"
@click="handleDownloadExcel"
:loading="exportLoading"
:disabled="exportLoading"
@click="handleExport"
>
{{ $t('pages.common.export') }}
</a-button>