This commit is contained in:
zxr
2026-05-02 17:08:10 +08:00
parent ea3e60c17c
commit 27e1f335a6
20 changed files with 1401 additions and 1050 deletions

View File

@@ -35,8 +35,28 @@ import axios, {
// 3. 响应拦截器
instance.interceptors.response.use(
(response: AxiosResponse) => {
const cfg = response.config as RequestConfig
if (cfg.rawResponse) {
return response
}
// 二进制流:只返回 data且勿对 Blob 访问 .status
if (cfg.responseType === 'blob' || cfg.responseType === 'arraybuffer') {
const body = response.data as unknown
if (body instanceof Blob) return body
if (typeof body === 'string') {
return new Blob([body], {
type: (response.headers['content-type'] as string) || 'application/octet-stream',
})
}
if (body instanceof ArrayBuffer) {
return new Blob([body], {
type: (response.headers['content-type'] as string) || 'application/octet-stream',
})
}
return body
}
// 统一处理响应数据格式[2](@ref)
if (response.data.status === 401) {
if (response.data?.status === 401) {
// token过期处理
SafeStorage.clearAppStorage();
window.location.href = "/auth/login";
@@ -59,6 +79,8 @@ import axios, {
interface RequestConfig extends AxiosRequestConfig {
data?: unknown;
needWorkspace?: boolean;
/** 为 true 时响应拦截器返回完整 AxiosResponse用于 blob 等需自行取 data 的场景) */
rawResponse?: boolean;
}
export const request = {