fix: use blob response for excel export auth and secure adjust route
This commit is contained in:
@ -748,11 +748,32 @@ const closeOverlays = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- 导出 Excel 逻辑 (调用后端API) ---
|
// --- 导出 Excel 逻辑 (调用后端API) ---
|
||||||
const exportToExcel = () => {
|
const exportToExcel = async () => {
|
||||||
// 调用后端API下载盘点报告
|
try {
|
||||||
const baseUrl = import.meta.env.VITE_APP_BASE_API || ''
|
ElMessage.info('正在生成盘点报告,请稍候...');
|
||||||
window.open(`${baseUrl}/v1/inbound/stock/export-stocktake`, '_blank')
|
// 使用项目封装的 request 发送请求,确保自动携带 JWT Token
|
||||||
ElMessage.success('正在下载盘点报告...')
|
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(() => {
|
const filteredList = computed(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user