diff --git a/frontend/src/components/canvas/custom-component/UserView.vue b/frontend/src/components/canvas/custom-component/UserView.vue index 50c444cd92..7267dd68b8 100644 --- a/frontend/src/components/canvas/custom-component/UserView.vue +++ b/frontend/src/components/canvas/custom-component/UserView.vue @@ -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 } diff --git a/frontend/src/store/getters.js b/frontend/src/store/getters.js index ada150bc49..cb814086c2 100644 --- a/frontend/src/store/getters.js +++ b/frontend/src/store/getters.js @@ -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, diff --git a/frontend/src/store/modules/user.js b/frontend/src/store/modules/user.js index e67c16c1d3..edf18a7091 100644 --- a/frontend/src/store/modules/user.js +++ b/frontend/src/store/modules/user.js @@ -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) } } diff --git a/frontend/src/utils/request.js b/frontend/src/utils/request.js index 77623de695..b0dcabba45 100644 --- a/frontend/src/utils/request.js +++ b/frontend/src/utils/request.js @@ -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']) {