refactor: 重构测试计划-性能测试页面 (#4560)

Co-authored-by: chenjianxing <jianxing.chen@fit2cloud.com>
--bug=1004990 --user=陈建星 【测试计划】性能用例,全选没自动提示“批量操作” https://www.tapd.cn/55049933/s/1025064
This commit is contained in:
metersphere-bot 2021-07-09 16:58:18 +08:00 committed by GitHub
parent ffb276545e
commit 09c876f7e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 125 additions and 190 deletions

View File

@ -135,14 +135,6 @@ export default {
planId() { planId() {
this.condition.planId = this.planId; this.condition.planId = this.planId;
}, },
selectNodeIds() {
this.search();
},
projectId() {
this.condition.projectId = this.projectId;
this.getProjectNode();
this.search();
},
reviewId() { reviewId() {
this.condition.reviewId = this.reviewId; this.condition.reviewId = this.reviewId;
}, },
@ -157,6 +149,9 @@ export default {
}, },
setProject(projectId) { setProject(projectId) {
this.projectId = projectId; this.projectId = projectId;
this.condition.projectId = this.projectId;
this.getProjectNode();
this.search();
}, },
saveCaseRelevance() { saveCaseRelevance() {
let param = {}; let param = {};
@ -238,6 +233,7 @@ export default {
nodeChange(node, nodeIds, nodeNames) { nodeChange(node, nodeIds, nodeNames) {
this.selectNodeIds = nodeIds; this.selectNodeIds = nodeIds;
this.selectNodeNames = nodeNames; this.selectNodeNames = nodeNames;
this.search();
}, },
refresh() { refresh() {
this.close(); this.close();

View File

@ -6,86 +6,70 @@
:condition="condition" :condition="condition"
:plan-id="planId" :plan-id="planId"
@refresh="initTable" @refresh="initTable"
@relevanceCase="$emit('relevanceCase')" @relevanceCase="$emit('relevanceCase')"/>
/>
</template> </template>
<el-table v-loading="result.loading" ref="table" <ms-table
border v-loading="result.loading"
:data="tableData" row-key="id" class="test-content adjust-table ms-select-all-fixed" :data="tableData"
@select-all="handleSelectAll" :condition="condition"
@filter-change="filter" :total="total"
@sort-change="sort" :page-size.sync="pageSize"
@select="handleSelectionChange" :height="screenHeight"> :operators="operators"
<el-table-column width="50" type="selection"/> :screen-height="screenHeight"
<ms-table-header-select-popover v-show="total>0" :batch-operators="buttons"
:page-size="pageSize > total ? total : pageSize" @handlePageChange="initTable"
:total="total" :fields.sync="fields"
:table-data-count-in-page="tableData.length" :field-key="tableHeaderKey"
@selectPageAll="isSelectDataAll(false)" @refresh="initTable"
@selectAll="isSelectDataAll(true)"/> ref="table">
<el-table-column min-width="40" :resizable="false" align="center"> <span v-for="(item) in fields" :key="item.key">
<template v-slot:default="scope"> <ms-table-column
<show-more-btn :is-show-tool="scope.row.showTool" :is-show="scope.row.showMore && !isReadOnly" :field="item"
:buttons="buttons" :size="selectDataCounts"/> :fields-width="fieldsWidth"
</template> prop="num"
</el-table-column> sortable
<template v-for="(item, index) in tableLabel"> min-width="80"
<el-table-column v-if="item.id == 'num'" prop="num" sortable min-width="80" label="ID" show-overflow-tooltip :key="index"/> label="ID"/>
<el-table-column <ms-table-column
v-if="item.id == 'caseName'" :field="item"
prop="caseName" :fields-width="fieldsWidth"
:label="$t('commons.name')" prop="caseName"
min-width="120" :label="$t('commons.name')"
sortable min-width="120"
show-overflow-tooltip sortable>
:key="index"> </ms-table-column>
</el-table-column> <ms-table-column
<el-table-column :field="item"
v-if="item.id == 'projectName'" :fields-width="fieldsWidth"
prop="projectName" prop="projectName"
min-width="120" min-width="120"
:label="$t('load_test.project_name')" :label="$t('load_test.project_name')">
show-overflow-tooltip </ms-table-column>
:key="index"> <ms-table-column
</el-table-column> :field="item"
<el-table-column :fields-width="fieldsWidth"
v-if="item.id == 'userName'" prop="userName"
prop="userName" min-width="100"
min-width="100" :label="$t('load_test.user_name')">
:label="$t('load_test.user_name')" </ms-table-column>
show-overflow-tooltip <ms-table-column
:key="index"> :field="item"
</el-table-column> :fields-width="fieldsWidth"
<el-table-column prop="status"
v-if="item.id == 'createTime'" :filters="statusFilters"
sortable :label="$t('commons.status')"
prop="createTime" min-width="80">
min-width="160"
:label="$t('commons.create_time')"
:key="index">
<template v-slot:default="scope">
<span>{{ scope.row.createTime | timestampFormatDate }}</span>
</template>
</el-table-column>
<el-table-column
v-if="item.id == 'status'"
prop="status"
column-key="status"
:filters="statusFilters"
:label="$t('commons.status')"
min-width="80"
:key="index">
<template v-slot:default="{row}"> <template v-slot:default="{row}">
<ms-performance-test-status :row="row"/> <ms-performance-test-status :row="row"/>
</template> </template>
</el-table-column> </ms-table-column>
<el-table-column <ms-table-column
v-if="item.id == 'caseStatus'" :field="item"
min-width="100" :fields-width="fieldsWidth"
prop="caseStatus" min-width="100"
:label="$t('test_track.plan.load_case.execution_status')" prop="caseStatus"
:key="index"> :label="$t('test_track.plan.load_case.execution_status')">
<template v-slot:default="{row}"> <template v-slot:default="{row}">
<el-tag size="mini" type="danger" v-if="row.caseStatus === 'error'"> <el-tag size="mini" type="danger" v-if="row.caseStatus === 'error'">
{{ row.caseStatus }} {{ row.caseStatus }}
@ -98,13 +82,13 @@
</el-tag> </el-tag>
<span v-else>-</span> <span v-else>-</span>
</template> </template>
</el-table-column> </ms-table-column>
<el-table-column <ms-table-column
v-if="item.id == 'loadReportId'" :field="item"
:label="$t('test_track.plan.load_case.report')" :fields-width="fieldsWidth"
min-width="80" :label="$t('test_track.plan.load_case.report')"
show-overflow-tooltip prop="loadReportId"
:key="index"> min-width="80">
<template v-slot:default="scope"> <template v-slot:default="scope">
<div v-loading="loading === scope.row.id"> <div v-loading="loading === scope.row.id">
<el-link type="info" @click="getReport(scope.row)" v-if="scope.row.loadReportId"> <el-link type="info" @click="getReport(scope.row)" v-if="scope.row.loadReportId">
@ -113,29 +97,14 @@
<span v-else> - </span> <span v-else> - </span>
</div> </div>
</template> </template>
</el-table-column> </ms-table-column>
</template>
<el-table-column v-if="!isReadOnly" fixed="right" min-width="100" :label="$t('commons.operating')" > <ms-update-time-column :field="item" :fields-width="fieldsWidth"/>
<template slot="header"> <ms-create-time-column :field="item" :fields-width="fieldsWidth"/>
<header-label-operate @exec="customHeader"/>
</template> </span>
<template v-slot:default="scope"> </ms-table>
<div>
<ms-table-operator-button class="run-button"
v-permission="['PROJECT_TRACK_PLAN:READ+RUN']"
:tip="$t('api_test.run')"
icon="el-icon-video-play"
@exec="run(scope.row)"/>
<ms-table-operator-button v-permission="['PROJECT_TRACK_PLAN:READ+RELEVANCE_OR_CANCEL']"
:tip="$t('test_track.plan_view.cancel_relevance')"
icon="el-icon-unlock" type="danger" @exec="handleDelete(scope.row)"/>
</div>
</template>
</el-table-column>
</el-table>
<header-custom ref="headerCustom" :initTableData="initTable" :optionalFields=headerItems
:type=type></header-custom>
<ms-table-pagination :change="initTable" :current-page.sync="currentPage" :page-size.sync="pageSize" <ms-table-pagination :change="initTable" :current-page.sync="currentPage" :page-size.sync="pageSize"
:total="total"/> :total="total"/>
</el-card> </el-card>
@ -148,61 +117,67 @@
<script> <script>
import TestPlanLoadCaseListHeader import TestPlanLoadCaseListHeader
from "@/business/components/track/plan/view/comonents/load/TestPlanLoadCaseListHeader"; from "@/business/components/track/plan/view/comonents/load/TestPlanLoadCaseListHeader";
import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn";
import MsTablePagination from "@/business/components/common/pagination/TablePagination"; import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import MsPerformanceTestStatus from "@/business/components/performance/test/PerformanceTestStatus"; import MsPerformanceTestStatus from "@/business/components/performance/test/PerformanceTestStatus";
import MsTableOperatorButton from "@/business/components/common/components/MsTableOperatorButton";
import LoadCaseReport from "@/business/components/track/plan/view/comonents/load/LoadCaseReport"; import LoadCaseReport from "@/business/components/track/plan/view/comonents/load/LoadCaseReport";
import { import {
_filter,
_handleSelect,
_handleSelectAll,
_sort,
getLabel,
getSelectDataCounts,
setUnSelectIds,
buildBatchParam, buildBatchParam,
initCondition, checkTableRowIsSelect, getCustomTableHeader, getCustomTableWidth
toggleAllSelection,
checkTableRowIsSelect, deepClone
} from "@/common/js/tableUtils"; } from "@/common/js/tableUtils";
import HeaderCustom from "@/business/components/common/head/HeaderCustom"; import {TEST_PLAN_LOAD_CASE} from "@/common/js/constants";
import {TAPD, TEST_CASE_LIST, TEST_PLAN_LOAD_CASE} from "@/common/js/constants";
import {Test_Plan_Load_Case, Track_Test_Case} from "@/business/components/common/model/JsonData";
import {getCurrentUser} from "@/common/js/utils"; import {getCurrentUser} from "@/common/js/utils";
import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate"; import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate";
import MsTableHeaderSelectPopover from "@/business/components/common/components/table/MsTableHeaderSelectPopover";
import MsPlanRunMode from "../../../common/PlanRunMode"; import MsPlanRunMode from "../../../common/PlanRunMode";
import MsTable from "@/business/components/common/components/table/MsTable";
import MsTableColumn from "@/business/components/common/components/table/MsTableColumn";
import MsCreateTimeColumn from "@/business/components/common/components/table/MsCreateTimeColumn";
import MsUpdateTimeColumn from "@/business/components/common/components/table/MsUpdateTimeColumn";
export default { export default {
name: "TestPlanLoadCaseList", name: "TestPlanLoadCaseList",
components: { components: {
MsUpdateTimeColumn,
MsCreateTimeColumn,
MsTableColumn,
MsTable,
HeaderLabelOperate, HeaderLabelOperate,
HeaderCustom,
LoadCaseReport, LoadCaseReport,
TestPlanLoadCaseListHeader, TestPlanLoadCaseListHeader,
ShowMoreBtn,
MsTablePagination, MsTablePagination,
MsPerformanceTestStatus, MsPerformanceTestStatus,
MsTableOperatorButton,
MsTableHeaderSelectPopover,
MsPlanRunMode MsPlanRunMode
}, },
data() { data() {
return { return {
type: TEST_PLAN_LOAD_CASE, type: TEST_PLAN_LOAD_CASE,
headerItems: Test_Plan_Load_Case,
tableLabel: [], tableLabel: [],
condition: {}, condition: {},
result: {}, result: {},
tableData: [], tableData: [],
selectRows: new Set(),
currentPage: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
selectDataCounts: 0,
status: 'default', status: 'default',
screenHeight: 'calc(100vh - 250px)',// screenHeight: 'calc(100vh - 250px)',//
tableHeaderKey:"TEST_PLAN_LOAD_CASE",
fields: getCustomTableHeader('TEST_PLAN_LOAD_CASE'),
fieldsWidth: getCustomTableWidth('TEST_PLAN_LOAD_CASE'),
operators: [
{
tip: this.$t('api_test.run'), icon: "el-icon-video-play",
exec: this.run,
class: 'run-button',
isDisable: this.isReadOnly,
permissions: ['PROJECT_TRACK_PLAN:READ+RUN']
},
{
tip: this.$t('test_track.plan_view.cancel_relevance'), icon: "el-icon-unlock",
exec: this.handleDelete,
type: 'danger',
isDisable: this.isReadOnly,
permissions: ['PROJECT_TRACK_PLAN:READ+RELEVANCE_OR_CANCEL']
}
],
buttons: [ buttons: [
{ {
name: this.$t('test_track.plan.load_case.unlink_in_bulk'), handleClick: this.handleDeleteBatch, permissions: ['PROJECT_TRACK_PLAN:READ+CASE_BATCH_DELETE'] name: this.$t('test_track.plan.load_case.unlink_in_bulk'), handleClick: this.handleDeleteBatch, permissions: ['PROJECT_TRACK_PLAN:READ+CASE_BATCH_DELETE']
@ -256,13 +231,13 @@ export default {
array.push(this.tableData[i]); array.push(this.tableData[i]);
} }
} }
this.selectRows = array; return array;
}, },
runBatch(config){ runBatch(config){
this.orderBySelectRows(this.selectRows); let rows = this.orderBySelectRows(this.$refs.table.selectRows);
if(this.condition != null && this.condition.selectAll){ if(this.condition != null && this.condition.selectAll){
let selectAllRowParams = buildBatchParam(this); let selectAllRowParams = buildBatchParam(this);
selectAllRowParams.ids = Array.from(this.selectRows).map(row => row.id); selectAllRowParams.ids = Array.from(rows).map(row => row.id);
this.$post('/test/plan/load/case/selectAllTableRows', selectAllRowParams, response => { this.$post('/test/plan/load/case/selectAllTableRows', selectAllRowParams, response => {
let dataRows = response.data; let dataRows = response.data;
let runArr = []; let runArr = [];
@ -280,7 +255,7 @@ export default {
}); });
}else { }else {
let runArr = []; let runArr = [];
this.selectRows.forEach(loadCase => { rows.forEach(loadCase => {
runArr.push( { runArr.push( {
id: loadCase.loadCaseId, id: loadCase.loadCaseId,
testPlanLoadId: loadCase.id, testPlanLoadId: loadCase.id,
@ -300,14 +275,8 @@ export default {
this.initTable(); this.initTable();
this.refreshStatus(); this.refreshStatus();
}, },
customHeader() {
const list = deepClone(this.tableLabel);
this.$refs.headerCustom.open(list);
},
initTable() { initTable() {
this.autoCheckStatus(); this.autoCheckStatus();
this.selectRows = new Set();
this.condition.testPlanId = this.planId; this.condition.testPlanId = this.planId;
if (this.selectProjectId && this.selectProjectId !== 'root') { if (this.selectProjectId && this.selectProjectId !== 'root') {
this.condition.projectId = this.selectProjectId; this.condition.projectId = this.selectProjectId;
@ -329,10 +298,10 @@ export default {
this.tableData = listObject; this.tableData = listObject;
if (this.$refs.table) { if (this.$refs.table) {
setTimeout(this.$refs.table.doLayout, 200); setTimeout(this.$refs.table.doLayout, 200);
this.$nextTick(() => {
checkTableRowIsSelect(this, this.condition, this.tableData, this.$refs.table, this.$refs.table.selectRows);
});
} }
this.$nextTick(() => {
checkTableRowIsSelect(this,this.condition,this.tableData,this.$refs.table,this.selectRows);
})
}) })
} }
if (this.reviewId) { if (this.reviewId) {
@ -344,14 +313,12 @@ export default {
this.tableData = listObject; this.tableData = listObject;
if (this.$refs.table) { if (this.$refs.table) {
setTimeout(this.$refs.table.doLayout, 200); setTimeout(this.$refs.table.doLayout, 200);
this.$nextTick(() => {
checkTableRowIsSelect(this, this.condition, this.tableData, this.$refs.table, this.$refs.table.selectRows);
});
} }
this.$nextTick(() => {
checkTableRowIsSelect(this,this.condition,this.tableData,this.$refs.table,this.selectRows);
})
}) })
} }
getLabel(this, TEST_PLAN_LOAD_CASE);
}, },
autoCheckStatus() { autoCheckStatus() {
if (!this.planId) { if (!this.planId) {
@ -367,33 +334,24 @@ export default {
arr.length > 0 ? this.initTable() : clearInterval(this.refreshScheduler); arr.length > 0 ? this.initTable() : clearInterval(this.refreshScheduler);
}, 8000); }, 8000);
}, },
handleSelectAll(selection) {
_handleSelectAll(this, selection, this.tableData, this.selectRows);
setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
},
handleSelectionChange(selection, row) {
_handleSelect(this, selection, row, this.selectRows);
setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
},
handleDeleteBatch() { handleDeleteBatch() {
this.$alert(this.$t('test_track.plan_view.confirm_cancel_relevance') + "", '', { this.$alert(this.$t('test_track.plan_view.confirm_cancel_relevance') + "", '', {
confirmButtonText: this.$t('commons.confirm'), confirmButtonText: this.$t('commons.confirm'),
callback: (action) => { callback: (action) => {
if (action === 'confirm') { if (action === 'confirm') {
let ids = Array.from(this.selectRows).map(row => row.id); let ids = this.$refs.table.selectIds;
if (this.planId) { if (this.planId) {
let param = buildBatchParam(this); let param = buildBatchParam(this);
param.ids = ids;
this.result = this.$post('/test/plan/load/case/batch/delete', param, () => { this.result = this.$post('/test/plan/load/case/batch/delete', param, () => {
this.selectRows.clear(); this.clear();
this.initTable(); this.initTable();
this.$success(this.$t('test_track.cancel_relevance_success')); this.$success(this.$t('test_track.cancel_relevance_success'));
}); });
} }
if (this.reviewId) { if (this.reviewId) {
this.result = this.$post('/test/review/load/case/batch/delete', ids, () => { this.result = this.$post('/test/review/load/case/batch/delete', ids, () => {
this.selectRows.clear(); this.clear();
this.initTable(); this.initTable();
this.$success(this.$t('test_track.cancel_relevance_success')); this.$success(this.$t('test_track.cancel_relevance_success'));
}); });
@ -402,6 +360,11 @@ export default {
} }
}) })
}, },
clear() {
if (this.$refs.table) {
this.$refs.table.clear();
}
},
handleRunBatch() { handleRunBatch() {
this.$refs.runMode.open(); this.$refs.runMode.open();
}, },
@ -442,18 +405,6 @@ export default {
this.initTable(); this.initTable();
}); });
}, },
sort(column) {
//
if (this.condition.orders) {
this.condition.orders = [];
}
_sort(column, this.condition);
this.initTable();
},
filter(filters) {
_filter(filters, this.condition);
this.initTable();
},
getReport(data) { getReport(data) {
const {loadReportId} = data; const {loadReportId} = data;
this.reportId = loadReportId; this.reportId = loadReportId;
@ -476,20 +427,8 @@ export default {
clearInterval(this.refreshScheduler); clearInterval(this.refreshScheduler);
} }
}, },
isSelectDataAll(data) {
this.condition.selectAll = data;
//
toggleAllSelection(this.$refs.table, this.tableData, this.selectRows);
//
_handleSelectAll(this, this.tableData, this.tableData, this.selectRows);
//ID()
this.condition.unSelectIds = [];
//
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
},
}, },
beforeDestroy() { beforeDestroy() {
console.log('beforeDestroy')
this.cancelRefresh(); this.cancelRefresh();
}, },
} }