Skip to content

Commit

Permalink
fix: 修复切换到全局组织回不来的问题
Browse files Browse the repository at this point in the history
perf: 修改组织切换
  • Loading branch information
ibuler committed May 15, 2024
1 parent fb7c4a8 commit 72de927
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/store/modules/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const mutations = {
},
SET_CURRENT_ORG(state, org) {
// 系统组织和全局组织不设置成 Pre org
if (!state.currentOrg?.autoEnter) {
if (!state.currentOrg?.autoEnter && !state.currentOrg?.is_root) {
state.preOrg = state.currentOrg
setPreOrgLocal(state.username, state.currentOrg)
}
Expand Down Expand Up @@ -144,7 +144,7 @@ const actions = {
const systemOrg = {
id: orgUtil.SYSTEM_ORG_ID,
name: 'SystemSetting',
autoEnter: true
autoEnter: new Date().getTime()
}
commit('SET_CURRENT_ORG', systemOrg)
},
Expand All @@ -160,7 +160,7 @@ const actions = {
id: orgUtil.GLOBAL_ORG_ID,
name: 'Global',
is_root: true,
autoEnter: true
autoEnter: new Date().getTime()
}
commit('SET_CURRENT_ORG', globalOrg)
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function changeOrg(org, reload = true, vm = null) {
}
}
location.hash = '#' + path
setTimeout(() => location.reload(), 400)
setTimeout(() => location.reload(), 500)
}

function hasCurrentOrgPermission() {
Expand Down
24 changes: 15 additions & 9 deletions src/utils/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import orgs from '@/api/orgs'
import { getPropView, isViewHasOrgs } from '@/utils/jms'

const whiteList = ['/login', process.env.VUE_APP_LOGIN_PATH] // no redirect whitelist
const autoEnterOrgs = ['00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000000']

function reject(msg) {
return new Promise((resolve, reject) => reject(msg))
Expand Down Expand Up @@ -42,6 +43,10 @@ async function getPublicSetting({ to, from, next }, isOpen) {

async function refreshCurrentOrg() {
return orgs.getCurrentOrg().then(org => {
// Root 就不刷新本地的了, 会影响 autoEnter
if (autoEnterOrgs.indexOf(org.id) !== -1) {
return
}
store.dispatch('users/setCurrentOrg', org)
})
}
Expand All @@ -60,15 +65,16 @@ async function changeCurrentOrgIfNeed({ to, from, next }) {
Vue.$log.error('Current org is null or not a object: ', currentOrg)
await orgUtil.change2PropOrg({ to, from, next })
}
if (currentOrg.name === 'SystemSetting') {
const preOrg = store.getters.preOrg
await orgUtil.changeOrg(preOrg)
return
}
if (currentOrg.is_root && !currentOrg.autoEnter) {
setTimeout(() => {
orgUtil.change2PropOrg({ to, from, next })
}, 1000)
const globalOrgPath = [
'/console/perms/login-acls/', '/console/users/roles/',
'/console/perms/connect-method-acls/', '/settings/'
]
if (autoEnterOrgs.indexOf(currentOrg.id) !== -1 && currentOrg.autoEnter) {
const delta = new Date().getTime() - currentOrg.autoEnter
const notNeedChange = globalOrgPath.find(path => to.path.indexOf(path) === 0)
if (!notNeedChange && delta > 3000) {
await orgUtil.change2PropOrg({ to, from, next })
}
return
}
if (!orgUtil.hasCurrentOrgPermission()) {
Expand Down

0 comments on commit 72de927

Please sign in to comment.