最近的项目

This commit is contained in:
Captain.B 2020-02-26 13:30:50 +08:00
parent 3923aca94f
commit 32df172547
7 changed files with 50 additions and 22 deletions

View File

@ -9,6 +9,7 @@ import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.ProjectRequest; import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.service.ProjectService; import io.metersphere.service.ProjectService;
import io.metersphere.user.SessionUtils; import io.metersphere.user.SessionUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -29,6 +30,17 @@ public class ProjectController {
return projectService.getProjectList(request); return projectService.getProjectList(request);
} }
@GetMapping("/recent/{count}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public List<Project> recentProjects(@PathVariable int count) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
ProjectRequest request = new ProjectRequest();
request.setWorkspaceId(currentWorkspaceId);
// 最近 `count` 个项目
PageHelper.startPage(1, count);
return projectService.getRecentProjectList(request);
}
@PostMapping("/add") @PostMapping("/add")
@RequiresRoles(RoleConstants.TEST_MANAGER) @RequiresRoles(RoleConstants.TEST_MANAGER)
public Project addProject(@RequestBody Project project) { public Project addProject(@RequestBody Project project) {

View File

@ -63,4 +63,15 @@ public class ProjectService {
public List<Project> listAll() { public List<Project> listAll() {
return projectMapper.selectByExample(null); return projectMapper.selectByExample(null);
} }
public List<Project> getRecentProjectList(ProjectRequest request) {
ProjectExample example = new ProjectExample();
ProjectExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotBlank(request.getWorkspaceId())) {
criteria.andWorkspaceIdEqualTo(request.getWorkspaceId());
}
// 按照修改时间排序
example.setOrderByClause("update_time desc");
return projectMapper.selectByExample(example);
}
} }

View File

@ -18,6 +18,9 @@ const en_US = {
'input_name_2_50': '2 to 50 characters in length', 'input_name_2_50': '2 to 50 characters in length',
'search_by_name': 'Search by name', 'search_by_name': 'Search by name',
}, },
project: {
'recent': 'Recent Projects'
},
i18n: { i18n: {
'home': 'Home', 'home': 'Home',
} }

View File

@ -18,6 +18,9 @@ const zh_CN = {
'input_name_2_50': '长度在 2 到 50 个字符', 'input_name_2_50': '长度在 2 到 50 个字符',
'search_by_name': '根据名称搜索', 'search_by_name': '根据名称搜索',
}, },
project: {
'recent': '最近的项目'
},
i18n: { i18n: {
'home': '首页', 'home': '首页',
} }

View File

@ -2,10 +2,10 @@
<div> <div>
<div class="recent-text"> <div class="recent-text">
<i class="el-icon-time"/> <i class="el-icon-time"/>
最近的项目 {{$t('project.recent')}}
</div> </div>
<el-menu-item v-bind:key="recentTestPlan.id" v-for="recentTestPlan in recentTestPlans"> <el-menu-item :key="recentProject.id" v-for="recentProject in recentProjects" @click="goTest(recentProject)">
{{ recentTestPlan.name }} {{ recentProject.name }}
</el-menu-item> </el-menu-item>
</div> </div>
</template> </template>
@ -13,26 +13,20 @@
<script> <script>
export default { export default {
name: "RecentProject", name: "RecentProject",
mounted() {
this.$get('/project/recent/5', (response) => {
this.recentProjects = response.data;
});
},
methods: {
goTest(project) {
window.console.log(project);
// this.$router.push({path: '/allTest', params: {projectId: project.id, projectName: project.name}});
}
},
data() { data() {
return { return {
recentTestPlans: [ recentProjects: [],
{
id: 1,
name: "项目1"
},
{
id: 2,
name: "项目2"
},
{
id: 3,
name: "项目3"
},
{
id: 4,
name: "项目4"
}
]
} }
} }
} }

View File

@ -86,7 +86,8 @@ const router = new VueRouter({
path: "/allTest", path: "/allTest",
components: { components: {
content: AllTestPlan content: AllTestPlan
} },
props: true,
}, },
{ {
path: "/project", path: "/project",

View File

@ -80,6 +80,10 @@
<script> <script>
export default { export default {
props: {
projectId: String,
projectName: String
},
data() { data() {
return { return {
result: {}, result: {},