feat: 切换项目后显示项目名

This commit is contained in:
shiziyuan9527 2020-12-14 16:17:45 +08:00
parent 6672c7756e
commit 3af1825a26
4 changed files with 66 additions and 27 deletions

View File

@ -6,8 +6,12 @@
<el-submenu :class="{'deactivation':!isProjectActivation}" <el-submenu :class="{'deactivation':!isProjectActivation}"
v-permission="['test_manager','test_user','test_viewer']" index="3"> v-permission="['test_manager','test_user','test_viewer']" index="3">
<template v-slot:title>{{ $t('commons.project') }}</template> <template v-slot:title>
<search-list ref="projectRecent" :options="projectRecent"/> <span style="display: inline-block;width: 150px;white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" :title="currentProject">
{{ $t('commons.project') }}: {{currentProject}}
</span>
</template>
<search-list ref="projectRecent" :options="projectRecent" :current-project.sync="currentProject"/>
<el-divider class="menu-divider"/> <el-divider class="menu-divider"/>
<el-menu-item :index="'/setting/project/create'"> <el-menu-item :index="'/setting/project/create'">
<font-awesome-icon :icon="['fa', 'plus']"/> <font-awesome-icon :icon="['fa', 'plus']"/>
@ -108,6 +112,7 @@ export default {
isProjectActivation: true, isProjectActivation: true,
isRouterAlive: true, isRouterAlive: true,
apiTestProjectPath: '', apiTestProjectPath: '',
currentProject: ''
} }
}, },
// watch: { // watch: {

View File

@ -2,7 +2,7 @@
<div v-loading="result.loading" class="search-list"> <div v-loading="result.loading" class="search-list">
<el-input placeholder="搜索项目" <el-input placeholder="搜索项目"
prefix-icon="el-icon-search" prefix-icon="el-icon-search"
v-model="search_text" v-model="searchString"
clearable clearable
class="search-input" class="search-input"
size="small"/> size="small"/>
@ -16,8 +16,8 @@
<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 === currentProjectId"></i>
</div> </div>
<i class="el-icon-check" v-if="i.id === currentProjectId"></i>
</template> </template>
</el-menu-item> </el-menu-item>
</div> </div>
@ -32,7 +32,8 @@ import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "@
export default { export default {
name: "SearchList", name: "SearchList",
props: { props: {
options: Object options: Object,
currentProject: String
}, },
mounted() { mounted() {
this.init(); this.init();
@ -41,44 +42,68 @@ export default {
return { return {
result: {}, result: {},
items: [], items: [],
search_text: '', searchArray: [],
searchString: '',
userId: getCurrentUser().id, userId: getCurrentUser().id,
currentProjectId: localStorage.getItem(PROJECT_ID) currentProjectId: localStorage.getItem(PROJECT_ID)
} }
}, },
watch: { watch: {
search_text(val) { searchString(val) {
if (!val) { this.query(val)
this.init();
} else {
this.search();
}
} }
}, },
methods: { methods: {
init: function () { init: function () {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) { if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
this.result = this.$get(this.options.url, (response) => { this.result = this.$get("/project/listAll", response => {
this.items = response.data; this.items = response.data;
this.items = this.items.splice(0, 3); this.searchArray = response.data;
if (!getCurrentProjectID() && this.items.length > 0) { if (!getCurrentProjectID() && this.items.length > 0) {
this.change(this.items[0].id); this.change(this.items[0].id);
} }
}); let projectId = getCurrentProjectID();
this.changeProjectName(projectId);
})
} }
}, },
search() { search() {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) { if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
this.result = this.$post("/project/search", {name: this.search_text},response => { this.result = this.$post("/project/search", {name: this.searchString},response => {
this.items = response.data; this.items = response.data;
}) })
} }
}, },
query(queryString) {
this.items = queryString ? this.searchArray.filter(this.createFilter(queryString)) : this.searchArray;
},
createFilter(queryString) {
return item => {
return (item.name.toLowerCase().indexOf(queryString.toLowerCase()) !== -1);
};
},
change(projectId) { change(projectId) {
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) {
this.$router.replace('/track/review/all');
} else if (this.$route.path.indexOf('/track/plan/view/') >= 0) {
this.$router.replace('/track/plan/all');
} else {
window.location.reload(); window.location.reload();
}
this.changeProjectName(projectId);
}); });
},
changeProjectName(projectId) {
if (projectId) {
let project = this.searchArray.filter(p => p.id === projectId);
if (project.length > 0) {
this.$emit("update:currentProject", project[0].name);
}
} else {
this.$emit("update:currentProject", '选择项目');
}
} }
} }
} }

View File

@ -1,13 +1,17 @@
<template> <template>
<div id="menu-bar"> <div id="menu-bar">
<el-row type="flex"> <el-row type="flex">
<el-col :span="8"> <el-col :span="10">
<el-menu class="header-menu" :unique-opened="true" mode="horizontal" router :default-active='$route.path'> <el-menu class="header-menu" :unique-opened="true" mode="horizontal" router :default-active='$route.path'>
<el-submenu v-permission="['test_manager','test_user','test_viewer']" <el-submenu v-permission="['test_manager','test_user','test_viewer']"
index="3" popper-class="submenu"> index="3" popper-class="submenu">
<template v-slot:title>{{ $t('commons.project') }}</template> <template v-slot:title>
<search-list ref="projectRecent" :options="projectRecent"/> <span style="display: inline-block;width: 150px;white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" :title="currentProject">
{{ $t('commons.project') }}: {{currentProject}}
</span>
</template>
<search-list ref="projectRecent" :options="projectRecent" :current-project.sync="currentProject"/>
<el-divider/> <el-divider/>
<el-menu-item :index="'/setting/project/create'"> <el-menu-item :index="'/setting/project/create'">
<font-awesome-icon :icon="['fa', 'plus']"/> <font-awesome-icon :icon="['fa', 'plus']"/>
@ -39,12 +43,12 @@
</el-submenu> </el-submenu>
</el-menu> </el-menu>
</el-col> </el-col>
<el-col :span="8"> <el-col :span="4" >
<el-row type="flex" justify="center"> <el-row type="flex" justify="center">
<ms-create-test :to="'/performance/test/create'"/> <ms-create-test :to="'/performance/test/create'"/>
</el-row> </el-row>
</el-col> </el-col>
<el-col :span="8"/> <el-col :span="10"/>
</el-row> </el-row>
</div> </div>
</template> </template>
@ -98,7 +102,7 @@ export default {
router(item) { router(item) {
} }
}, },
input2: '' currentProject: ''
} }
}, },
methods: { methods: {

View File

@ -2,13 +2,17 @@
<div id="menu-bar" v-if="isRouterAlive"> <div id="menu-bar" v-if="isRouterAlive">
<el-row type="flex"> <el-row type="flex">
<el-col :span="12"> <el-col :span="16">
<el-menu class="header-menu" :unique-opened="true" mode="horizontal" router <el-menu class="header-menu" :unique-opened="true" mode="horizontal" router
:default-active='$route.path'> :default-active='$route.path'>
<el-submenu :class="{'deactivation':!isProjectActivation}" <el-submenu :class="{'deactivation':!isProjectActivation}"
v-permission="['test_manager','test_user','test_viewer']" index="3" popper-class="submenu"> v-permission="['test_manager','test_user','test_viewer']" index="3" popper-class="submenu">
<template v-slot:title>{{ $t('commons.project') }}</template> <template v-slot:title>
<search-list ref="projectRecent" :options="projectRecent"/> <span style="display: inline-block;width: 150px;white-space:nowrap; overflow:hidden; text-overflow:ellipsis;" :title="currentProject">
{{ $t('commons.project') }}: {{currentProject}}
</span>
</template>
<search-list ref="projectRecent" :options="projectRecent" :current-project.sync="currentProject"/>
<el-divider/> <el-divider/>
<el-menu-item :index="'/setting/project/create'"> <el-menu-item :index="'/setting/project/create'">
<font-awesome-icon :icon="['fa', 'plus']"/> <font-awesome-icon :icon="['fa', 'plus']"/>
@ -54,7 +58,7 @@
</el-submenu> </el-submenu>
</el-menu> </el-menu>
</el-col> </el-col>
<el-col :span="12"/> <el-col :span="8"/>
</el-row> </el-row>
</div> </div>
@ -78,6 +82,7 @@ export default {
testCaseReviewEditPath: '', testCaseReviewEditPath: '',
testCaseProjectPath: '', testCaseProjectPath: '',
isProjectActivation: true, isProjectActivation: true,
currentProject: '',
projectRecent: { projectRecent: {
title: this.$t('project.recent'), title: this.$t('project.recent'),
url: "/project/recent/5", url: "/project/recent/5",