更改token问题

This commit is contained in:
wuhongjian 2022-10-12 09:50:17 +08:00
parent 240784a3b2
commit 70bb06cba6
5 changed files with 37 additions and 49 deletions

View File

@ -2,16 +2,16 @@
* @Author: hisense.wuhongjian * @Author: hisense.wuhongjian
* @Date: 2022-08-25 14:37:49 * @Date: 2022-08-25 14:37:49
* @LastEditors: hisense.wuhongjian * @LastEditors: hisense.wuhongjian
* @LastEditTime: 2022-08-27 14:25:39 * @LastEditTime: 2022-10-12 09:06:24
* @Description: 告诉大家这是什么 * @Description: 告诉大家这是什么
*/ */
var _global = {} var _global = {}
var CONFIGITEM = { var CONFIGITEM = {
version: 'qingdao', // 青岛 // version: 'qingdao', // 青岛
// version: 'xihaian', // 西海岸 // version: 'xihaian', // 西海岸
// version: 'test', // 测试 // version: 'test', // 测试
// version: 'frp', // 内网穿透 // version: 'frp', // 内网穿透
// version: 'dev', // 开发 version: 'dev', // 开发
vNum: 'v0.8.7.2', vNum: 'v0.8.7.2',
configData: { configData: {
// 青岛市大数据局 // 青岛市大数据局

View File

@ -1,15 +1,15 @@
/* /*
* @Author: hisense.wuhongjian * @Author: hisense.wuhongjian
* @Date: 2020-07-07 16:03:23 * @Date: 2020-07-07 16:03:23
* @LastEditors: hisense.liangjunhua * @LastEditors: hisense.wuhongjian
* @LastEditTime: 2022-09-19 09:36:49 * @LastEditTime: 2022-10-11 10:46:03
* @Description: 系统静态参数配置 * @Description: 系统静态参数配置
*/ */
var _global = {} var _global = {}
var CONFIGITEM = { var CONFIGITEM = {
// version: 'qingdao', // // version: 'qingdao', //
version: 'xihaian', // 西 //version: 'xihaian', // 西
// version: 'dev', // version: 'dev', //
// version: 'zhanTingDev', // dev (2022-09-13:) // version: 'zhanTingDev', // dev (2022-09-13:)
//version: 'test', // //version: 'test', //
//version: 'frp', // 穿 //version: 'frp', // 穿

View File

@ -126,16 +126,16 @@ const actions = {
* @returns * @returns
*/ */
async getUserInfo({ commit }) { async getUserInfo({ commit }) {
const { data } = await getUserInfo() const res = await getUserInfo()
if (!data) { if (!res || !res.data) {
message.error(`验证失败,请重新登录...`) message.error(`验证失败,请重新登录...`)
return false return false
} }
// debugger // debugger
commit('setUsername', data.data.username) commit('setUsername', res.data.data.username)
commit('setRealname', data.data.realName) commit('setRealname', res.data.data.realName)
commit('setRole', data.data.roleIdList.length) commit('setRole', res.data.data.roleIdList.length)
commit('setUserId', data.data.id) commit('setUserId', res.data.data.id)
// TODO // TODO
// let { username, avatar, roles, ability } = data // let { username, avatar, roles, ability } = data
// if (username && roles && Array.isArray(roles)) { // if (username && roles && Array.isArray(roles)) {
@ -168,6 +168,7 @@ const actions = {
* @param {*} { commit, dispatch } * @param {*} { commit, dispatch }
*/ */
async resetAll({ dispatch }) { async resetAll({ dispatch }) {
debugger
await dispatch('setAccessToken', '') await dispatch('setAccessToken', '')
await dispatch('acl/setFull', false, { await dispatch('acl/setFull', false, {
root: true, root: true,

View File

@ -11,14 +11,8 @@ import store from '@/store'
import qs from 'qs' import qs from 'qs'
import router from '@/router' import router from '@/router'
// import { isArray } from '@/utils/validate' // import { isArray } from '@/utils/validate'
import { import { message } from 'ant-design-vue'
message import { getAccessToken, setAccessToken } from '@/utils/accessToken'
} from 'ant-design-vue'
import {
getAccessToken,
setAccessToken
} from '@/utils/accessToken'
let loadingInstance let loadingInstance
@ -36,9 +30,11 @@ const handleCode = (code, msg, res) => {
store.dispatch('user/resetAll').catch(() => {}) store.dispatch('user/resetAll').catch(() => {})
break break
case 403: case 403:
router.push({ router
path: '/401' .push({
}).catch(() => { }) path: '/401',
})
.catch(() => {})
break break
case 500: case 500:
message.error(msg || '接口异常') message.error(msg || '接口异常')
@ -103,17 +99,14 @@ instance.interceptors.response.use(
console.log('接口返回headers', response.headers) console.log('接口返回headers', response.headers)
console.log('接口返回REDIRECT', response.headers.redirect) console.log('接口返回REDIRECT', response.headers.redirect)
response['Access-Control-Expose-Headers'] = 'redirect' response['Access-Control-Expose-Headers'] = 'redirect'
const { const { code, message } = response.data
code,
message
} = response.data
if (response.headers.token) { if (response.headers.token) {
setAccessToken(response.headers.token) setAccessToken(response.headers.token)
} }
if (response.headers.redirect) { if (response.headers.redirect) {
const _old_href = window.location.href.split('#')[0]; const _old_href = window.location.href.split('#')[0]
const _new_href = response.headers.redirect.split('#')[0]; const _new_href = response.headers.redirect.split('#')[0]
window.location.replace(response.headers.redirect) window.location.replace(response.headers.redirect)
// url // url
if (_old_href === _new_href) { if (_old_href === _new_href) {
@ -168,14 +161,14 @@ instance.interceptors.response.use(
console.log('接口error', error) console.log('接口error', error)
if (loadingInstance) loadingInstance.close() if (loadingInstance) loadingInstance.close()
const { const { response, message } = error
response,
message
} = error
if (error.response) { if (error.response) {
console.log('接口返回', response) console.log('接口返回', response)
console.log('接口返回headers', response.headers) console.log('接口返回headers', response.headers)
console.log('接口返回REDIRECT', response.headers.redirect) console.log('接口返回REDIRECT', response.headers.redirect)
const { status, data } = response
handleCode(status, data.msg || message, response.headers.redirect)
if (response.headers.token) { if (response.headers.token) {
setAccessToken(response.headers.token) setAccessToken(response.headers.token)
} }
@ -183,17 +176,10 @@ instance.interceptors.response.use(
window.location.replace(response.headers.redirect) window.location.replace(response.headers.redirect)
return Promise.resolve() return Promise.resolve()
} }
const {
status,
data
} = response
handleCode(status, data.msg || message, response.headers.redirect)
return Promise.reject(error) return Promise.reject(error)
} else { } else {
let { let { message } = error
message
} = error
if (message === 'Network Error') { if (message === 'Network Error') {
message = '后端接口连接异常' message = '后端接口连接异常'
} }

View File

@ -1,8 +1,8 @@
/* /*
* @Author: hisense.wuhongjian * @Author: hisense.wuhongjian
* @Date: 2022-04-01 17:23:11 * @Date: 2022-04-01 17:23:11
* @LastEditors: Light * @LastEditors: hisense.wuhongjian
* @LastEditTime: 2022-10-10 16:43:58 * @LastEditTime: 2022-10-11 13:59:18
* @Description: 告诉大家这是什么 * @Description: 告诉大家这是什么
*/ */
/** /**
@ -26,7 +26,7 @@ router.beforeEach(async (to, from, next) => {
// if (SSOTOKEN) { // if (SSOTOKEN) {
// setAccessToken(SSOTOKEN) // setAccessToken(SSOTOKEN)
// } // }
console.log('验证白名单', routesWhiteList)
const token = getAccessToken() const token = getAccessToken()
console.log('token', token) console.log('token', token)
let hasToken = token let hasToken = token
@ -45,6 +45,7 @@ router.beforeEach(async (to, from, next) => {
router.addRoute(item) router.addRoute(item)
}) })
if (routesWhiteList.indexOf(to.path) !== -1) { if (routesWhiteList.indexOf(to.path) !== -1) {
debugger
next() next()
} else { } else {
// //