报告菜单 0.1

This commit is contained in:
Captain.B 2020-03-02 15:11:05 +08:00
parent 761dea73aa
commit 0714200b5f
5 changed files with 121 additions and 4 deletions

View File

@ -0,0 +1,36 @@
package io.metersphere.controller;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.LoadTestReport;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.controller.request.ReportRequest;
import io.metersphere.service.ReportService;
import io.metersphere.user.SessionUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping(value = "report")
public class ReportController {
@Resource
private ReportService reportService;
@GetMapping("/recent/{count}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public List<LoadTestReport> recentProjects(@PathVariable int count) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
ReportRequest request = new ReportRequest();
request.setWorkspaceId(currentWorkspaceId);
// 最近 `count` 个项目
PageHelper.startPage(1, count);
return reportService.getRecentReportList(request);
}
}

View File

@ -0,0 +1,13 @@
package io.metersphere.controller.request;
public class ReportRequest {
private String workspaceId;
public String getWorkspaceId() {
return workspaceId;
}
public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId;
}
}

View File

@ -0,0 +1,28 @@
package io.metersphere.service;
import io.metersphere.base.domain.LoadTestReport;
import io.metersphere.base.domain.LoadTestReportExample;
import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.controller.request.ReportRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class ReportService {
@Resource
private LoadTestReportMapper loadTestReportMapper;
public List<LoadTestReport> getRecentReportList(ReportRequest request) {
LoadTestReportExample example = new LoadTestReportExample();
LoadTestReportExample.Criteria criteria = example.createCriteria();
//
example.setOrderByClause("update_time desc");
return loadTestReportMapper.selectByExample(example);
}
}

View File

@ -30,9 +30,12 @@
</el-submenu>
<el-submenu index="5" popper-class="submenu" v-permission="['test_manager', 'test_user', 'test_viewer']">
<template slot="title">报告</template>
<el-menu-item index="5-1">报告1</el-menu-item>
<el-menu-item index="5-2">报告2</el-menu-item>
<el-menu-item index="5-3">显示全部</el-menu-item>
<ms-recent-report/>
<el-divider/>
<el-menu-item index="/report/all">
<font-awesome-icon :icon="['fa', 'list-ul']"/>
<span style="padding-left: 5px;">显示全部</span>
</el-menu-item>
</el-submenu>
</el-menu>
</template>
@ -40,10 +43,11 @@
<script>
import MsRecentTestPlan from "./testPlan/RecentTestPlan";
import MsRecentProject from "./project/RecentProject";
import MsRecentReport from "./report/RecentReport";
export default {
name: "MsMenus",
components: {MsRecentTestPlan, MsRecentProject}
components: {MsRecentReport, MsRecentTestPlan, MsRecentProject}
}
</script>

View File

@ -0,0 +1,36 @@
<template>
<el-menu router menu-trigger="click" :default-active="$route.path">
<el-menu-item :key="p.id" v-for="p in recentReports"
:index="'/report/' + p.id" :route="{name:'report', params:{projectId:p.id, projectName:p.name}}">
{{ p.name }}
</el-menu-item>
</el-menu>
</template>
<script>
import {ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "../../../common/constants";
export default {
name: "MsRecentReport",
mounted() {
const rolesString = localStorage.getItem("roles");
const roles = rolesString.split(',');
if (roles.indexOf(ROLE_TEST_MANAGER) > -1 || roles.indexOf(ROLE_TEST_USER) > -1 || roles.indexOf(ROLE_TEST_VIEWER) > -1) {
this.$get('/report/recent/5', (response) => {
this.recentReports = response.data;
});
}
},
methods: {},
data() {
return {
recentReports: [],
}
}
}
</script>
<style scoped>
</style>