单点登录bug修复
This commit is contained in:
parent
678367a6bf
commit
a839c90a1e
|
@ -28,10 +28,10 @@
|
|||
<!-- 站点配置 -->
|
||||
<script>
|
||||
window.SITE_CONFIG = {};
|
||||
// window.SITE_CONFIG['backUrl'] = 'http://15.72.183.90:8001';
|
||||
// window.SITE_CONFIG['previewUrl'] = 'http://15.72.183.90:7008/';
|
||||
// window.SITE_CONFIG['frontUrl'] = 'http://15.72.183.90:7008/document/#/devModelFile/';
|
||||
// window.SITE_CONFIG['apiURL'] = 'http://15.72.183.90:8000/renren-admin';
|
||||
window.SITE_CONFIG['backUrl'] = 'http://15.72.183.90:8001';
|
||||
window.SITE_CONFIG['previewUrl'] = 'http://15.72.183.90:7008/';
|
||||
window.SITE_CONFIG['frontUrl'] = 'http://15.72.183.90:7008/document/#/devModelFile/';
|
||||
window.SITE_CONFIG['apiURL'] = 'http://15.72.183.90:8000/renren-admin';
|
||||
window.SITE_CONFIG['POI_URL'] = 'http://15.72.178.129:8090/iserver/services/addressmatch-qingdaoPOI181015/restjsr/v1/address';
|
||||
// 包头
|
||||
// window.SITE_CONFIG['backUrl'] = 'http://10.110.205.1:8001';
|
||||
|
@ -45,10 +45,10 @@
|
|||
// window.SITE_CONFIG['frontUrl'] = 'http://10.134.135.9:9796/document/#/devModelFile/';
|
||||
// window.SITE_CONFIG['apiURL'] = 'http://10.134.135.9:8888/renren-admin';
|
||||
// 开发
|
||||
window.SITE_CONFIG['backUrl'] = 'http://15.2.21.238:9797';
|
||||
window.SITE_CONFIG['previewUrl'] = 'http://15.2.21.238:9796/';
|
||||
window.SITE_CONFIG['frontUrl'] = 'http://15.2.21.238:9796/document/#/devModelFile/';
|
||||
window.SITE_CONFIG['apiURL'] = 'http://15.2.21.238:8888/renren-admin';
|
||||
// window.SITE_CONFIG['backUrl'] = 'http://15.2.21.238:9797';
|
||||
// window.SITE_CONFIG['previewUrl'] = 'http://15.2.21.238:9796/';
|
||||
// window.SITE_CONFIG['frontUrl'] = 'http://15.2.21.238:9796/document/#/devModelFile/';
|
||||
// window.SITE_CONFIG['apiURL'] = 'http://15.2.21.238:8888/renren-admin';
|
||||
// window.SITE_CONFIG['POI_URL'] = 'http://15.72.178.129:8090/iserver/services/addressmatch-qingdaoPOI181015/restjsr/v1/address';
|
||||
// 穿透版本
|
||||
// window.SITE_CONFIG['backUrl'] = 'http://124.222.94.39:9797';
|
||||
|
|
|
@ -2,30 +2,30 @@
|
|||
* @author chuzhixin 1204505056@qq.com
|
||||
* @description 登录、获取用户信息、退出登录、清除accessToken逻辑,不建议修改
|
||||
*/
|
||||
import { getUserInfo, login, logout } from '@/api/user'
|
||||
import {
|
||||
import { getUserInfo, login, logout } from '@/api/user'
|
||||
import {
|
||||
getAccessToken,
|
||||
removeAccessToken,
|
||||
setAccessToken,
|
||||
} from '@/utils/accessToken'
|
||||
import { title, tokenName } from '@/config'
|
||||
import { message, notification } from 'ant-design-vue'
|
||||
} from '@/utils/accessToken'
|
||||
import { title, tokenName } from '@/config'
|
||||
import { message, notification } from 'ant-design-vue'
|
||||
|
||||
const state = () => ({
|
||||
const state = () => ({
|
||||
accessToken: getAccessToken(),
|
||||
username: '',
|
||||
userId: '',
|
||||
avatar: '',
|
||||
role: 0, // 用户管理员权限
|
||||
})
|
||||
const getters = {
|
||||
})
|
||||
const getters = {
|
||||
accessToken: (state) => state.accessToken,
|
||||
username: (state) => state.username,
|
||||
avatar: (state) => state.avatar,
|
||||
role: (state) => state.role,
|
||||
userId: (state) => state.userId,
|
||||
}
|
||||
const mutations = {
|
||||
}
|
||||
const mutations = {
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com
|
||||
* @description 设置accessToken
|
||||
|
@ -62,8 +62,8 @@ const mutations = {
|
|||
setAvatar(state, avatar) {
|
||||
state.avatar = avatar
|
||||
},
|
||||
}
|
||||
const actions = {
|
||||
}
|
||||
const actions = {
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com
|
||||
* @description 登录拦截放行时,设置虚拟角色
|
||||
|
@ -113,24 +113,31 @@ const actions = {
|
|||
* @param {*} { commit, dispatch, state }
|
||||
* @returns
|
||||
*/
|
||||
getUserInfo({ commit }) {
|
||||
return new Promise((resolve, reject)=>{
|
||||
getUserInfo().then( (res) =>{
|
||||
console.log('res', res)
|
||||
const data = res.data
|
||||
async getUserInfo({ commit }) {
|
||||
const { data } = await getUserInfo()
|
||||
if (!data) {
|
||||
message.error(`验证失败,请重新登录...`)
|
||||
reject()
|
||||
return false
|
||||
}
|
||||
// debugger
|
||||
commit('setUsername', data.data.username)
|
||||
commit('setRole', data.data.roleIdList.length)
|
||||
commit('setUserId', data.data.id)
|
||||
setTimeout(()=>{
|
||||
resolve()
|
||||
},500)
|
||||
|
||||
})
|
||||
})
|
||||
// TODO 获取用户信息,后续执行部分操作
|
||||
// let { username, avatar, roles, ability } = data
|
||||
// if (username && roles && Array.isArray(roles)) {
|
||||
// dispatch('acl/setRole', roles, {
|
||||
// root: true,
|
||||
// })
|
||||
// if (ability && ability.length > 0)
|
||||
// dispatch('acl/setAbility', ability, {
|
||||
// root: true,
|
||||
// })
|
||||
// commit('setUsername', username)
|
||||
// commit('setAvatar', avatar)
|
||||
// } else {
|
||||
// message.error('用户信息接口异常')
|
||||
// }
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -167,10 +174,10 @@ const actions = {
|
|||
setAccessToken({ commit }, accessToken) {
|
||||
commit('setAccessToken', accessToken)
|
||||
},
|
||||
}
|
||||
export default {
|
||||
}
|
||||
export default {
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import qs from 'qs'
|
|||
import router from '@/router'
|
||||
// import { isArray } from '@/utils/validate'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { setAccessToken } from '@/utils/accessToken'
|
||||
import { getAccessToken, setAccessToken } from '@/utils/accessToken'
|
||||
|
||||
let loadingInstance
|
||||
|
||||
|
@ -22,15 +22,24 @@ let loadingInstance
|
|||
* @param {*} code
|
||||
* @param {*} msg
|
||||
*/
|
||||
const handleCode = (code, msg, redirect) => {
|
||||
const handleCode = (code, msg, res) => {
|
||||
debugger
|
||||
switch (code) {
|
||||
case 401:
|
||||
// message.error(msg || '登录失效')
|
||||
|
||||
store.dispatch('user/resetAll').catch(() => {})
|
||||
// // location.reload()
|
||||
if (redirect) {
|
||||
window.location.href = redirect
|
||||
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(() => {})
|
||||
|
@ -87,10 +96,21 @@ instance.interceptors.request.use(
|
|||
*/
|
||||
instance.interceptors.response.use(
|
||||
(response) => {
|
||||
// console.log('接口返回', response)
|
||||
// console.log('接口返回headers', response.headers)
|
||||
// console.log('接口返回REDIRECT', response.headers.redirect)
|
||||
|
||||
console.log('接口返回', response)
|
||||
console.log('接口返回headers', response.headers)
|
||||
console.log('接口返回REDIRECT', response.headers.redirect)
|
||||
response['Access-Control-Expose-Headers'] = 'redirect'
|
||||
const { code, message } = response.data
|
||||
if (response.headers.token) {
|
||||
setAccessToken(response.headers.token)
|
||||
} else {
|
||||
if (response.headers.redirect) {
|
||||
// window.location.href = response.headers.redirect
|
||||
window.location.replace(response.headers.redirect)
|
||||
return
|
||||
// location.reload()
|
||||
}
|
||||
}
|
||||
if (response.headers.redirect === '/#/login') {
|
||||
var keys = document.cookie.match(/[^ =;]+(?=\=)/g)
|
||||
if (keys) {
|
||||
|
@ -109,29 +129,12 @@ instance.interceptors.response.use(
|
|||
new Date(0).toUTCString() //清除一级域名下的或指定的,例如 .kevis.com
|
||||
}
|
||||
}
|
||||
// console.log('已清除')
|
||||
console.log('已清除')
|
||||
setTimeout(() => {
|
||||
location.reload()
|
||||
}, 1000)
|
||||
}
|
||||
debugger;
|
||||
response['Access-Control-Expose-Headers'] = 'redirect'
|
||||
const { code, message } = response.data
|
||||
if (response.headers.token) {
|
||||
setAccessToken(response.headers.token)
|
||||
debugger
|
||||
// setAccessToken(response.headers.token)
|
||||
// store.dispatch('user/getUserInfo')
|
||||
} else {
|
||||
if (response.headers.redirect) {
|
||||
// window.location.href = response.headers.redirect
|
||||
window.location.replace(response.headers.redirect)
|
||||
return
|
||||
// location.reload()
|
||||
}
|
||||
}
|
||||
|
||||
handleCode(code, message, response.headers.redirect)
|
||||
handleCode(code, message, response.headers)
|
||||
if (loadingInstance) loadingInstance.close()
|
||||
// const { data, config } = response
|
||||
// const { code, msg } = data
|
||||
|
@ -151,38 +154,15 @@ instance.interceptors.response.use(
|
|||
// }
|
||||
},
|
||||
(error) => {
|
||||
// console.log('接口error', error)
|
||||
console.log('接口error', error)
|
||||
if (loadingInstance) loadingInstance.close()
|
||||
const { response, message } = error
|
||||
if (error.response && error.response.data) {
|
||||
// console.log('接口返回', response)
|
||||
// console.log('接口返回headers', response.headers)
|
||||
// console.log('接口返回REDIRECT1111', response.headers.redirect)
|
||||
if (response.headers.redirect === '/#/login') {
|
||||
var keys = document.cookie.match(/[^ =;]+(?=\=)/g)
|
||||
if (keys) {
|
||||
for (var i = keys.length; i--; ) {
|
||||
document.cookie =
|
||||
keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString() //清除当前域名下的,例如:m.kevis.com
|
||||
document.cookie =
|
||||
keys[i] +
|
||||
'=0;path=/;domain=' +
|
||||
document.domain +
|
||||
';expires=' +
|
||||
new Date(0).toUTCString() //清除当前域名下的,例如 .m.kevis.com
|
||||
document.cookie =
|
||||
keys[i] +
|
||||
'=0;path=/;domain=kevis.com;expires=' +
|
||||
new Date(0).toUTCString() //清除一级域名下的或指定的,例如 .kevis.com
|
||||
}
|
||||
}
|
||||
// console.log('已清除')
|
||||
setTimeout(() => {
|
||||
location.reload()
|
||||
}, 1000)
|
||||
}
|
||||
console.log('接口返回', response)
|
||||
console.log('接口返回headers', response.headers)
|
||||
console.log('接口返回REDIRECT', response.headers.redirect)
|
||||
if (response.headers.redirect) {
|
||||
window.location.href = response.headers.redirect
|
||||
window.location.replace(response.headers.redirect)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
const { status, data } = response
|
||||
|
|
|
@ -2,42 +2,39 @@
|
|||
* @Author: hisense.wuhongjian
|
||||
* @Date: 2022-04-01 17:23:11
|
||||
* @LastEditors: hisense.wuhongjian
|
||||
* @LastEditTime: 2022-07-07 19:58:32
|
||||
* @LastEditTime: 2022-07-08 18:55:28
|
||||
* @Description: 告诉大家这是什么
|
||||
*/
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com
|
||||
* @description 路由守卫,目前两种模式:all模式与intelligence模式
|
||||
*/
|
||||
import router from '@/router'
|
||||
import store from '@/store'
|
||||
import getPageTitle from '@/utils/pageTitle'
|
||||
import {
|
||||
import router from '@/router'
|
||||
import store from '@/store'
|
||||
import getPageTitle from '@/utils/pageTitle'
|
||||
import { getUserInfo } from '@/api/user'
|
||||
import {
|
||||
// authentication,
|
||||
loginInterception,
|
||||
// recordRoute,
|
||||
routesWhiteList,
|
||||
} from '@/config'
|
||||
import { setAccessToken, getAccessToken } from '@/utils/accessToken'
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
// 初始化拦截
|
||||
} from '@/config'
|
||||
import { setAccessToken, getAccessToken } from '@/utils/accessToken'
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
// debugger
|
||||
// const SSOTOKEN = to.query.SSOToken
|
||||
// if (SSOTOKEN) {
|
||||
// setAccessToken(SSOTOKEN)
|
||||
// }
|
||||
const token = getAccessToken()
|
||||
// console.log('token', token)
|
||||
console.log('token', token)
|
||||
let hasToken = token || store.getters['user/accessToken']
|
||||
// debugger
|
||||
// 未开启登录拦截状态
|
||||
if (!loginInterception) hasToken = true
|
||||
// console.log('hasToken存在巨大问题', hasToken)
|
||||
debugger
|
||||
console.log('hasToken存在巨大问题', hasToken)
|
||||
if (hasToken) {
|
||||
setAccessToken(token)
|
||||
setAccessToken(hasToken)
|
||||
await store.dispatch('user/getUserInfo')
|
||||
debugger
|
||||
next()
|
||||
} else {
|
||||
let accessRoutes = []
|
||||
|
@ -48,21 +45,20 @@ router.beforeEach(async (to, from, next) => {
|
|||
if (routesWhiteList.indexOf(to.path) !== -1) {
|
||||
next()
|
||||
} else {
|
||||
store.dispatch('user/getUserInfo').then((res)=>{
|
||||
console.log('马到成功!')
|
||||
next()
|
||||
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 })
|
||||
// debugger
|
||||
// setTimeout(()=>{
|
||||
// next()
|
||||
// }, 500)
|
||||
// window.open('http://www.baidu.com', '_self')
|
||||
}
|
||||
}
|
||||
})
|
||||
router.afterEach((to) => {
|
||||
})
|
||||
router.afterEach((to) => {
|
||||
document.title = getPageTitle(to.meta.title)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue