fix: 修复切换项目缺陷

This commit is contained in:
shiziyuan9527 2020-12-14 17:43:57 +08:00
parent fd3c8052fc
commit 80a652813f
4 changed files with 26 additions and 11 deletions

View File

@ -26,13 +26,14 @@
</template>
<script>
import {
ROLE_ORG_ADMIN,
ROLE_TEST_MANAGER,
ROLE_TEST_USER,
ROLE_TEST_VIEWER,
WORKSPACE_ID
} from '../../../../common/js/constants';
import {
PROJECT_ID,
ROLE_ORG_ADMIN,
ROLE_TEST_MANAGER,
ROLE_TEST_USER,
ROLE_TEST_VIEWER,
WORKSPACE_ID
} from '../../../../common/js/constants';
import {getCurrentUser, hasRoles, saveLocalStorage} from "../../../../common/js/utils";
export default {
@ -107,6 +108,7 @@
if (response.data.workspaceId) {
localStorage.setItem("workspace_id", response.data.workspaceId);
}
localStorage.removeItem(PROJECT_ID)
this.$router.push('/');
window.location.reload();
});
@ -119,6 +121,7 @@
this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
saveLocalStorage(response);
localStorage.setItem("workspace_id", workspaceId);
localStorage.removeItem(PROJECT_ID)
this.$router.push('/');
window.location.reload();
})

View File

@ -11,7 +11,7 @@
无数据
</span>
</div>
<div v-else style="height: 120px;overflow: auto">
<div v-else style="height: 150px;overflow: auto">
<el-menu-item :key="i.id" v-for="i in items" @click="change(i.id)">
<template slot="title">
<div class="title">
@ -35,9 +35,19 @@ export default {
options: Object,
currentProject: String
},
created() {
if (getCurrentUser().lastProjectId) {
localStorage.setItem(PROJECT_ID, getCurrentUser().lastProjectId);
}
},
mounted() {
this.init();
},
computed: {
currentProjectId() {
return localStorage.getItem(PROJECT_ID)
}
},
data() {
return {
result: {},
@ -45,7 +55,6 @@ export default {
searchArray: [],
searchString: '',
userId: getCurrentUser().id,
currentProjectId: localStorage.getItem(PROJECT_ID)
}
},
watch: {
@ -83,6 +92,10 @@ export default {
};
},
change(projectId) {
let currentProjectId = getCurrentProjectID();
if (projectId === currentProjectId) {
return;
}
this.$post("/user/update/current", {id: this.userId, lastProjectId: projectId}, () => {
localStorage.setItem(PROJECT_ID, projectId);
if (this.$route.path.indexOf('/track/review/view/') >= 0) {

View File

@ -42,7 +42,7 @@
</el-submenu>
<el-menu-item v-for="menu in project" :key="menu.index" :index="'/setting/project/all'" class="setting-item"
v-permission="menu.roles">
v-permission="['test_user','test_manager', 'org_admin', 'admin']">
<template v-slot:title>
<font-awesome-icon class="icon" :icon="['fa', 'bars']" size="lg"/>
<span>{{ $t(menu.title) }}</span>

View File

@ -96,7 +96,6 @@ export function getCurrentProjectID() {
export function saveLocalStorage(response) {
// 登录信息保存 cookie
localStorage.setItem(TokenKey, JSON.stringify(response.data));
localStorage.setItem(PROJECT_ID, response.data.lastProjectId);
let rolesArray = response.data.roles;
let roles = rolesArray.map(r => r.id);
// 保存角色