fix: 登录后未保存当前项目值

This commit is contained in:
shiziyuan9527 2020-12-11 14:36:12 +08:00
parent a3cfeaca6c
commit 928f7bcf7c
2 changed files with 7 additions and 4 deletions

View File

@ -16,7 +16,7 @@
<template slot="title"> <template slot="title">
<div class="title"> <div class="title">
{{ i.name }} {{ i.name }}
<i class="el-icon-check" v-if="i.id === projectId"></i> <i class="el-icon-check" v-if="i.id === currentProjectId"></i>
</div> </div>
</template> </template>
</el-menu-item> </el-menu-item>
@ -26,7 +26,7 @@
</template> </template>
<script> <script>
import {getCurrentUser, hasRoles} from "@/common/js/utils"; import {getCurrentProjectID, getCurrentUser, hasRoles} from "@/common/js/utils";
import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "@/common/js/constants"; import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "@/common/js/constants";
export default { export default {
@ -43,7 +43,7 @@ export default {
items: [], items: [],
search_text: '', search_text: '',
userId: getCurrentUser().id, userId: getCurrentUser().id,
projectId: localStorage.getItem(PROJECT_ID) currentProjectId: localStorage.getItem(PROJECT_ID)
} }
}, },
watch: { watch: {
@ -61,6 +61,9 @@ export default {
this.result = this.$get(this.options.url, (response) => { this.result = this.$get(this.options.url, (response) => {
this.items = response.data; this.items = response.data;
this.items = this.items.splice(0, 3); this.items = this.items.splice(0, 3);
if (!getCurrentProjectID() && this.items.length > 0) {
this.change(this.items[0].id);
}
}); });
} }
}, },
@ -72,7 +75,6 @@ export default {
} }
}, },
change(projectId) { change(projectId) {
// todo
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);
window.location.reload(); window.location.reload();

View File

@ -96,6 +96,7 @@ 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);
// 保存角色 // 保存角色