From 62ed11e7ec91fa99ec66768e54d96398ca22eddf Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Mon, 18 Apr 2022 20:20:32 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=89=80=E5=B1=9E=E7=9A=84=20org=20(#1662)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 修改用户所属的 org * perf: 修改组织问题 * perf: 修改优化 nav 切换 * perf: 修改 org id * perf: 修改验证逻辑 * perf: 修改 orgs Co-authored-by: ibuler --- src/api/orgs.js | 6 ++ src/api/users.js | 5 ++ src/guards.js | 23 +---- .../components/NavHeader/AccountDropdown.vue | 24 ++--- .../components/NavHeader/Organization.vue | 41 +++++---- .../components/NavHeader/ViewSwitcher.vue | 22 +++-- src/router/audit/index.js | 7 +- src/router/console/index.js | 7 +- src/router/index.js | 7 +- src/router/profile/index.js | 2 +- src/router/workbench/index.js | 7 +- src/store/getters.js | 9 +- src/store/modules/app.js | 12 ++- src/store/modules/permission.js | 3 - src/store/modules/users.js | 89 ++++++------------- src/utils/auth.js | 5 +- src/utils/jms.js | 46 ++++------ src/utils/org.js | 6 +- src/utils/startup.js | 52 ++++++++--- src/views/myassets/index.vue | 1 - src/views/profile/TempPassword.vue | 4 +- .../tickets/TicketFlow/FlowCreateUpdate.vue | 4 +- src/views/tickets/components/Session.vue | 1 - 23 files changed, 194 insertions(+), 189 deletions(-) diff --git a/src/api/orgs.js b/src/api/orgs.js index 34ec9acd7..823581c42 100644 --- a/src/api/orgs.js +++ b/src/api/orgs.js @@ -13,3 +13,9 @@ export function getCurrentOrg() { method: 'get' }) } + +export default { + getCurrentOrg, + getOrgDetail +} + diff --git a/src/api/users.js b/src/api/users.js index 84b302629..3482c9e89 100644 --- a/src/api/users.js +++ b/src/api/users.js @@ -69,3 +69,8 @@ export function logout() { export function refreshSessionIdAge() { return getProfile() } + +export default { + getProfile, + getUserList +} diff --git a/src/guards.js b/src/guards.js index ee484ddcc..82c6d8397 100644 --- a/src/guards.js +++ b/src/guards.js @@ -4,8 +4,7 @@ import NProgress from 'nprogress' // progress bar import 'nprogress/nprogress.css' // progress bar style import { startup } from '@/utils/startup' import store from '@/store' -import { getPropView, hasRouteViewPerm, isSameView } from '@/utils/jms' -import Vue from 'vue' +import { isSameView } from '@/utils/jms' NProgress.configure({ showSpinner: false @@ -30,20 +29,6 @@ function generateViewRoutesIfChange({ to, from }) { } } -async function changeCurrentViewIfNeed({ to, from, next }) { - if (!to.path || isSameView(to, from)) { - return - } - const hasPerm = hasRouteViewPerm(to) - Vue.$log.debug('Change has current view, has perm: ', hasPerm) - if (hasPerm) { - return - } - const view = getPropView() - Vue.$log.debug('Get prop view and goto: ', view) - next(`/${view}`) -} - function setPageTitle() { const currentRoute = router.currentRoute const loginTitle = store.getters.publicSettings['LOGIN_TITLE'] @@ -53,12 +38,6 @@ function setPageTitle() { } } -router.beforeResolve(async(to, from, next) => { - /* must call `next` */ - await changeCurrentViewIfNeed({ to, from, next }) - next() -}) - router.afterEach(async(to, from) => { // finish progress bar await setPageTitle() diff --git a/src/layout/components/NavHeader/AccountDropdown.vue b/src/layout/components/NavHeader/AccountDropdown.vue index 4f2014ab5..4bc375a72 100644 --- a/src/layout/components/NavHeader/AccountDropdown.vue +++ b/src/layout/components/NavHeader/AccountDropdown.vue @@ -7,10 +7,18 @@ - {{ $t('common.nav.Profile') }} - {{ $t('common.nav.APIKey') }} - {{ $t('common.nav.TempPassword') }} - {{ $t('common.nav.Logout') }} + + {{ $t('common.nav.Profile') }} + + + {{ $t('common.nav.APIKey') }} + + + {{ $t('common.nav.TempPassword') }} + + + {{ $t('common.nav.Logout') }} + @@ -29,11 +37,7 @@ export default { }, computed: { ...mapGetters([ - 'currentUser', - 'currentRole', - 'currentOrgRoles', - 'orgs', - 'currentOrgPerms' + 'currentUser' ]) }, created() { @@ -52,7 +56,7 @@ export default { this.$router.push('/profile/key') break case 'tempPassword': - this.$router.push('/profile/tempPassword') + this.$router.push('/profile/temp-password') } }, logout() { diff --git a/src/layout/components/NavHeader/Organization.vue b/src/layout/components/NavHeader/Organization.vue index 062621c83..87439fb69 100644 --- a/src/layout/components/NavHeader/Organization.vue +++ b/src/layout/components/NavHeader/Organization.vue @@ -11,7 +11,7 @@ {{ item.name }} - @@ -55,15 +54,10 @@ export default { computed: { ...mapGetters([ 'currentOrg', - 'currentRole', - 'orgs' - ]) - }, - created() { - this.init() - }, - methods: { - init() { + 'usingOrgs', + 'currentViewRoute' + ]), + orgActionsGroup() { const orgActions = { label: this.$t('xpack.Organization.OrganizationList'), options: [ @@ -82,14 +76,25 @@ export default { ] } const hasPerms = this.$hasPerm('orgs.view_organization | orgs.add_organization') - this.orgOption = [ - (hasPerms && orgActions), - { - label: this.$t('xpack.Organization.AllOrganization'), - options: this.orgs - } - ] + const isConsole = this.currentViewRoute.name === 'console' + return hasPerms && isConsole ? orgActions : {} }, + orgChoicesGroup() { + return { + label: this.$t('xpack.Organization.AllOrganization'), + options: this.usingOrgs + } + }, + orgGroups() { + return [ + this.orgActionsGroup, + this.orgChoicesGroup + ] + } + }, + created() { + }, + methods: { changeOrg(orgId) { if (orgId === 'create') { this.$router.push({ name: 'OrganizationCreate' }) diff --git a/src/layout/components/NavHeader/ViewSwitcher.vue b/src/layout/components/NavHeader/ViewSwitcher.vue index df0533803..817523cdc 100644 --- a/src/layout/components/NavHeader/ViewSwitcher.vue +++ b/src/layout/components/NavHeader/ViewSwitcher.vue @@ -19,7 +19,6 @@ @@ -31,6 +30,7 @@