From 4eea1eef347d02731fc5a61f89d5310820056eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E7=A0=81-=E6=96=B9=E6=99=93=E8=BE=89?= Date: Mon, 2 Feb 2026 20:04:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=A8=A1=E6=9D=BF=E4=B8=8B=E8=BD=BD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 axios (request) 替代 fetch,走 Vite 代理正确转发请求 --- .../student/components/ImportDialog.vue | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/frontend/ruoyi-ui/src/views/business/student/components/ImportDialog.vue b/frontend/ruoyi-ui/src/views/business/student/components/ImportDialog.vue index e4230f6..7dc30d1 100644 --- a/frontend/ruoyi-ui/src/views/business/student/components/ImportDialog.vue +++ b/frontend/ruoyi-ui/src/views/business/student/components/ImportDialog.vue @@ -87,6 +87,7 @@ import { Download, UploadFilled } from '@element-plus/icons-vue' import { ElMessage } from 'element-plus' import { computed, ref } from 'vue' import { getToken } from '@/utils/auth' +import request from '@/utils/request' const emit = defineEmits(['success']) @@ -112,20 +113,15 @@ const uploadHeaders = computed(() => { const handleDownloadTemplate = async () => { downloadLoading.value = true try { - const baseApi = import.meta.env.VITE_APP_BASE_API || '' - // 使用 fetch 下载文件 - const response = await fetch(`${baseApi}/business/student/template`, { - method: 'GET', - headers: { - 'Authorization': 'Bearer ' + getToken() - } + // 使用 axios 下载文件(走 Vite 代理) + const response = await request({ + url: '/business/student/template', + method: 'get', + responseType: 'blob' }) - if (!response.ok) { - throw new Error('下载失败') - } - - const blob = await response.blob() + // response 就是 blob 数据 + const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) const url = window.URL.createObjectURL(blob) const link = document.createElement('a') link.href = url