diff --git a/backend/src/main/java/io/metersphere/controller/ProjectController.java b/backend/src/main/java/io/metersphere/controller/ProjectController.java index 9daf139dcc..fa67a7de67 100644 --- a/backend/src/main/java/io/metersphere/controller/ProjectController.java +++ b/backend/src/main/java/io/metersphere/controller/ProjectController.java @@ -9,6 +9,7 @@ import io.metersphere.commons.utils.Pager; import io.metersphere.controller.request.ProjectRequest; import io.metersphere.service.ProjectService; 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.*; @@ -29,6 +30,17 @@ public class ProjectController { return projectService.getProjectList(request); } + @GetMapping("/recent/{count}") + @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) + public List 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") @RequiresRoles(RoleConstants.TEST_MANAGER) public Project addProject(@RequestBody Project project) { diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index b9fce1d079..4cfe911cec 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -63,4 +63,15 @@ public class ProjectService { public List listAll() { return projectMapper.selectByExample(null); } + + public List 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); + } } diff --git a/frontend/src/i18n/en_US.js b/frontend/src/i18n/en_US.js index 3992d2caf5..a4578177cb 100644 --- a/frontend/src/i18n/en_US.js +++ b/frontend/src/i18n/en_US.js @@ -18,6 +18,9 @@ const en_US = { 'input_name_2_50': '2 to 50 characters in length', 'search_by_name': 'Search by name', }, + project: { + 'recent': 'Recent Projects' + }, i18n: { 'home': 'Home', } diff --git a/frontend/src/i18n/zh_CN.js b/frontend/src/i18n/zh_CN.js index ccb94cac38..ea742402e0 100644 --- a/frontend/src/i18n/zh_CN.js +++ b/frontend/src/i18n/zh_CN.js @@ -18,6 +18,9 @@ const zh_CN = { 'input_name_2_50': '长度在 2 到 50 个字符', 'search_by_name': '根据名称搜索', }, + project: { + 'recent': '最近的项目' + }, i18n: { 'home': '首页', } diff --git a/frontend/src/performance/components/project/RecentProject.vue b/frontend/src/performance/components/project/RecentProject.vue index 13f9b456a6..ecf04f1885 100644 --- a/frontend/src/performance/components/project/RecentProject.vue +++ b/frontend/src/performance/components/project/RecentProject.vue @@ -2,10 +2,10 @@
- 最近的项目 + {{$t('project.recent')}}
- - {{ recentTestPlan.name }} + + {{ recentProject.name }}
@@ -13,26 +13,20 @@