Merge pull request #614 from dataease/pr@dev@fix_外部链接token机制

fix: 外部链接token存储使用vuex不实用cookie
This commit is contained in:
fit2cloud-chenyw 2021-08-13 12:10:48 +08:00 committed by GitHub
commit 48f6889fe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View File

@ -219,7 +219,9 @@ export default {
// 使viewInfo 使viewData
let method = viewData
if (!getToken() && getLinkToken()) {
const token = this.$store.getters.token || getToken()
const linkToken = this.$store.getters.linkToken || getLinkToken()
if (!token && linkToken) {
method = viewInfo
}

View File

@ -4,6 +4,7 @@ const getters = {
size: state => state.app.size,
device: state => state.app.device,
token: state => state.user.token,
linkToken: state => state.user.linkToken,
avatar: state => state.user.avatar,
name: state => state.user.name,
introduction: state => state.user.introduction,

View File

@ -18,7 +18,8 @@ const getDefaultState = () => {
// 当前用户拥有哪些资源权限
permissions: [],
language: getLanguage(),
uiInfo: null
uiInfo: null,
linkToken: null
}
}
@ -31,6 +32,9 @@ const mutations = {
SET_TOKEN: (state, token) => {
state.token = token
},
SET_LINK_TOKEN: (state, linkToken) => {
state.linkToken = linkToken
},
SET_NAME: (state, name) => {
state.name = name
},
@ -165,6 +169,9 @@ const actions = {
commit('SET_LANGUAGE', language)
router.go(0)
})
},
setLinkToken({ commit }, linkToken) {
commit('SET_LINK_TOKEN', linkToken)
}
}

View File

@ -34,6 +34,10 @@ service.interceptors.request.use(
if ((linkToken = getLinkToken()) !== null) {
config.headers[LinkTokenKey] = linkToken
}
if (!linkToken) {
linkToken = store.getters.linkToken
config.headers[LinkTokenKey] = linkToken
}
if (i18n.locale) {
const lang = i18n.locale.replace('_', '-')
@ -92,6 +96,7 @@ const checkAuth = response => {
if (response.headers[LinkTokenKey.toLocaleLowerCase()] || (response.config.headers && response.config.headers[LinkTokenKey.toLocaleLowerCase()])) {
const linkToken = response.headers[LinkTokenKey.toLocaleLowerCase()] || response.config.headers[LinkTokenKey.toLocaleLowerCase()]
setLinkToken(linkToken)
store.dispatch('user/setLinkToken', linkToken)
}
// 许可状态改变 刷新页面
// if (response.headers['lic-status']) {