refactor: 顶部切换工作空间菜单修改

This commit is contained in:
Captain.B 2021-06-11 10:26:08 +08:00 committed by 刘瑞斌
parent 2508965ab3
commit 88b6e742a7
1 changed files with 54 additions and 40 deletions

View File

@ -1,5 +1,6 @@
<template> <template>
<el-menu :unique-opened="true" mode="horizontal" router <el-menu :unique-opened="true" mode="horizontal"
router
class="header-user-menu align-right" class="header-user-menu align-right"
:background-color="color" :background-color="color"
active-text-color="#fff" active-text-color="#fff"
@ -11,10 +12,10 @@
'PROJECT_API_DEFINITION:READ','PROJECT_API_SCENARIO:READ','PROJECT_API_REPORT:READ', 'PROJECT_API_DEFINITION:READ','PROJECT_API_SCENARIO:READ','PROJECT_API_REPORT:READ',
'PROJECT_PERFORMANCE_TEST:READ','PROJECT_PERFORMANCE_REPORT:READ', 'ORGANIZATION_USER:READ', 'PROJECT_PERFORMANCE_TEST:READ','PROJECT_PERFORMANCE_REPORT:READ', 'ORGANIZATION_USER:READ',
'WORKSPACE_USER:READ']"> 'WORKSPACE_USER:READ']">
<template v-slot:title>{{ $t('commons.organization') }}: <template v-slot:title>
<span class="org-ws-name" :title="currentOrganizationName"> <div class="org-ws-name" :title="currentOrganizationName + '-' + currentWorkspaceName">
{{ currentOrganizationName }} <div>{{ currentWorkspaceName || currentOrganizationName }}</div>
</span> </div>
</template> </template>
<el-input :placeholder="$t('project.search_by_name')" <el-input :placeholder="$t('project.search_by_name')"
prefix-icon="el-icon-search" prefix-icon="el-icon-search"
@ -23,38 +24,29 @@
class="search-input" class="search-input"
size="small"/> size="small"/>
<div class="org-ws-menu"> <div class="org-ws-menu">
<el-menu-item @click="changeOrg(item)" v-for="(item,index) in organizationList" :key="index"> <el-submenu :index="1+'-'+index" v-for="(item, index) in organizationList" :key="index">
<span class="title"> <template v-slot:title>
{{ item.name }} <div @click="changeOrg(item)">
</span> {{ item.name }}
<i class="el-icon-check" <i class="el-icon-check" v-if="item.id === getCurrentOrganizationId()"></i>
v-if="item.id === getCurrentOrganizationId()"></i> </div>
</el-menu-item> </template>
</div> <el-input :placeholder="$t('project.search_by_name')"
</el-submenu> prefix-icon="el-icon-search"
<el-submenu index="2" popper-class="submenu" v-model="searchWs"
v-permission="['PROJECT_TRACK_CASE:READ','PROJECT_TRACK_PLAN:READ','PROJECT_TRACK_REVIEW:READ', clearable
'PROJECT_API_DEFINITION:READ','PROJECT_API_SCENARIO:READ','PROJECT_API_REPORT:READ', class="search-input"
'PROJECT_PERFORMANCE_TEST:READ','PROJECT_PERFORMANCE_REPORT:READ','WORKSPACE_USER:READ']" size="small"/>
> <div class="org-ws-menu">
<template v-slot:title>{{ $t('commons.workspace') }}: <el-menu-item :index="1+'-'+index+'-'+index2" @click="changeWs(ws)"
<span class="org-ws-name" :title="currentWorkspaceName"> v-for="(ws,index2) in item.workspaceList" :key="index2">
{{ currentWorkspaceName }} <span class="title">
</span> {{ ws.name }}
</template> </span>
<el-input :placeholder="$t('project.search_by_name')" <i class="el-icon-check" v-if="ws.id === getCurrentWorkspaceId()"></i>
prefix-icon="el-icon-search" </el-menu-item>
v-model="searchWs" </div>
clearable </el-submenu>
class="search-input"
size="small"/>
<div class="org-ws-menu">
<el-menu-item @click="changeWs(item)" v-for="(item,index) in workspaceList" :key="index">
<span class="title">
{{ item.name }}
</span>
<i class="el-icon-check" v-if="item.id === getCurrentWorkspaceId()"></i>
</el-menu-item>
</div> </div>
</el-submenu> </el-submenu>
</el-menu> </el-menu>
@ -120,11 +112,28 @@ export default {
if (org.length > 0) { if (org.length > 0) {
this.currentOrganizationName = org[0].name; this.currentOrganizationName = org[0].name;
} }
this.organizationList.forEach(org => {
this.$get("/workspace/list/orgworkspace/" + org.id, response => {
let d = response.data;
if (d.length === 0) {
// org.workspaceList = [{name: this.$t('workspace.none')}];
// this.$set(org, 'workspaceList', [{name: this.$t('workspace.none')}]);
} else {
this.$set(org, 'workspaceList', d);
// org.workspaceList = d;
org.wsListCopy = d;
let workspace = d.filter(r => r.id === getCurrentWorkspaceId());
if (workspace.length > 0) {
this.currentWorkspaceName = workspace[0].name;
}
}
});
});
}); });
if (!this.currentUser.lastOrganizationId) { if (!this.currentUser.lastOrganizationId) {
return false; return false;
} }
this.$get("/workspace/list/orgworkspace/" + getCurrentOrganizationId(), response => { /*this.$get("/workspace/list/orgworkspace/" + getCurrentOrganizationId(), response => {
let data = response.data; let data = response.data;
if (data.length === 0) { if (data.length === 0) {
this.workspaceList = [{name: this.$t('workspace.none')}]; this.workspaceList = [{name: this.$t('workspace.none')}];
@ -136,7 +145,7 @@ export default {
this.currentWorkspaceName = workspace[0].name; this.currentWorkspaceName = workspace[0].name;
} }
} }
}); });*/
}, },
getCurrentUserInfo() { getCurrentUserInfo() {
this.$get("/user/info/" + encodeURIComponent(this.currentUserId), response => { this.$get("/user/info/" + encodeURIComponent(this.currentUserId), response => {
@ -167,6 +176,8 @@ export default {
} }
this.$post("/user/switch/source/ws/" + workspaceId, {}, response => { this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
saveLocalStorage(response); saveLocalStorage(response);
sessionStorage.setItem(ORGANIZATION_ID, response.data.lastOrganizationId);
sessionStorage.setItem(WORKSPACE_ID, workspaceId); sessionStorage.setItem(WORKSPACE_ID, workspaceId);
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId); sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
@ -180,7 +191,10 @@ export default {
this.organizationList = queryString ? this.orgListCopy.filter(this.createFilter(queryString)) : this.orgListCopy; this.organizationList = queryString ? this.orgListCopy.filter(this.createFilter(queryString)) : this.orgListCopy;
} }
if (sign === 'ws') { if (sign === 'ws') {
this.workspaceList = queryString ? this.wsListCopy.filter(this.createFilter(queryString)) : this.wsListCopy; this.organizationList.forEach(org => {
let wsListCopy = org.wsListCopy;
org.workspaceList = queryString ? wsListCopy?.filter(this.createFilter(queryString)) : wsListCopy;
});
} }
}, },
createFilter(queryString) { createFilter(queryString) {