From 15eb5dbd1373551151742a13d0ee5903e6a127f1 Mon Sep 17 00:00:00 2001 From: yuhan_jiang <1165121840@qq.com> Date: Sat, 16 Jul 2022 16:16:38 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8D=95=E7=82=B9=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E3=80=91=E4=BF=AE=E5=A4=8D=E4=BA=91=E5=9B=BE=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E4=B8=A4=E6=AC=A1=E6=89=8D=E8=83=BD=E5=8D=95?= =?UTF-8?q?=E7=82=B9=E6=88=90=E5=8A=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/api/user.js | 6 ++- front/src/utils/request.js | 46 ++++++++--------------- front/src/vab/plugins/permissions.js | 21 ++++------- front/src/views/capabilityCloud/index.vue | 2 +- 4 files changed, 29 insertions(+), 46 deletions(-) diff --git a/front/src/api/user.js b/front/src/api/user.js index a39992be..a8e05e59 100644 --- a/front/src/api/user.js +++ b/front/src/api/user.js @@ -23,11 +23,15 @@ export async function socialLogin(data) { }) } -export function getUserInfo() { +export function getUserInfo(redict) { //此处为了兼容mock.js使用data传递accessToken,如果使用mock可以走headers + // debugger return request({ url: '/sys/user/info', method: 'get', + headers: { + REQUESTURI:redict + } }) } export function getDeptAll() { diff --git a/front/src/utils/request.js b/front/src/utils/request.js index 0f02346e..f605d9ae 100644 --- a/front/src/utils/request.js +++ b/front/src/utils/request.js @@ -23,24 +23,10 @@ let loadingInstance * @param {*} msg */ const handleCode = (code, msg, res) => { - debugger + // debugger switch (code) { case 401: - // message.error(msg || '登录失效') - store.dispatch('user/resetAll').catch(() => {}) - debugger - // if (res.token) { - // console.log('存在token信息', res.token) - // setAccessToken(res.token) - // const token = getAccessToken() - // console.log('验证token信息', token) - // } - - // // location.reload() - // if (redirect) { - // window.location.href = res.redirect - // } break case 403: router.push({ path: '/401' }).catch(() => {}) @@ -72,7 +58,7 @@ const instance = axios.create({ */ instance.interceptors.request.use( (config) => { - debugger + // debugger const token = getAccessToken() if (token) config.headers[tokenName] = token @@ -85,7 +71,10 @@ instance.interceptors.request.use( if (debounce.some((item) => config.url.includes(item))) { //这里写加载动画 } - config.headers.REQUESTURI = window.location.href + if (!config.headers.REQUESTURI){ + config.headers.REQUESTURI = window.location.href + } + return config }, (error) => { @@ -104,17 +93,12 @@ instance.interceptors.response.use( console.log('接口返回REDIRECT', response.headers.redirect) response['Access-Control-Expose-Headers'] = 'redirect' const { code, message } = response.data - debugger - if (code=='0' && response.headers.token) { + if (response.headers.token) { setAccessToken(response.headers.token) - } else { - const token = getAccessToken() - if (response.headers.redirect && !token) { - // window.location.href = response.headers.redirect - window.location.replace(response.headers.redirect) + } + if (response.headers.redirect) { + window.location.replace(response.headers.redirect) return - // location.reload() - } } if (response.headers.redirect === '/#/login') { var keys = document.cookie.match(/[^ =;]+(?=\=)/g) @@ -159,7 +143,7 @@ instance.interceptors.response.use( // } }, (error) => { - debugger + // debugger console.log('接口error', error) if (loadingInstance) loadingInstance.close() @@ -168,12 +152,12 @@ instance.interceptors.response.use( console.log('接口返回', response) console.log('接口返回headers', response.headers) console.log('接口返回REDIRECT', response.headers.redirect) - // if (response.headers.token) { - // setAccessToken(response.headers.token) - // } + if (response.headers.token) { + setAccessToken(response.headers.token) + } if (response.headers.redirect) { window.location.replace(response.headers.redirect) - // return Promise.resolve() + return Promise.resolve() } const { status, data } = response diff --git a/front/src/vab/plugins/permissions.js b/front/src/vab/plugins/permissions.js index 6139bd4b..9a058ed2 100644 --- a/front/src/vab/plugins/permissions.js +++ b/front/src/vab/plugins/permissions.js @@ -26,16 +26,17 @@ // if (SSOTOKEN) { // setAccessToken(SSOTOKEN) // } + const token = getAccessToken() console.log('token', token) - let hasToken = token || store.getters['user/accessToken'] + let hasToken = token // debugger if (!loginInterception) hasToken = true console.log('hasToken存在巨大问题', hasToken) if (hasToken) { // setAccessToken(hasToken) await store.dispatch('user/getUserInfo') - debugger + // debugger next() } else { let accessRoutes = [] @@ -47,17 +48,11 @@ next() } else { // 这里是一个单点登录的入口 - getUserInfo().then(res=>{ - console.log(res) - router.replace('/home') - }) - // await store.dispatch('user/getUserInfo') - // next() - // if (recordRoute) - // next({ path: '/login', query: { redirect: to.path }, replace: true }) - // else next({ path: '/login', replace: true }) - // next() - // window.open('http://www.baidu.com', '_self') + if (to.query.redict) + getUserInfo(to.query.redict) + else { + getUserInfo() + } } } }) diff --git a/front/src/views/capabilityCloud/index.vue b/front/src/views/capabilityCloud/index.vue index b1c7d442..04dd8dc9 100644 --- a/front/src/views/capabilityCloud/index.vue +++ b/front/src/views/capabilityCloud/index.vue @@ -32,7 +32,7 @@ import { useRouter } from 'vue-router' const router = useRouter() const goHome = () => { - router.push('/home') + router.push({path: '/home', query:{redict: window.location.origin + '/#/home'}}) }