From 79b9c73e0717c244391ab1e15c6f6da9975f2610 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期二, 12 十一月 2024 15:58:30 +0800 Subject: [PATCH] 打包bug --- src/utils/request.ts | 45 ++++++++++++++++++--------------------------- 1 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 6178701..79b82f4 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -11,6 +11,7 @@ import { encryptBase64, encryptWithAes, generateAesKey } from '@/utils/crypto'; import { encrypt } from '@/utils/jsencrypt'; import router from "@/router"; +import { ElLoading, ElMessage, ElNotification } from "element-plus"; let downloadLoadingInstance: LoadingInstance; // 鏄惁鏄剧ず閲嶆柊鐧诲綍 @@ -46,13 +47,14 @@ } // get璇锋眰鏄犲皠params鍙傛暟 if (config.method === 'get' && config.params) { + console.log(config.params, '璇锋眰鍙傛暟'); let url = config.url + '?' + tansParams(config.params); url = url.slice(0, -1); config.params = {}; config.url = url; } - if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) { + if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put' || config.method === 'get')) { const requestObj = { url: config.url, data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data, @@ -65,7 +67,7 @@ const s_url = sessionObj.url; // 璇锋眰鍦板潃 const s_data = sessionObj.data; // 璇锋眰鏁版嵁 const s_time = sessionObj.time; // 璇锋眰鏃堕棿 - const interval = 500; // 闂撮殧鏃堕棿(ms)锛屽皬浜庢鏃堕棿瑙嗕负閲嶅鎻愪氦 + const interval = 5; // 闂撮殧鏃堕棿(ms)锛屽皬浜庢鏃堕棿瑙嗕负閲嶅鎻愪氦 if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) { const message = '鏁版嵁姝e湪澶勭悊锛岃鍕块噸澶嶆彁浜�'; console.warn(`[${s_url}]: ` + message); @@ -76,7 +78,8 @@ } } // 褰撳紑鍚弬鏁板姞瀵� - if (isEncrypt && (config.method === 'post' || config.method === 'put')) { + if (isEncrypt && (config.method === 'post' || config.method === 'put' || config.method === 'get')) { + console.log('寮�鍚簡鍙傛暟鍔犲瘑'); // 鐢熸垚涓�涓� AES 瀵嗛挜 const aesKey = generateAesKey(); config.headers['encrypt-key'] = encrypt(encryptBase64(aesKey)); @@ -89,14 +92,15 @@ return config; }, (error: any) => { - console.log(error); + console.log(error, 'wcs'); return Promise.reject(error); } ); + // 鍝嶅簲鎷︽埅鍣� service.interceptors.response.use( - (res: AxiosResponse) => { + async (res: AxiosResponse) => { // 鏈缃姸鎬佺爜鍒欓粯璁ゆ垚鍔熺姸鎬� const code = res.data.code || HttpStatus.SUCCESS; // 鑾峰彇閿欒淇℃伅 @@ -106,33 +110,20 @@ return res.data; } if (code === 401) { - console.log(code,'code=============='); - router.push({ path: '/login' }); - // prettier-ignore - // if (!isRelogin.show) { - // // isRelogin.show = true; - // isRelogin.show = true; - // ElMessageBox.confirm('鐧诲綍鐘舵�佸凡杩囨湡锛屾偍鍙互缁х画鐣欏湪璇ラ〉闈紝鎴栬�呴噸鏂扮櫥褰�', '绯荤粺鎻愮ず', { - // confirmButtonText: '閲嶆柊鐧诲綍', - // cancelButtonText: '鍙栨秷', - // type: 'warning' - // }).then(() => { - // isRelogin.show = false; - // useUserStore().logout().then(() => { - // location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index'; - // }); - // }).catch(() => { - // isRelogin.show = false; - // }); - // } - return Promise.reject('鏃犳晥鐨勪細璇濓紝鎴栬�呬細璇濆凡杩囨湡锛岃閲嶆柊鐧诲綍銆�'); + + const userStore = useUserStore(); + await userStore.logout() + + console.log(code, 'code=============='); + await router.push({ path: '/login' }); + return } else if (code === HttpStatus.SERVER_ERROR) { console.log(msg); ElMessage({ message: msg, type: 'error' }); - return Promise.reject(new Error(msg)); + return Promise.reject(new Error('绯荤粺鍐呴儴閿欒')); } else if (code === HttpStatus.WARN) { ElMessage({ message: msg, type: 'warning' }); - return Promise.reject(new Error(msg)); + return Promise.reject(new Error('绯荤粺璀﹀憡娑堟伅')); } else if (code !== HttpStatus.SUCCESS) { ElNotification.error({ title: msg }); return Promise.reject('error'); -- Gitblit v1.8.0