fix(接口测试): 消息中心加载优化增加分页处理

This commit is contained in:
fit2-zhao 2021-11-05 19:14:40 +08:00 committed by fit2-zhao
parent 3213aeddea
commit 8107390b0f
5 changed files with 147 additions and 72 deletions

View File

@ -48,7 +48,7 @@
and t.user_id = #{request.executor} and t.user_id = #{request.executor}
</if> </if>
) )
)tt ORDER BY tt.executionTime DESC; )tt ORDER BY tt.executionTime DESC
</select> </select>
<select id="getCases" resultType="io.metersphere.task.dto.TaskCenterDTO" parameterType="java.lang.String"> <select id="getCases" resultType="io.metersphere.task.dto.TaskCenterDTO" parameterType="java.lang.String">

View File

@ -1,5 +1,9 @@
package io.metersphere.task.controller; package io.metersphere.task.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.task.dto.TaskCenterDTO; import io.metersphere.task.dto.TaskCenterDTO;
import io.metersphere.task.dto.TaskCenterRequest; import io.metersphere.task.dto.TaskCenterRequest;
import io.metersphere.task.service.TaskService; import io.metersphere.task.service.TaskService;
@ -15,10 +19,14 @@ public class TaskController {
@Resource @Resource
private TaskService taskService; private TaskService taskService;
@PostMapping("/list") @PostMapping("/list/{goPage}/{pageSize}")
@RequiresPermissions("PROJECT_API_SCENARIO:READ") @RequiresPermissions("PROJECT_API_SCENARIO:READ")
public List<TaskCenterDTO> getTasks(@RequestBody TaskCenterRequest request) { public Pager<List<TaskCenterDTO>> getTasks(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody TaskCenterRequest request) {
return taskService.getTasks(request); request.setGoPage(goPage);
request.setPageSize(pageSize);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, taskService.getTasks(request));
// return taskService.getTasks(request);
} }
@GetMapping("/case/{id}") @GetMapping("/case/{id}")

View File

@ -18,4 +18,7 @@ public class TaskCenterRequest {
* 执行人 * 执行人
*/ */
private String executor; private String executor;
private int goPage;
private int pageSize;
} }

View File

@ -1,12 +1,13 @@
<template> <template>
<div v-permission="['PROJECT_API_SCENARIO:READ']"> <div v-permission="['PROJECT_API_SCENARIO:READ','WORKSPACE_USER:READ']">
<el-menu v-if="showMenu" <el-menu
:unique-opened="true" v-if="showMenu"
class="header-user-menu align-right header-top-menu" :unique-opened="true"
mode="horizontal" class="header-user-menu align-right header-top-menu"
:background-color="color" mode="horizontal"
text-color="#fff" :background-color="color"
active-text-color="#fff"> text-color="#fff"
active-text-color="#fff">
<el-menu-item onselectstart="return false"> <el-menu-item onselectstart="return false">
<el-tooltip effect="light"> <el-tooltip effect="light">
<template v-slot:content> <template v-slot:content>
@ -14,8 +15,7 @@
</template> </template>
<div @click="showTaskCenter" v-if="runningTotal > 0"> <div @click="showTaskCenter" v-if="runningTotal > 0">
<el-badge :value="runningTotal" class="item" type="primary"> <el-badge :value="runningTotal" class="item" type="primary">
<font-awesome-icon class="icon global focusing" :icon="['fas', 'tasks']" <font-awesome-icon class="icon global focusing" :icon="['fas', 'tasks']" style="font-size: 18px"/>
style="font-size: 18px"/>
</el-badge> </el-badge>
</div> </div>
<font-awesome-icon @click="showTaskCenter" class="icon global focusing" :icon="['fas', 'tasks']" v-else/> <font-awesome-icon @click="showTaskCenter" class="icon global focusing" :icon="['fas', 'tasks']" v-else/>
@ -23,11 +23,16 @@
</el-menu-item> </el-menu-item>
</el-menu> </el-menu>
<el-drawer :visible.sync="taskVisible" :destroy-on-close="true" direction="rtl" <el-drawer
:withHeader="true" :modal="false" :title="$t('commons.task_center')" :size="size.toString()" :visible.sync="taskVisible"
custom-class="ms-drawer-task"> :destroy-on-close="true"
direction="rtl"
:withHeader="true"
:modal="false"
:title="$t('commons.task_center')"
:size="size.toString()"
custom-class="ms-drawer-task">
<el-card style="float: left;width: 850px" v-if="size > 550 "> <el-card style="float: left;width: 850px" v-if="size > 550 ">
<div class="ms-task-opt-btn" @click="packUp">收起</div> <div class="ms-task-opt-btn" @click="packUp">收起</div>
<!-- 接口用例结果 --> <!-- 接口用例结果 -->
<ms-request-result-tail :response="response" ref="debugResult" v-if="reportType === 'API'"/> <ms-request-result-tail :response="response" ref="debugResult" v-if="reportType === 'API'"/>
@ -35,9 +40,9 @@
<ms-api-report-detail :reportId="reportId" v-if="reportType === 'SCENARIO'"/> <ms-api-report-detail :reportId="reportId" v-if="reportType === 'SCENARIO'"/>
<performance-report-view :perReportId="reportId" v-if="reportType === 'PERFORMANCE'"/> <performance-report-view :perReportId="reportId" v-if="reportType === 'PERFORMANCE'"/>
</el-card> </el-card>
<el-card style="width: 550px;float: right">
<el-card style="width: 550px;float: right" v-loading="loading">
<div style="color: #2B415C;margin: 0px 20px 0px;"> <div style="color: #2B415C;margin: 0px 20px 0px;">
<el-form label-width="68px" class="ms-el-form-item"> <el-form label-width="68px" class="ms-el-form-item">
<el-row> <el-row>
@ -78,48 +83,49 @@
</el-row> </el-row>
</el-form> </el-form>
</div> </div>
<el-divider direction="horizontal" style="width: 100%"/>
<div class="report-container"> <div class="report-container">
<div v-for="item in taskData" :key="item.id" style="margin-bottom: 5px"> <div v-for="item in taskData" :key="item.id" style="margin-bottom: 5px;">
<el-card class="ms-card-task" @click.native="showReport(item)"> <el-card class="ms-card-task" @click.native="showReport(item)">
<span class="ms-task-name-width"><el-link type="primary"> <span class="ms-task-name-width"><el-link type="primary">
{{ getModeName(item.executionModule) }} </el-link>: {{ item.name }} </span> {{ getModeName(item.executionModule) }} </el-link>: {{ item.name }}
<el-button size="mini" class="ms-task-stop" @click.stop @click="stop(item)" </span>
v-if="showStop(item.executionStatus)"> <el-button size="mini" class="ms-task-stop" @click.stop @click="stop(item)" v-if="showStop(item.executionStatus)">
{{ $t('report.stop_btn') }} {{ $t('report.stop_btn') }}
</el-button> </el-button>
<br/> <br/>
<span> <span>
执行器{{ item.actuator }} {{ item.executor }} 执行器{{ item.actuator }} {{ item.executor }} {{ item.executionTime | timestampFormatDate }} {{ getMode(item.triggerMode) }}
{{ item.executionTime | timestampFormatDate }} </span>
{{ getMode(item.triggerMode) }}
</span>
<br/> <br/>
<el-row> <el-row>
<el-col :span="20"> <el-col :span="20">
<el-progress :percentage="getPercentage(item.executionStatus)" :format="format"/> <el-progress :percentage="getPercentage(item.executionStatus)" :format="format"/>
</el-col> </el-col>
<el-col :span="4"> <el-col :span="4">
<span v-if="item.executionStatus && item.executionStatus.toLowerCase() === 'error'" <span v-if="item.executionStatus && item.executionStatus.toLowerCase() === 'error'" class="ms-task-error">
class="ms-task-error">
error error
</span> </span>
<span v-else-if="item.executionStatus && item.executionStatus.toLowerCase() === 'success'" <span v-else-if="item.executionStatus && item.executionStatus.toLowerCase() === 'success'" class="ms-task-success">
class="ms-task-success"> success
success </span>
</span> <span v-else-if="item.executionStatus && item.executionStatus.toLowerCase() === 'stop'">
<span v-else-if="item.executionStatus && item.executionStatus.toLowerCase() === 'stop'"> stopped
stopped </span>
<span v-else>
{{ item.executionStatus ? item.executionStatus.toLowerCase() : item.executionStatus }}
</span> </span>
<span v-else>{{
item.executionStatus ? item.executionStatus.toLowerCase() : item.executionStatus
}}</span>
</el-col> </el-col>
</el-row> </el-row>
</el-card> </el-card>
</div> </div>
</div> </div>
<div class="report-bottom">
<ms-table-pagination :change="init" :current-page.sync="currentPage" :page-size.sync="pageSize" :total="total" small/>
</div>
</el-card> </el-card>
</el-drawer> </el-drawer>
</div> </div>
</template> </template>
@ -127,14 +133,14 @@
<script> <script>
import MsDrawer from "../common/components/MsDrawer"; import MsDrawer from "../common/components/MsDrawer";
import {getCurrentProjectID, getCurrentUser, hasPermissions} from "@/common/js/utils"; import {getCurrentProjectID, getCurrentUser, hasPermissions} from "@/common/js/utils";
export default { export default {
name: "MsTaskCenter", name: "MsTaskCenter",
components: { components: {
MsDrawer, MsDrawer,
MsRequestResultTail: () => import("../../components/api/definition/components/response/RequestResultTail"), MsRequestResultTail: () => import("../../components/api/definition/components/response/RequestResultTail"),
MsApiReportDetail: () => import("../../components/api/automation/report/ApiReportDetail"), MsApiReportDetail: () => import("../../components/api/automation/report/ApiReportDetail"),
PerformanceReportView: () => import("../../components/performance/report/PerformanceReportView") PerformanceReportView: () => import("../../components/performance/report/PerformanceReportView"),
MsTablePagination: () => import("./TaskPagination"),
}, },
inject: [ inject: [
'reload' 'reload'
@ -144,11 +150,15 @@ export default {
runningTotal: 0, runningTotal: 0,
taskVisible: false, taskVisible: false,
result: {}, result: {},
loading: false,
taskData: [], taskData: [],
response: {}, response: {},
initEnd: false, initEnd: false,
visible: false, visible: false,
showType: "", showType: "",
pageSize: 10,
currentPage: 1,
total: 0,
runMode: [ runMode: [
{id: '', label: this.$t('api_test.definition.document.data_set.all')}, {id: '', label: this.$t('api_test.definition.document.data_set.all')},
{id: 'BATCH', label: this.$t('api_test.automation.batch_execute')}, {id: 'BATCH', label: this.$t('api_test.automation.batch_execute')},
@ -181,6 +191,11 @@ export default {
default: true default: true
} }
}, },
computed: {
disabled() {
return this.loading
}
},
created() { created() {
if (hasPermissions('PROJECT_API_SCENARIO:READ')) { if (hasPermissions('PROJECT_API_SCENARIO:READ')) {
this.condition.executor = getCurrentUser().id; this.condition.executor = getCurrentUser().id;
@ -194,6 +209,10 @@ export default {
} }
}, },
methods: { methods: {
nextData() {
this.loading = true;
this.init();
},
format(item) { format(item) {
return ''; return '';
}, },
@ -245,6 +264,8 @@ export default {
onError(e) { onError(e) {
}, },
onMessage(e) { onMessage(e) {
this.currentPage = 1;
this.loading = false;
let taskTotal = e.data; let taskTotal = e.data;
this.runningTotal = taskTotal; this.runningTotal = taskTotal;
this.initIndex++; this.initIndex++;
@ -267,6 +288,7 @@ export default {
this.visible = false; this.visible = false;
this.size = 550; this.size = 550;
this.showType = ""; this.showType = "";
this.currentPage = 1;
if (this.websocket && this.websocket.close instanceof Function) { if (this.websocket && this.websocket.close instanceof Function) {
this.websocket.close(); this.websocket.close();
} }
@ -274,6 +296,8 @@ export default {
open() { open() {
this.showTaskCenter(); this.showTaskCenter();
this.initIndex = 0; this.initIndex = 0;
this.noMore = false;
this.currentPage = 1;
}, },
getPercentage(status) { getPercentage(status) {
if (status) { if (status) {
@ -376,12 +400,13 @@ export default {
if (this.showType === "CASE" || this.showType === "SCENARIO") { if (this.showType === "CASE" || this.showType === "SCENARIO") {
return; return;
} }
this.result.loading = true;
this.condition.projectId = getCurrentProjectID(); this.condition.projectId = getCurrentProjectID();
this.result = this.$post('/task/center/list', this.condition, response => { this.result = this.$post('/task/center/list/' + this.currentPage + '/' + this.pageSize, this.condition, response => {
this.taskData = response.data; this.total = response.data.itemCount;
this.taskData = response.data.listObject;
this.calculationRunningTotal(); this.calculationRunningTotal();
this.initEnd = true; this.initEnd = true;
this.loading = false;
}); });
}, },
initCaseHistory(id) { initCaseHistory(id) {
@ -416,21 +441,16 @@ export default {
color: #44b349; color: #44b349;
margin-left: 10px; margin-left: 10px;
} }
.report-container { .report-container {
height: calc(100vh - 180px); height: calc(100vh - 270px);
min-height: 550px;
overflow-y: auto; overflow-y: auto;
} }
.align-right { .align-right {
float: right; float: right;
} }
.icon { .icon {
width: 24px; width: 24px;
} }
/deep/ .el-drawer__header { /deep/ .el-drawer__header {
font-size: 18px; font-size: 18px;
color: #0a0a0a; color: #0a0a0a;
@ -439,79 +459,63 @@ export default {
margin-bottom: 10px; margin-bottom: 10px;
padding: 10px; padding: 10px;
} }
.ms-card-task >>> .el-card__body { .ms-card-task >>> .el-card__body {
padding: 10px; padding: 10px;
} }
.global { .global {
color: #fff; color: #fff;
} }
.header-top-menu { .header-top-menu {
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;
color: inherit; color: inherit;
} }
.header-top-menu.el-menu--horizontal > li { .header-top-menu.el-menu--horizontal > li {
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;
color: inherit; color: inherit;
} }
.header-top-menu.el-menu--horizontal > li.el-submenu > * { .header-top-menu.el-menu--horizontal > li.el-submenu > * {
height: 39px; height: 39px;
line-height: 40px; line-height: 40px;
color: inherit; color: inherit;
} }
.header-top-menu.el-menu--horizontal > li.is-active { .header-top-menu.el-menu--horizontal > li.is-active {
background: var(--color_shallow) !important; background: var(--color_shallow) !important;
} }
.ms-card-task:hover { .ms-card-task:hover {
cursor: pointer; cursor: pointer;
border-color: #783887; border-color: #783887;
} }
/deep/ .el-progress-bar { /deep/ .el-progress-bar {
padding-right: 20px; padding-right: 20px;
} }
/deep/ .el-menu-item { /deep/ .el-menu-item {
padding-left: 0; padding-left: 0;
padding-right: 0; padding-right: 0;
} }
/deep/ .el-badge__content.is-fixed { /deep/ .el-badge__content.is-fixed {
top: 25px; top: 25px;
} }
/deep/ .el-badge__content { /deep/ .el-badge__content {
border-radius: 10px; border-radius: 10px;
height: 10px; height: 10px;
line-height: 10px; line-height: 10px;
} }
.item { .item {
margin-right: 10px; margin-right: 10px;
} }
.ms-task-error { .ms-task-error {
color: #F56C6C; color: #F56C6C;
} }
.ms-task-stop { .ms-task-stop {
color: #F56C6C; color: #F56C6C;
float: right; float: right;
margin-right: 20px; margin-right: 20px;
} }
.ms-task-success { .ms-task-success {
color: #67C23A; color: #67C23A;
} }
.ms-task-name-width { .ms-task-name-width {
display: inline-block; display: inline-block;
overflow-x: hidden; overflow-x: hidden;
@ -521,11 +525,9 @@ export default {
white-space: nowrap; white-space: nowrap;
width: 360px; width: 360px;
} }
.ms-el-form-item >>> .el-form-item { .ms-el-form-item >>> .el-form-item {
margin-bottom: 6px; margin-bottom: 6px;
} }
.ms-task-opt-btn { .ms-task-opt-btn {
position: fixed; position: fixed;
right: 1372px; right: 1372px;
@ -545,17 +547,17 @@ export default {
font-weight: bold; font-weight: bold;
margin-left: 1px; margin-left: 1px;
} }
.ms-task-opt-btn i { .ms-task-opt-btn i {
margin-left: -2px; margin-left: -2px;
} }
.ms-task-opt-btn:hover { .ms-task-opt-btn:hover {
opacity: 0.8; opacity: 0.8;
} }
.ms-task-opt-btn:hover i { .ms-task-opt-btn:hover i {
margin-left: 0; margin-left: 0;
color: white; color: white;
} }
.report-bottom {
margin-top: 10px;
}
</style> </style>

View File

@ -0,0 +1,62 @@
<template>
<el-row type="flex" justify="end">
<div class="table-page">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="pageSizes"
:page-size="pageSize"
:page-count="5"
small
layout="total, sizes, prev, pager, next"
:total="total">
</el-pagination>
</div>
</el-row>
</template>
<script>
export default {
name: "MsTaskPagination",
props: {
page: Object,
currentPage: {
type: Number,
default: 1
},
pageSize: {
type: Number,
default: 5
},
pageSizes: {
type: Array,
default: function () {
return [5, 10, 20, 50, 100]
}
},
total: {
type: Number,
default: 0
},
change: Function
},
methods: {
handleSizeChange: function (size) {
this.$emit('update:pageSize', size)
this.change();
},
handleCurrentChange(current) {
this.$emit('update:currentPage', current)
this.change();
}
}
}
</script>
<style scoped>
.table-page {
padding-top: 10px;
}
</style>