feat: 切换项目

This commit is contained in:
shiziyuan9527 2020-12-10 10:45:22 +08:00
parent 1f59d12f7b
commit 4f1f1c85d9
5 changed files with 40 additions and 19 deletions

View File

@ -12,7 +12,7 @@
</span>
</div>
<div v-else style="height: 120px;overflow: auto">
<el-menu-item :key="i.id" v-for="i in items" :index="getIndex(i)" :route="getRouter(i)">
<el-menu-item :key="i.id" v-for="i in items" @click="change(i.id)">
<template slot="title">
<div class="title">{{ i.name }}</div>
</template>
@ -23,8 +23,8 @@
</template>
<script>
import {hasRoles} from "@/common/js/utils";
import {ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "@/common/js/constants";
import {getCurrentUser, hasRoles} from "@/common/js/utils";
import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "@/common/js/constants";
export default {
name: "SearchList",
@ -32,13 +32,18 @@ export default {
options: Object
},
mounted() {
console.log('mounted')
this.init();
},
beforeDestroy() {
console.log('beforeDestroy')
},
data() {
return {
result: {},
items: [],
search_text: ''
search_text: '',
userId: getCurrentUser().id,
}
},
watch: {
@ -51,18 +56,18 @@ export default {
}
},
computed: {
getIndex: function () {
return function (item) {
return this.options.index(item);
}
},
getRouter: function () {
return function (item) {
if (this.options.router) {
return this.options.router(item);
}
}
}
// getIndex: function () {
// return function (item) {
// return this.options.index(item);
// }
// },
// getRouter: function () {
// return function (item) {
// if (this.options.router) {
// return this.options.router(item);
// }
// }
// }
},
methods: {
@ -80,6 +85,13 @@ export default {
this.items = response.data;
})
}
},
change(projectId) {
// todo
this.$post("/user/update/current", {id: this.userId, lastProjectId: projectId}, () => {
localStorage.setItem(PROJECT_ID, projectId);
window.location.reload();
});
}
}
}

View File

@ -1,5 +1,5 @@
<template>
<el-menu-item :index="this.index">
<el-menu-item :index="this.index" @click="changeRoute">
<font-awesome-icon :icon="['fa', 'list-ul']"/>
<span>{{ $t('commons.show_all') }}</span>
</el-menu-item>
@ -10,6 +10,14 @@ export default {
name: "MsShowAll",
props: {
index: String
},
methods: {
changeRoute() {
//
if (this.$route.path === this.index) {
this.$router.replace({path: this.index, query: {type: 'all'}});
}
}
}
}
</script>

@ -1 +1 @@
Subproject commit 8a972a198775b3783ed6e4cef27197e53d1ebdc8
Subproject commit a22a3005d9bd254793fcf634d72539cbdf31be3a

View File

@ -10,6 +10,7 @@ export const ROLE_TEST_VIEWER = 'test_viewer';
export const WORKSPACE_ID = 'workspace_id';
export const CURRENT_PROJECT = 'current_project';
export const PROJECT_ID = 'project_id';
export const REFRESH_SESSION_USER_URL = 'user/refresh';
export const WORKSPACE = 'workspace';

View File

@ -279,7 +279,7 @@ export default {
verified: '验证通过'
}
},
edit: {
project: {
recent: '最近的项目',
create: '创建项目',
edit: '编辑项目',