diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 8fb28926b..af0871a61 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -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) } @@ -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) }, @@ -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) }, diff --git a/src/utils/org.js b/src/utils/org.js index 730b7dd64..00f7fcb02 100644 --- a/src/utils/org.js +++ b/src/utils/org.js @@ -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() { diff --git a/src/utils/startup.js b/src/utils/startup.js index 48f099515..9806ddedc 100644 --- a/src/utils/startup.js +++ b/src/utils/startup.js @@ -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)) @@ -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) }) } @@ -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()) {