Commit e74dad1b authored by xioln's avatar xioln

免登录处理

parent ed56bb88
......@@ -8,6 +8,7 @@ const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist
let path = ''
router.beforeEach(async (to, from, next) => {
const hasToken = getToken()
const isLogin = sessionStorage.getItem('isLogin')
if (hasToken) {
if (!to.matched.length) {
from.name ? next({ name: from.name }) : next('/home')
......@@ -38,7 +39,12 @@ router.beforeEach(async (to, from, next) => {
next()
}
} else {
if (util.getCookie('portal')) {
if (!isLogin) {
sessionStorage.setItem('isLogin', '1')
next()
} else if (isLogin === '2') {
next()
} else if (util.getCookie('portal')) {
singleLogin(false)
} else if (whiteList.indexOf(to.path) !== -1) {
next()
......@@ -49,7 +55,6 @@ router.beforeEach(async (to, from, next) => {
})
function singleLogin(state) {
const params = {}
console.log('util.getCookie', util.getCookie('url'))
if (util.getCookie('url')) {
const search = util.getCookie('url')
let query = search.substring(search.indexOf('?') + 1, search?.length)
......
......@@ -31,22 +31,22 @@ axios.interceptors.request.use(
delete config.data.userAction
}
if (store.getters.token) {
config.headers.authorization = getToken()
config.headers['Dex-Token'] = getToken()
config.headers['Dex-Auth-Type'] = 'Token'
if (!getToken()) {
delete config.headers.authorization
delete config.headers['Dex-Token']
}
} else if (sessionStorage.getItem('isLogin')) {
const queryUserAccount = queryURLParams(window.location.href).userAccount || sessionStorage.getItem('Login-free-userAccount') || ''
// eslint-disable-next-line no-prototype-builtins
if (queryUserAccount) {
const rsaUserAccount = RSA.rsaPublicData(queryUserAccount)
sessionStorage.setItem('Login-free-userAccount', queryUserAccount)
sessionStorage.setItem('isLogin', '2')
config.headers.authorization = rsaUserAccount
config.headers['Dex-Ukey-Token'] = rsaUserAccount
config.headers['Dex-Auth-Type'] = 'Ukey'
} else {
config.headers.authorization = getToken()
config.headers['Dex-Token'] = getToken()
config.headers['Dex-Auth-Type'] = 'Token'
}
if (!getToken()) {
delete config.headers.authorization
delete config.headers['Dex-Token']
}
}
return config
......
......@@ -92,8 +92,39 @@ export default {
// 避免堆栈溢出,多次创建、多次触发
window.removeEventListener('popstate', this.popstate, false)
},
mounted () { },
mounted () {
this.$nextTick(() => {
console.log('this.$router.query.userAccount', this.$route.query?.userAccount)
if (this.$route.query?.userAccount) {
this.setUserLocalData()
}
})
},
methods: {
setUserLocalData() {
const params = {
searchItems: {
items: [
{
fieldName: 'userAccount',
operator: 'EQ',
value: this.$route.query?.userAccount
}
],
operator: 'AND'
}
}
this.$api.searchApi('DxUserInfo', params).then(res => {
if (res.items.content) {
const userVO = res.items.content[0]
localStorage.setItem('user', userVO.name)
localStorage.setItem('userAccount', userVO.userAccount)
localStorage.setItem('fullName', userVO.nickName)
localStorage.setItem('userId', userVO.id)
localStorage.setItem('org', userVO.dxOrganizationId)
}
})
},
popstate () {
Dialog.confirm({
title: '是否退出?'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment