From 155f22b72cbde994bd5a27b0fbc72d721197f303 Mon Sep 17 00:00:00 2001 From: LiuHao <liuhaoai545@gmail> Date: 星期四, 13 四月 2023 18:59:33 +0800 Subject: [PATCH] fix 用户头像上传失败问题 --- src/utils/request.ts | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 14c33f8..af73926 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,4 +1,4 @@ -import axios, { InternalAxiosRequestConfig } from 'axios'; +import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios'; import { useUserStore } from '@/store/modules/user'; import { getToken } from '@/utils/auth'; import { tansParams, blobValidate } from '@/utils/ruoyi'; @@ -61,6 +61,10 @@ } } } + // FormData鏁版嵁鍘昏姹傚ごContent-Type + if (config.data instanceof FormData) { + delete config.headers['Content-Type']; + } return config; }, (error: any) => { @@ -71,7 +75,7 @@ // 鍝嶅簲鎷︽埅鍣� service.interceptors.response.use( - (res) => { + (res: AxiosResponse) => { // 鏈缃姸鎬佺爜鍒欓粯璁ゆ垚鍔熺姸鎬� const code = res.data.code || HttpStatus.SUCCESS; // 鑾峰彇閿欒淇℃伅 @@ -112,7 +116,7 @@ return Promise.resolve(res.data); } }, - (error) => { + (error: any) => { let { message } = error; if (message == 'Network Error') { message = '鍚庣鎺ュ彛杩炴帴寮傚父'; @@ -131,16 +135,16 @@ // prettier-ignore return service.post(url, params, { transformRequest: [ - (params) => { + (params: any) => { return tansParams(params); } ], headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, responseType: 'blob' - }).then(async (resp) => { + }).then(async (resp: any) => { const isLogin = blobValidate(resp); if (isLogin) { - const blob = new Blob([resp as any]); + const blob = new Blob([resp]); FileSaver.saveAs(blob, fileName); } else { const resText = await resp.data.text(); @@ -149,7 +153,7 @@ ElMessage.error(errMsg); } downloadLoadingInstance.close(); - }).catch((r) => { + }).catch((r: any) => { console.error(r); ElMessage.error('涓嬭浇鏂囦欢鍑虹幇閿欒锛岃鑱旂郴绠$悊鍛橈紒'); downloadLoadingInstance.close(); -- Gitblit v1.9.3