更改token问题
This commit is contained in:
parent
240784a3b2
commit
70bb06cba6
|
@ -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: {
|
||||
// 青岛市大数据局
|
||||
|
|
|
@ -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', // 内网穿透
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 || '接口异常')
|
||||
|
@ -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 = '后端接口连接异常'
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
// 这里是一个单点登录的入口
|
||||
|
|
Loading…
Reference in New Issue