From f703bfe9d16065985caebb15da06fe7b7c080ed9 Mon Sep 17 00:00:00 2001 From: bb_pan Date: Thu, 13 Feb 2025 15:30:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=93=8D=E5=BA=94=E6=8B=A6=E6=88=AA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/http/index.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/http/index.ts b/src/http/index.ts index d3be41b..3e0d642 100644 --- a/src/http/index.ts +++ b/src/http/index.ts @@ -44,7 +44,7 @@ service.interceptors.request.use( } if (config.data) { let data = typeof config.data === 'object' ? JSON.stringify(config.data) : config.data - config.data = encryptWithSM4(data+"|"+hashWithSM3AndSalt(data)) + config.data = encryptWithSM4(data + '|' + hashWithSM3AndSalt(data)) } return config }, @@ -56,9 +56,13 @@ service.interceptors.request.use( service.interceptors.response.use( (res) => { ElMessage.closeAll() - // const { data } = res - const data = JSON.parse(decryptWithSM4(res.data)) - // console.log('πŸš€ ~ data:', data) + let data: any = null + if (res.headers.encryptresponse && !res.data.hasOwnProperty('code')) { + data = JSON.parse(decryptWithSM4(res.data)) + } else { + data = res.data + } + // console.log('πŸš€ ~ 响应-data:', data) if (data.code == '200') { return data } else if (data.code == '403') { @@ -74,7 +78,7 @@ service.interceptors.response.use( }, 500) } } else if (data.code == '401') { - ElMessage.error('请登录') + ElMessage.error('请重新登录') if (import.meta.env.VITE_API_URL == '/proxyApi') { router.push('/login') } else {