feat: 切换项目后显示项目名
This commit is contained in:
parent
6672c7756e
commit
3af1825a26
|
@ -6,8 +6,12 @@
|
|||
|
||||
<el-submenu :class="{'deactivation':!isProjectActivation}"
|
||||
v-permission="['test_manager','test_user','test_viewer']" index="3">
|
||||
<template v-slot:title>{{ $t('commons.project') }}</template>
|
||||
<search-list ref="projectRecent" :options="projectRecent"/>
|
||||
<template v-slot:title>
|
||||
<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-menu-item :index="'/setting/project/create'">
|
||||
<font-awesome-icon :icon="['fa', 'plus']"/>
|
||||
|
@ -108,6 +112,7 @@ export default {
|
|||
isProjectActivation: true,
|
||||
isRouterAlive: true,
|
||||
apiTestProjectPath: '',
|
||||
currentProject: ''
|
||||
}
|
||||
},
|
||||
// watch: {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div v-loading="result.loading" class="search-list">
|
||||
<el-input placeholder="搜索项目"
|
||||
prefix-icon="el-icon-search"
|
||||
v-model="search_text"
|
||||
v-model="searchString"
|
||||
clearable
|
||||
class="search-input"
|
||||
size="small"/>
|
||||
|
@ -16,8 +16,8 @@
|
|||
<template slot="title">
|
||||
<div class="title">
|
||||
{{ i.name }}
|
||||
<i class="el-icon-check" v-if="i.id === currentProjectId"></i>
|
||||
</div>
|
||||
<i class="el-icon-check" v-if="i.id === currentProjectId"></i>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
</div>
|
||||
|
@ -32,7 +32,8 @@ import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "@
|
|||
export default {
|
||||
name: "SearchList",
|
||||
props: {
|
||||
options: Object
|
||||
options: Object,
|
||||
currentProject: String
|
||||
},
|
||||
mounted() {
|
||||
this.init();
|
||||
|
@ -41,44 +42,68 @@ export default {
|
|||
return {
|
||||
result: {},
|
||||
items: [],
|
||||
search_text: '',
|
||||
searchArray: [],
|
||||
searchString: '',
|
||||
userId: getCurrentUser().id,
|
||||
currentProjectId: localStorage.getItem(PROJECT_ID)
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
search_text(val) {
|
||||
if (!val) {
|
||||
this.init();
|
||||
} else {
|
||||
this.search();
|
||||
}
|
||||
searchString(val) {
|
||||
this.query(val)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init: function () {
|
||||
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 = this.items.splice(0, 3);
|
||||
this.searchArray = response.data;
|
||||
if (!getCurrentProjectID() && this.items.length > 0) {
|
||||
this.change(this.items[0].id);
|
||||
}
|
||||
});
|
||||
let projectId = getCurrentProjectID();
|
||||
this.changeProjectName(projectId);
|
||||
})
|
||||
}
|
||||
},
|
||||
search() {
|
||||
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;
|
||||
})
|
||||
}
|
||||
},
|
||||
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) {
|
||||
this.$post("/user/update/current", {id: this.userId, lastProjectId: projectId}, () => {
|
||||
localStorage.setItem(PROJECT_ID, projectId);
|
||||
window.location.reload();
|
||||
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();
|
||||
}
|
||||
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", '选择项目');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
<template>
|
||||
<div id="menu-bar">
|
||||
<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-submenu v-permission="['test_manager','test_user','test_viewer']"
|
||||
index="3" popper-class="submenu">
|
||||
<template v-slot:title>{{ $t('commons.project') }}</template>
|
||||
<search-list ref="projectRecent" :options="projectRecent"/>
|
||||
<template v-slot:title>
|
||||
<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-menu-item :index="'/setting/project/create'">
|
||||
<font-awesome-icon :icon="['fa', 'plus']"/>
|
||||
|
@ -39,12 +43,12 @@
|
|||
</el-submenu>
|
||||
</el-menu>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-col :span="4" >
|
||||
<el-row type="flex" justify="center">
|
||||
<ms-create-test :to="'/performance/test/create'"/>
|
||||
</el-row>
|
||||
</el-col>
|
||||
<el-col :span="8"/>
|
||||
<el-col :span="10"/>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -98,7 +102,7 @@ export default {
|
|||
router(item) {
|
||||
}
|
||||
},
|
||||
input2: ''
|
||||
currentProject: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
<div id="menu-bar" v-if="isRouterAlive">
|
||||
<el-row type="flex">
|
||||
<el-col :span="12">
|
||||
<el-col :span="16">
|
||||
<el-menu class="header-menu" :unique-opened="true" mode="horizontal" router
|
||||
:default-active='$route.path'>
|
||||
<el-submenu :class="{'deactivation':!isProjectActivation}"
|
||||
v-permission="['test_manager','test_user','test_viewer']" index="3" popper-class="submenu">
|
||||
<template v-slot:title>{{ $t('commons.project') }}</template>
|
||||
<search-list ref="projectRecent" :options="projectRecent"/>
|
||||
<template v-slot:title>
|
||||
<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-menu-item :index="'/setting/project/create'">
|
||||
<font-awesome-icon :icon="['fa', 'plus']"/>
|
||||
|
@ -54,7 +58,7 @@
|
|||
</el-submenu>
|
||||
</el-menu>
|
||||
</el-col>
|
||||
<el-col :span="12"/>
|
||||
<el-col :span="8"/>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
|
@ -78,6 +82,7 @@ export default {
|
|||
testCaseReviewEditPath: '',
|
||||
testCaseProjectPath: '',
|
||||
isProjectActivation: true,
|
||||
currentProject: '',
|
||||
projectRecent: {
|
||||
title: this.$t('project.recent'),
|
||||
url: "/project/recent/5",
|
||||
|
|
Loading…
Reference in New Issue