From 0e4cc662cb37d0666a9ba3ede5d1d2e667268d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Fri, 10 Jun 2022 14:51:39 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=9D=83=E9=99=90=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 11 ++++++++--- src/utils/request.js | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index ad7b75c..b6fc752 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -59,13 +59,18 @@ router.onError((error, to) => { router.beforeEach(async (to, from, next) => { if (store.state.local.token) { if (!store.state.auth.permission.length) { - await store.dispatch('auth/getUserInfo'); + let res = true; + res &= await store.dispatch('auth/getUserInfo'); if (config.useLocalRouter) { store.commit('auth/setPermission', routes); } else { - await store.dispatch('auth/getPermission'); + res &= await store.dispatch('auth/getPermission'); + } + if (res) { + next({ ...to, replace: true }); + } else { + next(false); } - next({ ...to, replace: true }); } else { console.info(`[router] from ${from.name} to ${to.name}`); const deep = (route) => { diff --git a/src/utils/request.js b/src/utils/request.js index 034ba57..4a7d620 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -12,10 +12,13 @@ const handleResponse = async ({ config: requestConfig, data, status }) => { if (requestConfig.headers.download === true) { return data; } - let code = data.code || status; - console.info('[api]', code, requestConfig.method, requestConfig.url, data.data); + let code = data?.code || status; + console.info('[api]', code, requestConfig.method, requestConfig.url, data?.data); if (code !== 'SUCCESS') { - ElMessage.error(data.message || '服务器异常'); + ElMessage.error(data?.message || '服务器异常'); + if (data) { + data.data = null; + } switch (code) { case 'SYSTEM_ERROR': //系统异常 case 'INTERFACE_SYSTEM_ERROR': // 外部接口调用异常