refactor(monitor): 重构操作日志与登录日志导出功能

使用 useBlobExport 组合式函数替换 commonDownloadExcel,统一导出逻辑
移除手动构建请求参数和文件名的代码,提高代码复用性
为导出按钮添加加载状态,改善用户体验
This commit is contained in:
dap
2026-01-28 19:33:25 +08:00
parent d28d80295c
commit abb386f49d
2 changed files with 24 additions and 17 deletions

View File

@@ -18,7 +18,7 @@ import {
loginInfoRemove, loginInfoRemove,
userUnlock, userUnlock,
} from '#/api/monitor/logininfo'; } from '#/api/monitor/logininfo';
import { commonDownloadExcel } from '#/utils/file/download'; import { useBlobExport } from '#/utils/file/export';
import { confirmDeleteModal } from '#/utils/modal'; import { confirmDeleteModal } from '#/utils/modal';
import { columns, querySchema } from './data'; import { columns, querySchema } from './data';
@@ -134,15 +134,14 @@ async function handleUnlock() {
tableApi.grid.clearCheckboxRow(); tableApi.grid.clearCheckboxRow();
} }
function handleDownloadExcel() { const { exportBlob, exportLoading, buildExportFileName } =
commonDownloadExcel( useBlobExport(loginInfoExport);
loginInfoExport, async function handleExport() {
'登录日志', // 构建表单请求参数
tableApi.formApi.form.values, const formValues = await tableApi.formApi.getValues();
{ // 文件名
fieldMappingTime: formOptions.fieldMappingTime, const fileName = buildExportFileName('登录日志');
}, exportBlob({ data: formValues, fileName });
);
} }
</script> </script>
@@ -159,7 +158,9 @@ function handleDownloadExcel() {
</a-button> </a-button>
<a-button <a-button
v-access:code="['monitor:logininfor:export']" v-access:code="['monitor:logininfor:export']"
@click="handleDownloadExcel" :loading="exportLoading"
:disabled="exportLoading"
@click="handleExport"
> >
{{ $t('pages.common.export') }} {{ $t('pages.common.export') }}
</a-button> </a-button>

View File

@@ -21,7 +21,7 @@ import {
operLogExport, operLogExport,
operLogList, operLogList,
} from '#/api/monitor/operlog'; } from '#/api/monitor/operlog';
import { commonDownloadExcel } from '#/utils/file/download'; import { useBlobExport } from '#/utils/file/export';
import { confirmDeleteModal } from '#/utils/modal'; import { confirmDeleteModal } from '#/utils/modal';
import { columns, querySchema } from './data'; import { columns, querySchema } from './data';
@@ -135,10 +135,14 @@ async function handleDelete() {
}); });
} }
function handleDownloadExcel() { const { exportBlob, exportLoading, buildExportFileName } =
commonDownloadExcel(operLogExport, '操作日志', tableApi.formApi.form.values, { useBlobExport(operLogExport);
fieldMappingTime: formOptions.fieldMappingTime, async function handleExport() {
}); // 构建表单请求参数
const formValues = await tableApi.formApi.getValues();
// 文件名
const fileName = buildExportFileName('操作日志');
exportBlob({ data: formValues, fileName });
} }
</script> </script>
@@ -155,7 +159,9 @@ function handleDownloadExcel() {
</a-button> </a-button>
<a-button <a-button
v-access:code="['monitor:operlog:export']" v-access:code="['monitor:operlog:export']"
@click="handleDownloadExcel" :loading="exportLoading"
:disabled="exportLoading"
@click="handleExport"
> >
{{ $t('pages.common.export') }} {{ $t('pages.common.export') }}
</a-button> </a-button>