From 18eb4308e941a265daba8eda2f2ee91115963a3c Mon Sep 17 00:00:00 2001 From: haoxuan <haoxuan> Date: 星期四, 18 四月 2024 17:06:04 +0800 Subject: [PATCH] 1 --- src/common/utils/request.ts | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/utils/request.ts b/src/common/utils/request.ts index a73faac..82f6c31 100644 --- a/src/common/utils/request.ts +++ b/src/common/utils/request.ts @@ -16,11 +16,12 @@ (config) => { // 鑻ユ槸鏈夊仛閴存潈token , 灏辩粰澶撮儴甯︿笂token const token = getToken() - if (token) { - config.headers.Authorization = 'Bearer ' + token - } else { + if ((token == null || token == '' || token == 'undefined') && config.url != '/api/base/login') { router.push('/login') + return config // window.location = `//${window.location.hostname}:9080`+'/login' + } else if (token) { + config.headers.Authorization = 'Bearer ' + token } return config @@ -47,6 +48,10 @@ } }, (error) => { + if (error.response.status === 401) { + // alert('JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..') + router.push('/login') + } let { message } = error if (message === 'Network Error') { message = '鍚庣鎺ュ彛杩炴帴寮傚父' -- Gitblit v1.8.0