From 0e7b60a00105ca8e12f190df3800424b560f9165 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 21 Apr 2022 11:07:56 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20=E5=88=87=E6=8D=A2=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E5=88=87=E6=8D=A2=E7=9A=84=E9=97=AE=E9=A2=98=20(#1701?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 切换视图的问题,修复组织切换的问题 * perf: 优化写法 Co-authored-by: ibuler --- .../components/NavHeader/Organization.vue | 19 ++++---- src/utils/common.js | 4 ++ src/utils/org.js | 45 +++++++++---------- src/utils/startup.js | 12 +++-- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/layout/components/NavHeader/Organization.vue b/src/layout/components/NavHeader/Organization.vue index dd437df42..c047ede7f 100644 --- a/src/layout/components/NavHeader/Organization.vue +++ b/src/layout/components/NavHeader/Organization.vue @@ -101,16 +101,19 @@ export default { return currentOrgId } }, - created() { - }, methods: { changeOrg(orgId) { - if (orgId === 'create') { - this.$router.push({ name: 'OrganizationCreate' }) - } else if (orgId === 'list') { - this.$router.push({ name: 'OrganizationList' }) - } else { - orgUtil.changeOrg(orgId) + const org = this.usingOrgs.find(item => item.id === orgId) + + switch (orgId) { + case 'create': + this.$router.push({ name: 'OrganizationCreate' }) + break + case 'list': + this.$router.push({ name: 'OrganizationList' }) + break + default: + orgUtil.changeOrg(org) } } } diff --git a/src/utils/common.js b/src/utils/common.js index 8e0e407ff..33f6cba83 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -159,6 +159,10 @@ export function hasUUID(s) { return s.search(uuidPattern) !== -1 } +export function replaceUUID(s, n) { + return s.replace(uuidPattern, n) +} + export function getDaysAgo(days, now) { if (!now) { now = new Date() diff --git a/src/utils/org.js b/src/utils/org.js index 53842ea14..e2808a99d 100644 --- a/src/utils/org.js +++ b/src/utils/org.js @@ -1,6 +1,5 @@ -import { hasUUID, BASE_URL } from '@/utils/common' -import { getOrgDetail } from '@/api/orgs' import store from '@/store' +import { hasUUID, replaceUUID } from '@/utils/common' export const DEFAULT_ORG_ID = '00000000-0000-0000-0000-000000000002' @@ -10,12 +9,25 @@ function getPropOrg() { if (defaultOrg) { return defaultOrg } - return orgs.filter(item => !item.is_root)[0] + return orgs.filter(item => !item['is_root'])[0] } -function change2PropOrg() { +async function change2PropOrg() { const org = getPropOrg() - setTimeout(() => changeOrg(org.id), 100) + await changeOrg(org) +} + +async function changeOrg(org) { + await store.dispatch('users/setCurrentOrg', org) + await store.dispatch('app/reset') + let path = location.href + if (hasUUID(path)) { + path = replaceUUID(path, '') + path = _.trimEnd(path, '/') + location.href = path + } else { + location.reload() + } } function hasCurrentOrgPermission() { @@ -25,27 +37,10 @@ function hasCurrentOrgPermission() { return orgs.find((item) => item.id === currentOrgId) } -async function changeOrg(orgId) { - const org = await getOrgDetail(orgId) - if (!org) { - console.debug('Error: org not found') - } else { - console.debug('Change to org: ', org) - } - - store.dispatch('users/setCurrentOrg', org).then(() => { - // console.log('Set current org to: ', org) - if (hasUUID(location.href)) { - location.href = BASE_URL - } else { - window.location.reload(true) - } - }) -} - export default { hasCurrentOrgPermission, - changeOrg, DEFAULT_ORG_ID, - change2PropOrg + change2PropOrg, + changeOrg, + getPropOrg } diff --git a/src/utils/startup.js b/src/utils/startup.js index 4a4056643..d9481a1dd 100644 --- a/src/utils/startup.js +++ b/src/utils/startup.js @@ -67,14 +67,12 @@ async function changeCurrentOrgIfNeed({ to, from, next }) { await refreshCurrentOrg() const currentOrg = store.getters.currentOrg if (!currentOrg || typeof currentOrg !== 'object') { - Vue.$log.error('Current org is null or not a object') - orgUtil.change2PropOrg() - return reject('Change prop org') + Vue.$log.error('Current org is null or not a object: ', currentOrg) + await orgUtil.change2PropOrg({ to, from, next }) } if (!orgUtil.hasCurrentOrgPermission()) { - Vue.$log.error('Not has current org permission') - orgUtil.change2PropOrg() - return reject('Change prop org') + Vue.$log.error('Not has current org permission: ', currentOrg) + await orgUtil.change2PropOrg({ to, from, next }) } } @@ -126,7 +124,7 @@ export async function changeCurrentViewIfNeed({ to, from, next }) { } const has = isViewHasOrgs(viewName) - Vue.$log.debug('Change has current view, has perm: ', has) + Vue.$log.debug('Change has current view, has perm: ', viewName, '=>', has) if (has) { await store.dispatch('users/changeToView', viewName) return From b9547214b703ece4d339a63fea437968e96b11c4 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 21 Apr 2022 13:59:58 +0800 Subject: [PATCH 2/7] =?UTF-8?q?perf:=20view=20switch=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=20(#1702)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: view switch 默认值 * perf: 去掉冗余 Co-authored-by: ibuler --- src/layout/components/NavHeader/ViewSwitcher.vue | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/layout/components/NavHeader/ViewSwitcher.vue b/src/layout/components/NavHeader/ViewSwitcher.vue index 817523cdc..2bc1dbfe3 100644 --- a/src/layout/components/NavHeader/ViewSwitcher.vue +++ b/src/layout/components/NavHeader/ViewSwitcher.vue @@ -1,6 +1,6 @@