fix: use blob response for excel export auth and secure adjust route

This commit is contained in:
DXC
2026-03-18 11:24:41 +08:00
parent 54ea476206
commit b19699cfba

View File

@ -748,11 +748,32 @@ const closeOverlays = () => {
}
// --- 导出 Excel 逻辑 (调用后端API) ---
const exportToExcel = () => {
// 调用后端API下载盘点报告
const baseUrl = import.meta.env.VITE_APP_BASE_API || ''
window.open(`${baseUrl}/v1/inbound/stock/export-stocktake`, '_blank')
ElMessage.success('正在下载盘点报告...')
const exportToExcel = async () => {
try {
ElMessage.info('正在生成盘点报告,请稍候...');
// 使用项目封装的 request 发送请求,确保自动携带 JWT Token
const res: any = await request({
url: '/v1/inbound/stock/export-stocktake',
method: 'get',
responseType: 'blob' as any // 核心:接收二进制文件流
});
// 触发静默下载
const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
const dateStr = new Date().toISOString().split('T')[0];
link.download = `盘点差异报告_${dateStr}.xlsx`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
ElMessage.success('报告导出成功');
} catch (error) {
console.error('导出失败:', error);
ElMessage.error('导出失败,请重试');
}
}
const filteredList = computed(() => {