From 70bb06cba602f488bb29a0a2d520b85e6ea835d1 Mon Sep 17 00:00:00 2001 From: wuhongjian Date: Wed, 12 Oct 2022 09:50:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9token=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/public/config/basicConfig.js | 6 +-- front/public/static/config/basicConfig.js | 8 ++-- front/src/store/modules/user.js | 15 +++---- front/src/utils/request.js | 50 ++++++++--------------- front/src/vab/plugins/permissions.js | 7 ++-- 5 files changed, 37 insertions(+), 49 deletions(-) diff --git a/back/public/config/basicConfig.js b/back/public/config/basicConfig.js index 37616e9b..00261cd2 100644 --- a/back/public/config/basicConfig.js +++ b/back/public/config/basicConfig.js @@ -2,16 +2,16 @@ * @Author: hisense.wuhongjian * @Date: 2022-08-25 14:37:49 * @LastEditors: hisense.wuhongjian - * @LastEditTime: 2022-08-27 14:25:39 + * @LastEditTime: 2022-10-12 09:06:24 * @Description: 告诉大家这是什么 */ var _global = {} var CONFIGITEM = { - version: 'qingdao', // 青岛 + // version: 'qingdao', // 青岛 // version: 'xihaian', // 西海岸 // version: 'test', // 测试 // version: 'frp', // 内网穿透 - // version: 'dev', // 开发 + version: 'dev', // 开发 vNum: 'v0.8.7.2', configData: { // 青岛市大数据局 diff --git a/front/public/static/config/basicConfig.js b/front/public/static/config/basicConfig.js index ea1f9e0d..5072b016 100644 --- a/front/public/static/config/basicConfig.js +++ b/front/public/static/config/basicConfig.js @@ -1,15 +1,15 @@ /* * @Author: hisense.wuhongjian * @Date: 2020-07-07 16:03:23 - * @LastEditors: hisense.liangjunhua - * @LastEditTime: 2022-09-19 09:36:49 + * @LastEditors: hisense.wuhongjian + * @LastEditTime: 2022-10-11 10:46:03 * @Description: 系统静态参数配置 */ var _global = {} var CONFIGITEM = { // version: 'qingdao', //青岛 - version: 'xihaian', // 西海岸 - // version: 'dev', // 开发 + //version: 'xihaian', // 西海岸 + version: 'dev', // 开发 // version: 'zhanTingDev', // 展厅dev (2022-09-13:姜永超让添加) //version: 'test', // 测试 //version: 'frp', // 内网穿透 diff --git a/front/src/store/modules/user.js b/front/src/store/modules/user.js index 08a7e1db..949868d6 100644 --- a/front/src/store/modules/user.js +++ b/front/src/store/modules/user.js @@ -53,7 +53,7 @@ const mutations = { * @param {*} state * @param {*} username */ - setRealname(state, realName) { + setRealname(state, realName) { state.realName = realName }, // 设置角色 @@ -126,16 +126,16 @@ const actions = { * @returns */ async getUserInfo({ commit }) { - const { data } = await getUserInfo() - if (!data) { + const res = await getUserInfo() + if (!res || !res.data) { message.error(`验证失败,请重新登录...`) return false } // debugger - commit('setUsername', data.data.username) - commit('setRealname', data.data.realName) - commit('setRole', data.data.roleIdList.length) - commit('setUserId', data.data.id) + commit('setUsername', res.data.data.username) + commit('setRealname', res.data.data.realName) + commit('setRole', res.data.data.roleIdList.length) + commit('setUserId', res.data.data.id) // TODO 获取用户信息,后续执行部分操作 // let { username, avatar, roles, ability } = data // if (username && roles && Array.isArray(roles)) { @@ -168,6 +168,7 @@ const actions = { * @param {*} { commit, dispatch } */ async resetAll({ dispatch }) { + debugger await dispatch('setAccessToken', '') await dispatch('acl/setFull', false, { root: true, diff --git a/front/src/utils/request.js b/front/src/utils/request.js index 4721f5c7..03239f01 100644 --- a/front/src/utils/request.js +++ b/front/src/utils/request.js @@ -11,14 +11,8 @@ import store from '@/store' import qs from 'qs' import router from '@/router' // import { isArray } from '@/utils/validate' -import { - message -} from 'ant-design-vue' -import { - getAccessToken, - setAccessToken -} from '@/utils/accessToken' - +import { message } from 'ant-design-vue' +import { getAccessToken, setAccessToken } from '@/utils/accessToken' let loadingInstance @@ -33,12 +27,14 @@ const handleCode = (code, msg, res) => { switch (code) { case 401: debugger - store.dispatch('user/resetAll').catch(() => { }) + store.dispatch('user/resetAll').catch(() => {}) break case 403: - router.push({ - path: '/401' - }).catch(() => { }) + router + .push({ + path: '/401', + }) + .catch(() => {}) break case 500: message.error(msg || '接口异常') @@ -76,7 +72,7 @@ instance.interceptors.request.use( if ( config.data && config.headers['Content-Type'] === - 'application/x-www-form-urlencoded;charset=UTF-8' + 'application/x-www-form-urlencoded;charset=UTF-8' ) config.data = qs.stringify(config.data) if (debounce.some((item) => config.url.includes(item))) { @@ -103,17 +99,14 @@ instance.interceptors.response.use( console.log('接口返回headers', response.headers) console.log('接口返回REDIRECT', response.headers.redirect) response['Access-Control-Expose-Headers'] = 'redirect' - const { - code, - message - } = response.data + const { code, message } = response.data if (response.headers.token) { setAccessToken(response.headers.token) } if (response.headers.redirect) { - const _old_href = window.location.href.split('#')[0]; - const _new_href = response.headers.redirect.split('#')[0]; + const _old_href = window.location.href.split('#')[0] + const _new_href = response.headers.redirect.split('#')[0] window.location.replace(response.headers.redirect) // url 相同,强制刷新 if (_old_href === _new_href) { @@ -124,7 +117,7 @@ instance.interceptors.response.use( if (response.headers.redirect === '/#/login') { var keys = document.cookie.match(/[^ =;]+(?=\=)/g) if (keys) { - for (var i = keys.length; i--;) { + for (var i = keys.length; i--; ) { document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString() //清除当前域名下的,例如:m.kevis.com document.cookie = @@ -168,14 +161,14 @@ instance.interceptors.response.use( console.log('接口error', error) if (loadingInstance) loadingInstance.close() - const { - response, - message - } = error + const { response, message } = error if (error.response) { console.log('接口返回', response) console.log('接口返回headers', response.headers) console.log('接口返回REDIRECT', response.headers.redirect) + const { status, data } = response + + handleCode(status, data.msg || message, response.headers.redirect) if (response.headers.token) { setAccessToken(response.headers.token) } @@ -183,17 +176,10 @@ instance.interceptors.response.use( window.location.replace(response.headers.redirect) return Promise.resolve() } - const { - status, - data - } = response - handleCode(status, data.msg || message, response.headers.redirect) return Promise.reject(error) } else { - let { - message - } = error + let { message } = error if (message === 'Network Error') { message = '后端接口连接异常' } diff --git a/front/src/vab/plugins/permissions.js b/front/src/vab/plugins/permissions.js index 1cd6fbd4..4c197d7c 100644 --- a/front/src/vab/plugins/permissions.js +++ b/front/src/vab/plugins/permissions.js @@ -1,8 +1,8 @@ /* * @Author: hisense.wuhongjian * @Date: 2022-04-01 17:23:11 - * @LastEditors: Light - * @LastEditTime: 2022-10-10 16:43:58 + * @LastEditors: hisense.wuhongjian + * @LastEditTime: 2022-10-11 13:59:18 * @Description: 告诉大家这是什么 */ /** @@ -26,7 +26,7 @@ router.beforeEach(async (to, from, next) => { // if (SSOTOKEN) { // setAccessToken(SSOTOKEN) // } - + console.log('验证白名单', routesWhiteList) const token = getAccessToken() console.log('token', token) let hasToken = token @@ -45,6 +45,7 @@ router.beforeEach(async (to, from, next) => { router.addRoute(item) }) if (routesWhiteList.indexOf(to.path) !== -1) { + debugger next() } else { // 这里是一个单点登录的入口