fix: 修复学生导入模板下载功能

使用 axios (request) 替代 fetch,走 Vite 代理正确转发请求
This commit is contained in:
神码-方晓辉 2026-02-02 20:04:14 +08:00
parent ca433d6ab9
commit 4eea1eef34
1 changed files with 8 additions and 12 deletions

View File

@ -87,6 +87,7 @@ import { Download, UploadFilled } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import request from '@/utils/request'
const emit = defineEmits(['success']) const emit = defineEmits(['success'])
@ -112,20 +113,15 @@ const uploadHeaders = computed(() => {
const handleDownloadTemplate = async () => { const handleDownloadTemplate = async () => {
downloadLoading.value = true downloadLoading.value = true
try { try {
const baseApi = import.meta.env.VITE_APP_BASE_API || '' // 使 axios Vite
// 使 fetch const response = await request({
const response = await fetch(`${baseApi}/business/student/template`, { url: '/business/student/template',
method: 'GET', method: 'get',
headers: { responseType: 'blob'
'Authorization': 'Bearer ' + getToken()
}
}) })
if (!response.ok) { // response blob
throw new Error('下载失败') const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
}
const blob = await response.blob()
const url = window.URL.createObjectURL(blob) const url = window.URL.createObjectURL(blob)
const link = document.createElement('a') const link = document.createElement('a')
link.href = url link.href = url