fix: 导出导入修复响应拦截器问题(api返回response.data非response)

This commit is contained in:
mediabot-pt
2026-07-02 13:35:40 +08:00
parent a5f007a088
commit 1c1680bed7

View File

@@ -76,9 +76,10 @@ const sites = ref([])
const exportScripts = async () => { const exportScripts = async () => {
exporting.value = true exporting.value = true
try { try {
// api 响应拦截器返回 response.data,所以 r 直接就是 blob
const r = await api.get('/admin/scripts/export', { responseType: 'blob' }) const r = await api.get('/admin/scripts/export', { responseType: 'blob' })
const a = document.createElement('a') 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) a.download = 'scripts.zip'; a.click(); URL.revokeObjectURL(a.href)
} catch { ElMessage.error('导出失败') } } catch { ElMessage.error('导出失败') }
finally { exporting.value = false } finally { exporting.value = false }
@@ -89,7 +90,7 @@ const importScripts = async (file) => {
try { try {
const fd = new FormData(); fd.append('file', file.raw) const fd = new FormData(); fd.append('file', file.raw)
const r = await api.post('/admin/scripts/import', fd) 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() fetchAll()
} catch { ElMessage.error('导入失败') } } catch { ElMessage.error('导入失败') }
finally { importing.value = false } finally { importing.value = false }