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

View File

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

View File

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

View File

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