fix: 导出导入修复响应拦截器问题(api返回response.data非response)
This commit is contained in:
@@ -76,9 +76,10 @@ const sites = ref([])
|
||||
const exportScripts = async () => {
|
||||
exporting.value = true
|
||||
try {
|
||||
// api 响应拦截器返回 response.data,所以 r 直接就是 blob
|
||||
const r = await api.get('/admin/scripts/export', { responseType: 'blob' })
|
||||
const a = document.createElement('a')
|
||||
a.href = URL.createObjectURL(new Blob([r.data]))
|
||||
a.href = URL.createObjectURL(new Blob([r]))
|
||||
a.download = 'scripts.zip'; a.click(); URL.revokeObjectURL(a.href)
|
||||
} catch { ElMessage.error('导出失败') }
|
||||
finally { exporting.value = false }
|
||||
@@ -89,7 +90,7 @@ const importScripts = async (file) => {
|
||||
try {
|
||||
const fd = new FormData(); fd.append('file', file.raw)
|
||||
const r = await api.post('/admin/scripts/import', fd)
|
||||
ElMessage.success('导入完成: ' + ((r.data?.ok || 0) + ' 成功, ' + (r.data?.fail || 0) + ' 失败'))
|
||||
ElMessage.success('导入完成: ' + ((r.ok || 0) + ' 成功, ' + (r.fail || 0) + ' 失败'))
|
||||
fetchAll()
|
||||
} catch { ElMessage.error('导入失败') }
|
||||
finally { importing.value = false }
|
||||
|
||||
Reference in New Issue
Block a user