fix: 修复学生导入模板下载功能
使用 axios (request) 替代 fetch,走 Vite 代理正确转发请求
This commit is contained in:
parent
ca433d6ab9
commit
4eea1eef34
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue