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 { 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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue