子页面激活菜单栏

This commit is contained in:
chenjianxing 2020-04-08 15:42:06 +08:00
parent 2364fac57b
commit 11956de1ea
10 changed files with 165 additions and 43 deletions

View File

@ -2,10 +2,7 @@ package io.metersphere.controller;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.LoadTest; import io.metersphere.base.domain.*;
import io.metersphere.base.domain.TestCase;
import io.metersphere.base.domain.TestCaseNode;
import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.testcase.QueryTestCaseRequest; import io.metersphere.controller.request.testcase.QueryTestCaseRequest;
@ -39,8 +36,7 @@ public class TestCaseController {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId(); String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
QueryTestCaseRequest request = new QueryTestCaseRequest(); QueryTestCaseRequest request = new QueryTestCaseRequest();
request.setWorkspaceId(currentWorkspaceId); request.setWorkspaceId(currentWorkspaceId);
PageHelper.startPage(1, count, true); return testCaseService.recentTestPlans(request, count);
return testCaseService.recentTestPlans(request);
} }
@PostMapping("/list") @PostMapping("/list")
@ -58,6 +54,11 @@ public class TestCaseController {
return testCaseService.getTestCase(testCaseId); return testCaseService.getTestCase(testCaseId);
} }
@GetMapping("/project/{testCaseId}")
public Project getProjectByTestCaseId(@PathVariable String testCaseId){
return testCaseService.getProjectByTestCaseId(testCaseId);
}
@PostMapping("/add") @PostMapping("/add")
public void addTestCase(@RequestBody TestCaseWithBLOBs testCase){ public void addTestCase(@RequestBody TestCaseWithBLOBs testCase){
testCaseService.addTestCase(testCase); testCaseService.addTestCase(testCase);

View File

@ -1,6 +1,7 @@
package io.metersphere.service; package io.metersphere.service;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.TestCaseMapper; import io.metersphere.base.mapper.TestCaseMapper;
@ -114,7 +115,7 @@ public class TestCaseService {
} }
public List<TestCase> recentTestPlans(QueryTestCaseRequest request) { public List<TestCase> recentTestPlans(QueryTestCaseRequest request, int count) {
if (StringUtils.isBlank(request.getWorkspaceId())) { if (StringUtils.isBlank(request.getWorkspaceId())) {
return null; return null;
@ -126,9 +127,19 @@ public class TestCaseService {
List<String> projectIds = projectMapper.selectByExample(projectExample).stream() List<String> projectIds = projectMapper.selectByExample(projectExample).stream()
.map(Project::getId).collect(Collectors.toList()); .map(Project::getId).collect(Collectors.toList());
PageHelper.startPage(1, count, true);
TestCaseExample testCaseExample = new TestCaseExample(); TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andProjectIdIn(projectIds); testCaseExample.createCriteria().andProjectIdIn(projectIds);
testCaseExample.setOrderByClause("update_time desc"); testCaseExample.setOrderByClause("update_time desc");
return testCaseMapper.selectByExample(testCaseExample); return testCaseMapper.selectByExample(testCaseExample);
} }
public Project getProjectByTestCaseId(String testCaseId) {
TestCaseWithBLOBs testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCaseId);
if (testCaseWithBLOBs == null) {
return null;
}
return projectMapper.selectByPrimaryKey(testCaseWithBLOBs.getProjectId());
}
} }

View File

@ -1,6 +1,6 @@
<template> <template>
<el-col> <el-col>
<header-menus/> <api-header-menus/>
<div> <div>
<transition> <transition>
<keep-alive> <keep-alive>
@ -12,11 +12,11 @@
</template> </template>
<script> <script>
import HeaderMenus from "./head/HeaderMenus"; import ApiHeaderMenus from "./head/ApiHeaderMenus";
export default { export default {
name: "ApiTest", name: "ApiTest",
components: {HeaderMenus}, components: {ApiHeaderMenus},
data() { data() {
return { return {
beaseUrl: "api" beaseUrl: "api"

View File

@ -1,6 +1,6 @@
<template> <template>
<div id="menu-bar"> <div id="menu-bar" v-if="isRouterAlive">
<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-menu-item :index="'/api/home'"> <el-menu-item :index="'/api/home'">
@ -24,7 +24,7 @@
<el-submenu v-if="isCurrentWorkspaceUser" <el-submenu v-if="isCurrentWorkspaceUser"
index="4" popper-class="submenu" v-permission="['test_manager', 'test_user']"> index="4" popper-class="submenu" v-permission="['test_manager', 'test_user']">
<template v-slot:title>{{$t('commons.test')}}</template> <template v-slot:title>{{$t('commons.test')}}</template>
<api-recent-test-plan/> <api-recent-test/>
<el-divider/> <el-divider/>
<el-menu-item :index="'/api/test/all'"> <el-menu-item :index="'/api/test/all'">
<font-awesome-icon :icon="['fa', 'list-ul']"/> <font-awesome-icon :icon="['fa', 'list-ul']"/>
@ -33,6 +33,8 @@
<el-menu-item :index="'/api/test/create'"> <el-menu-item :index="'/api/test/create'">
<el-button type="text">{{$t('load_test.create')}}</el-button> <el-button type="text">{{$t('load_test.create')}}</el-button>
</el-menu-item> </el-menu-item>
<el-menu-item :index="testCaseProjectPath" class="blank_item"></el-menu-item>
<el-menu-item :index="testEditPath" class="blank_item"></el-menu-item>
</el-submenu> </el-submenu>
<el-submenu v-if="isCurrentWorkspaceUser" <el-submenu v-if="isCurrentWorkspaceUser"
@ -44,6 +46,7 @@
<font-awesome-icon :icon="['fa', 'list-ul']"/> <font-awesome-icon :icon="['fa', 'list-ul']"/>
<span style="padding-left: 5px;">{{$t('commons.show_all')}}</span> <span style="padding-left: 5px;">{{$t('commons.show_all')}}</span>
</el-menu-item> </el-menu-item>
<el-menu-item :index="reportViewPath" class="blank_item"></el-menu-item>
</el-submenu> </el-submenu>
<router-link v-if="isCurrentWorkspaceUser" <router-link v-if="isCurrentWorkspaceUser"
@ -64,15 +67,45 @@
import {checkoutCurrentWorkspace} from "../../../../common/utils"; import {checkoutCurrentWorkspace} from "../../../../common/utils";
export default { export default {
name: "MsMenus", name: "ApiHeaderMenus",
components: {ApiRecentTest, ApiRecentReport, ApiRecentProject}, components: {ApiRecentTest, ApiRecentReport, ApiRecentProject},
data() { data() {
return { return {
isCurrentWorkspaceUser: false, isCurrentWorkspaceUser: false,
testCaseProjectPath: '',
testEditPath: '',
reportViewPath: '',
isRouterAlive: true
}
},
watch: {
'$route'(to, from) {
let path = to.path;
//
if (path.indexOf("/api/test/") >= 0){
this.testCaseProjectPath = '/api/test/' + this.$route.params.projectId;
this.reload();
}
if (path.indexOf("/api/test/edit/") >= 0){
this.testEditPath = '/api/test/edit/' + this.$route.params.testId;
this.reload();
}
if (path.indexOf("/api/report/view/") >= 0){
this.reportViewPath = '/api/report/view/' + this.$route.params.reportId;
this.reload();
}
} }
}, },
mounted() { mounted() {
this.isCurrentWorkspaceUser = checkoutCurrentWorkspace(); this.isCurrentWorkspaceUser = checkoutCurrentWorkspace();
},
methods: {
reload () {
this.isRouterAlive = false;
this.$nextTick(function () {
this.isRouterAlive = true;
})
}
} }
} }
@ -106,4 +139,9 @@
#menu-bar { #menu-bar {
border-bottom: 1px solid #E6E6E6; border-bottom: 1px solid #E6E6E6;
} }
.blank_item {
display: none;
}
</style> </style>

View File

@ -1,6 +1,6 @@
<template> <template>
<el-col> <el-col>
<header-menus/> <performance-header-menus/>
<div> <div>
<transition> <transition>
<keep-alive> <keep-alive>
@ -13,11 +13,11 @@
<script> <script>
import HeaderMenus from "./head/HeaderMenus"; import PerformanceHeaderMenus from "./head/PerformanceHeaderMenus";
export default { export default {
name: "PerformanceTest", name: "PerformanceTest",
components: {HeaderMenus}, components: {PerformanceHeaderMenus},
data() { data() {
return { return {
beaseUrl: "performance" beaseUrl: "performance"

View File

@ -1,6 +1,6 @@
<template> <template>
<div id="menu-bar"> <div id="menu-bar" v-if="isRouterAlive">
<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-menu-item :index="'/performance/home'"> <el-menu-item :index="'/performance/home'">
@ -33,6 +33,8 @@
<el-menu-item :index="'/performance/test/create'"> <el-menu-item :index="'/performance/test/create'">
<el-button type="text">{{$t('load_test.create')}}</el-button> <el-button type="text">{{$t('load_test.create')}}</el-button>
</el-menu-item> </el-menu-item>
<el-menu-item :index="testCaseProjectPath" class="blank_item"></el-menu-item>
<el-menu-item :index="testEditPath" class="blank_item"></el-menu-item>
</el-submenu> </el-submenu>
<el-submenu v-if="isCurrentWorkspaceUser" <el-submenu v-if="isCurrentWorkspaceUser"
@ -44,6 +46,7 @@
<font-awesome-icon :icon="['fa', 'list-ul']"/> <font-awesome-icon :icon="['fa', 'list-ul']"/>
<span style="padding-left: 5px;">{{$t('commons.show_all')}}</span> <span style="padding-left: 5px;">{{$t('commons.show_all')}}</span>
</el-menu-item> </el-menu-item>
<el-menu-item :index="reportViewPath" class="blank_item"></el-menu-item>
</el-submenu> </el-submenu>
<router-link v-if="isCurrentWorkspaceUser" <router-link v-if="isCurrentWorkspaceUser"
@ -64,20 +67,45 @@
import {checkoutCurrentWorkspace} from "../../../../common/utils"; import {checkoutCurrentWorkspace} from "../../../../common/utils";
export default { export default {
name: "MsMenus", name: "PerformanceHeaderMenus",
components: {PerformanceRecentReport, PerformanceRecentTestPlan, PerformanceRecentProject}, components: {PerformanceRecentReport, PerformanceRecentTestPlan, PerformanceRecentProject},
data() { data() {
return { return {
isCurrentWorkspaceUser: false, isCurrentWorkspaceUser: false,
testCaseProjectPath: '',
testEditPath: '',
reportViewPath: '',
isRouterAlive: true
} }
}, },
props: {
beaseUrl: {
type: String
}
},
mounted() { mounted() {
this.isCurrentWorkspaceUser = checkoutCurrentWorkspace(); this.isCurrentWorkspaceUser = checkoutCurrentWorkspace();
},
watch: {
'$route'(to, from) {
let path = to.path;
//
if (path.indexOf("/performance/test/") >= 0){
this.testCaseProjectPath = '/performance/test/' + this.$route.params.projectId;
this.reload();
}
if (path.indexOf("/performance/test/edit/") >= 0){
this.testEditPath = '/performance/test/edit/' + this.$route.params.testId;
this.reload();
}
if (path.indexOf("/performance/report/view/") >= 0){
this.reportViewPath = '/performance/report/view/' + this.$route.params.reportId;
this.reload();
}
}
},
methods: {
reload () {
this.isRouterAlive = false;
this.$nextTick(function () {
this.isRouterAlive = true;
})
}
} }
} }
@ -111,4 +139,8 @@
#menu-bar { #menu-bar {
border-bottom: 1px solid #E6E6E6; border-bottom: 1px solid #E6E6E6;
} }
.blank_item {
display: none;
}
</style> </style>

View File

@ -1,6 +1,6 @@
<template> <template>
<el-col> <el-col>
<header-menus/> <track-header-menus/>
<div> <div>
<transition> <transition>
<keep-alive> <keep-alive>
@ -13,11 +13,11 @@
<script> <script>
import HeaderMenus from "./head/HeaderMenus"; import TrackHeaderMenus from "./head/TrackHeaderMenus";
export default { export default {
name: "TrackHome", name: "TrackHome",
components: {HeaderMenus}, components: {TrackHeaderMenus},
data() { data() {
return { return {
beaseUrl: "track" beaseUrl: "track"

View File

@ -72,23 +72,22 @@
treeNodes: [] treeNodes: []
} }
}, },
created: function () { created() {
this.caseId = this.$route.params.caseId;
this.getProjects(); this.getProjects();
}, },
mounted() {
if (this.$route.path.indexOf("/track/case/edit") >= 0){
this.openRecentTestCaseEditDialog();
}
},
watch: { watch: {
'$route'(to, from) { '$route'(to, from) {
let path = to.path; let path = to.path;
if (path.indexOf("/track/case/all") >= 0){ if (path.indexOf("/track/case/all") >= 0){
this.getProjects();
this.refresh(); this.refresh();
} }
if (path.indexOf("/track/case/edit") >= 0){ if (path.indexOf("/track/case/edit") >= 0){
let caseId = this.$route.params.caseId; this.openRecentTestCaseEditDialog();
this.$get('/test/case/get/' + caseId, response => {
console.log(response.data);
this.openTestCaseEditDialog(response.data[0]);
});
} }
} }
}, },
@ -164,9 +163,24 @@
this.$refs.testCaseEditDialog.maintainerOptions = response.data; this.$refs.testCaseEditDialog.maintainerOptions = response.data;
}); });
}, },
getProjectByCaseId(caseId) {
return this.$get('/test/case/project/' + caseId, async response => {
localStorage.setItem(CURRENT_PROJECT, JSON.stringify(response.data));
this.refresh();
});
},
refresh() { refresh() {
this.$refs.testCaseList.initTableData(); this.$refs.testCaseList.initTableData();
this.$refs.nodeTree.getNodeTree(); this.$refs.nodeTree.getNodeTree();
this.getProjects();
},
openRecentTestCaseEditDialog() {
let caseId = this.$route.params.caseId;
this.getProjectByCaseId(caseId);
this.refresh();
this.$get('/test/case/get/' + caseId, response => {
this.openTestCaseEditDialog(response.data[0]);
});
} }
} }
} }

View File

@ -140,7 +140,6 @@
} }
}, },
created: function () { created: function () {
this.initTableData(); this.initTableData();
}, },
methods: { methods: {

View File

@ -1,6 +1,6 @@
<template> <template>
<div id="menu-bar"> <div id="menu-bar" v-if="isRouterAlive">
<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-menu-item :index="'/track/home'"> <el-menu-item :index="'/track/home'">
@ -30,6 +30,7 @@
<font-awesome-icon :icon="['fa', 'list-ul']"/> <font-awesome-icon :icon="['fa', 'list-ul']"/>
<span style="padding-left: 5px;">{{$t('test_track.case_list')}}</span> <span style="padding-left: 5px;">{{$t('test_track.case_list')}}</span>
</el-menu-item> </el-menu-item>
<el-menu-item :index="testCaseEditPath" class="blank_item"></el-menu-item>
<!--<el-menu-item :index="'/' + beaseUrl + '/case/create'">--> <!--<el-menu-item :index="'/' + beaseUrl + '/case/create'">-->
<!--<el-button type="text">{{$t('test_track.create_case')}}</el-button>--> <!--<el-button type="text">{{$t('test_track.create_case')}}</el-button>-->
<!--</el-menu-item>--> <!--</el-menu-item>-->
@ -40,11 +41,12 @@
<template v-slot:title>{{$t('test_track.test_plan')}}</template> <template v-slot:title>{{$t('test_track.test_plan')}}</template>
<recent-test-plan/> <recent-test-plan/>
<el-divider/> <el-divider/>
<el-menu-item :index="'/track/plan/all'"> <el-menu-item index="/track/plan/all">
<font-awesome-icon :icon="['fa', 'list-ul']"/> <font-awesome-icon :icon="['fa', 'list-ul']"/>
<span style="padding-left: 5px;">{{$t('commons.show_all')}}</span> <span style="padding-left: 5px;">{{$t('commons.show_all')}}</span>
</el-menu-item> </el-menu-item>
<el-menu-item :index="'/track/plan/create'"> <el-menu-item :index="testPlanViewPath" class="blank_item"></el-menu-item>
<el-menu-item index="/track/plan/create">
<el-button type="text">{{$t('test_track.create_plan')}}</el-button> <el-button type="text">{{$t('test_track.create_plan')}}</el-button>
</el-menu-item> </el-menu-item>
</el-submenu> </el-submenu>
@ -53,7 +55,6 @@
</div> </div>
</template> </template>
<script> <script>
import {checkoutCurrentWorkspace} from "../../../../common/utils"; import {checkoutCurrentWorkspace} from "../../../../common/utils";
@ -62,25 +63,45 @@
import RecentTestPlan from "../plan/components/RecentTestPlan"; import RecentTestPlan from "../plan/components/RecentTestPlan";
export default { export default {
name: "MsMenus", name: "TrackHeaderMenus",
components: {RecentTestCase, TrackRecentProject, RecentTestPlan}, components: {RecentTestCase, TrackRecentProject, RecentTestPlan},
data() { data() {
return { return {
isCurrentWorkspaceUser: false, isCurrentWorkspaceUser: false,
testPlanViewPath: '',
isRouterAlive: true,
testCaseEditPath: ''
} }
}, },
props: { watch: {
beaseUrl: { '$route'(to, from) {
type: String let path = to.path;
if (path.indexOf("/track/plan/view") >= 0){
this.testPlanViewPath = '/track/plan/view/' + this.$route.params.planId;
this.reload();
} }
if (path.indexOf("/track/case/edit") >= 0){
this.testCaseEditPath = '/track/case/edit/' + this.$route.params.caseId;
this.reload();
}
}
}, },
mounted() { mounted() {
this.isCurrentWorkspaceUser = checkoutCurrentWorkspace(); this.isCurrentWorkspaceUser = checkoutCurrentWorkspace();
},
methods: {
reload () {
this.isRouterAlive = false;
this.$nextTick(function () {
this.isRouterAlive = true;
})
}
} }
} }
</script> </script>
<style> <style>
.header-menu.el-menu--horizontal > li { .header-menu.el-menu--horizontal > li {
@ -100,6 +121,8 @@
margin-left: 20%; margin-left: 20%;
} }
</style> </style>
<style scoped> <style scoped>
@ -109,4 +132,8 @@
#menu-bar { #menu-bar {
border-bottom: 1px solid #E6E6E6; border-bottom: 1px solid #E6E6E6;
} }
.blank_item {
display: none;
}
</style> </style>