fix: 导出导入用api.raw绕过封装对象+暴露原始axios实例
This commit is contained in:
@@ -93,5 +93,7 @@ export default {
|
|||||||
parse: (configId, accessResultId) => api.post('/admin/adapter/parse', { configId, accessResultId }),
|
parse: (configId, accessResultId) => api.post('/admin/adapter/parse', { configId, accessResultId }),
|
||||||
parseBatch: (configId, siteId) => api.post('/admin/adapter/parse-batch', { configId, siteId }),
|
parseBatch: (configId, siteId) => api.post('/admin/adapter/parse-batch', { configId, siteId }),
|
||||||
},
|
},
|
||||||
health: () => api.get('/health', { baseURL: '' })
|
health: () => api.get('/health', { baseURL: '' }),
|
||||||
|
// 原始 axios 实例,供需要直接调用(如 blob 下载)的场景使用
|
||||||
|
raw: { get: (url, cfg) => api.get(url, cfg), post: (url, data, cfg) => api.post(url, data, cfg) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const exportScripts = async () => {
|
|||||||
exporting.value = true
|
exporting.value = true
|
||||||
try {
|
try {
|
||||||
// api 响应拦截器返回 response.data,所以 r 直接就是 blob
|
// api 响应拦截器返回 response.data,所以 r 直接就是 blob
|
||||||
const r = await api.get('/admin/scripts/export', { responseType: 'blob' })
|
const r = await api.raw.get('/admin/scripts/export', { responseType: 'blob' })
|
||||||
const a = document.createElement('a')
|
const a = document.createElement('a')
|
||||||
a.href = URL.createObjectURL(new Blob([r]))
|
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)
|
||||||
@@ -89,7 +89,7 @@ const importScripts = async (file) => {
|
|||||||
importing.value = true
|
importing.value = true
|
||||||
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.raw.post('/admin/scripts/import', fd)
|
||||||
ElMessage.success('导入完成: ' + ((r.ok || 0) + ' 成功, ' + (r.fail || 0) + ' 失败'))
|
ElMessage.success('导入完成: ' + ((r.ok || 0) + ' 成功, ' + (r.fail || 0) + ' 失败'))
|
||||||
fetchAll()
|
fetchAll()
|
||||||
} catch { ElMessage.error('导入失败') }
|
} catch { ElMessage.error('导入失败') }
|
||||||
|
|||||||
Reference in New Issue
Block a user