refactor: 功能用例页面性能优化

--bug=1009823 --user=陈建星 【测试跟踪】github#9651,功能测试用例点击编辑经常加载慢之后页面奔溃 https://www.tapd.cn/55049933/s/10970588
This commit is contained in:
chenjianxing 2022-01-24 22:35:04 +08:00 committed by zhangdahai112
parent 58eef7235b
commit db73275ccd
7 changed files with 122 additions and 125 deletions

View File

@ -100,11 +100,6 @@ public class TestCaseController {
return testCaseService.listTestCaseMthod(request); return testCaseService.listTestCaseMthod(request);
} }
@PostMapping("/list/ids")
public List<TestCaseDTO> getTestPlanCaseIds(@RequestBody QueryTestCaseRequest request) {
return testCaseService.listTestCaseIds(request);
}
@GetMapping("/relationship/case/{id}/{relationshipType}") @GetMapping("/relationship/case/{id}/{relationshipType}")
public List<RelationshipEdgeDTO> getRelationshipCase(@PathVariable("id") String id, @PathVariable("relationshipType") String relationshipType) { public List<RelationshipEdgeDTO> getRelationshipCase(@PathVariable("id") String id, @PathVariable("relationshipType") String relationshipType) {
return testCaseService.getRelationshipCase(id, relationshipType); return testCaseService.getRelationshipCase(id, relationshipType);

View File

@ -1772,15 +1772,6 @@ public class TestCaseService {
return request.getId(); return request.getId();
} }
public List<TestCaseDTO> listTestCaseIds(QueryTestCaseRequest request) {
setDefaultOrder(request);
List<String> selectFields = new ArrayList<>();
selectFields.add("test_case.id");
selectFields.add("test_case.name");
request.setSelectFields(selectFields);
return extTestCaseMapper.listIds(request);
}
public void minderEdit(TestCaseMinderEditRequest request) { public void minderEdit(TestCaseMinderEditRequest request) {
deleteToGcBatch(request.getIds()); deleteToGcBatch(request.getIds());

View File

@ -1,17 +1,17 @@
<template> <template>
<span class="previous-next-button"> <span class="previous-next-button">
<span class="head-right-tip" v-if="index + 1 === list.length"> <span class="head-right-tip" v-if="countNum === total">
{{ $t('test_track.plan_view.pre_case') }} : {{list[index - 1] ? list[index - 1].name : ''}} {{ $t('test_track.plan_view.pre_case') }} : {{list[index - 1] ? list[index - 1].name : ''}}
</span> </span>
<span class="head-right-tip" v-if="index + 1 !== list.length"> <span class="head-right-tip" v-if="countNum !== total">
{{ $t('test_track.plan_view.next_case') }} : {{list[index + 1] ? list[index + 1].name : ''}} {{ $t('test_track.plan_view.next_case') }} : {{list[index + 1] ? list[index + 1].name : ''}}
</span> </span>
<el-button plain size="mini" icon="el-icon-arrow-up" :disabled="index + 1 <= 1" @click="handlePre()"/> <el-button plain size="mini" icon="el-icon-arrow-up" :disabled="countNum <= 1" @click="handlePre()"/>
<span> <span>
{{ index + 1 }}/{{ list.length }} {{ countNum }}/{{ total }}
</span> </span>
<el-button plain size="mini" icon="el-icon-arrow-down" :disabled="index + 1 >= list.length" @click="handleNext()"/> <el-button plain size="mini" icon="el-icon-arrow-down" :disabled="countNum >= total" @click="handleNext()"/>
</span> </span>
</template> </template>
@ -35,6 +35,35 @@
default() { default() {
return 0 return 0
} }
},
pageTotal: {
type: Number,
default() {
return 0
}
},
total: {
type: Number,
default() {
return 0
}
},
pageNum: {
type: Number,
default() {
return 0
}
},
pageSize: {
type: Number,
default() {
return 0
}
}
},
computed: {
countNum() {
return this.pageSize * (this.pageNum - 1) + this.index + 1;
} }
}, },
methods: { methods: {

View File

@ -299,8 +299,6 @@ export default {
{value: 'manual', label: this.$t('test_track.case.manual')} {value: 'manual', label: this.$t('test_track.case.manual')}
], ],
testCase: {}, testCase: {},
testCases: [],
index: 0,
showInputTag: true, showInputTag: true,
tableType: "", tableType: "",
stepFilter: new STEP, stepFilter: new STEP,
@ -602,7 +600,7 @@ export default {
this.customFieldForm = parseCustomField(this.form, this.testCaseTemplate, this.customFieldRules, buildTestCaseOldFields(this.form)); this.customFieldForm = parseCustomField(this.form, this.testCaseTemplate, this.customFieldRules, buildTestCaseOldFields(this.form));
this.reload(); this.reload();
} else { } else {
this.initTestCases(testCase); this.getTestCase(testCase.id);
} }
} else { } else {
if (this.selectNode.data) { if (this.selectNode.data) {
@ -629,40 +627,10 @@ export default {
this.getComments(this.currentTestCaseInfo); this.getComments(this.currentTestCaseInfo);
} }
}, },
handlePre() { getTestCase(id) {
this.index--;
this.getTestCase(this.index)
},
handleNext() {
this.index++;
this.getTestCase(this.index);
},
initTestCases(testCase) {
if (this.publicEnable) {
this.selectCondition.projectId = null;
} else {
this.selectCondition.workspaceId = null;
}
this.selectCondition.versionId = testCase.versionId
this.result = this.$post('/test/case/list/ids', this.selectCondition, response => {
this.testCases = response.data;
for (let i = 0; i < this.testCases.length; i++) {
if (this.testCases[i].id === testCase.id) {
this.index = i;
this.getTestCase(i);
}
}
});
},
getTestCase(index) {
let id = "";
this.showInputTag = false; this.showInputTag = false;
let testCase = this.testCases[index]; if (!id) {
if (typeof (index) == "undefined") {
id = this.currentTestCaseInfo.id; id = this.currentTestCaseInfo.id;
} else {
id = testCase.id;
} }
this.result = this.$get('/test/case/get/' + id, response => { this.result = this.$get('/test/case/get/' + id, response => {
if (response.data) { if (response.data) {

View File

@ -290,8 +290,6 @@ export default {
{value: 'manual', label: this.$t('test_track.case.manual')} {value: 'manual', label: this.$t('test_track.case.manual')}
], ],
testCase: {}, testCase: {},
testCases: [],
index: 0,
showInputTag: true, showInputTag: true,
tableType: "", tableType: "",
stepFilter: new STEP, stepFilter: new STEP,
@ -561,7 +559,7 @@ export default {
this.customFieldForm = parseCustomField(this.form, this.testCaseTemplate, this.customFieldRules, buildTestCaseOldFields(this.form)); this.customFieldForm = parseCustomField(this.form, this.testCaseTemplate, this.customFieldRules, buildTestCaseOldFields(this.form));
this.reload(); this.reload();
} else { } else {
this.initTestCases(testCase); this.getTestCase(testCase.id);
} }
} else { } else {
if (this.selectNode.data) { if (this.selectNode.data) {
@ -585,40 +583,10 @@ export default {
callback(); callback();
} }
}, },
handlePre() { getTestCase(id) {
this.index--;
this.getTestCase(this.index)
},
handleNext() {
this.index++;
this.getTestCase(this.index);
},
initTestCases(testCase) {
if (this.publicEnable) {
this.selectCondition.projectId = null;
} else {
this.selectCondition.workspaceId = null;
}
this.selectCondition.versionId = testCase.versionId
this.result = this.$post('/test/case/list/ids', this.selectCondition, response => {
this.testCases = response.data;
for (let i = 0; i < this.testCases.length; i++) {
if (this.testCases[i].id === testCase.id) {
this.index = i;
this.getTestCase(i);
}
}
});
},
getTestCase(index) {
let id = "";
this.showInputTag = false; this.showInputTag = false;
let testCase = this.testCases[index]; if (!id) {
if (typeof (index) == "undefined") {
id = this.currentTestCaseInfo.id; id = this.currentTestCaseInfo.id;
} else {
id = testCase.id;
} }
this.result = this.$get('/test/case/get/' + id, response => { this.result = this.$get('/test/case/get/' + id, response => {
if (response.data) { if (response.data) {

View File

@ -27,7 +27,15 @@
</el-col> </el-col>
<el-col class="head-right" :span="20"> <el-col class="head-right" :span="20">
<ms-previous-next-button :index="index" @pre="handlePre" @next="saveCase(true, true)" :list="testCases"/> <ms-previous-next-button
:index="index"
:page-num="pageNum"
:page-size="pageSize"
:page-total="pageTotal"
:total="total"
@pre="handlePre"
@next="saveCase(true, true)"
:list="testCases"/>
<el-button class="save-btn" type="primary" size="mini" :disabled="isReadOnly" @click="saveCase(true)"> <el-button class="save-btn" type="primary" size="mini" :disabled="isReadOnly" @click="saveCase(true)">
{{$t('test_track.save')}} & {{$t('test_track.next')}} {{$t('test_track.save')}} & {{$t('test_track.next')}}
</el-button> </el-button>
@ -185,7 +193,6 @@ export default {
showDialog: false, showDialog: false,
testCase: {}, testCase: {},
index: 0, index: 0,
testCases: [],
editor: ClassicEditor, editor: ClassicEditor,
editorConfig: { editorConfig: {
toolbar: ['heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', '|', 'undo', 'redo'], toolbar: ['heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', '|', 'undo', 'redo'],
@ -207,14 +214,21 @@ export default {
isCustomFiledActive: false, isCustomFiledActive: false,
otherInfoActive: true, otherInfoActive: true,
isReadOnly: false, isReadOnly: false,
testCases: []
}; };
}, },
props: { props: {
total: { total: {
type: Number type: Number,
}, },
searchParam: { searchParam: {
type: Object type: Object
},
pageNum: Number,
pageSize: {
type: Number,
default: 1
} }
}, },
computed: { computed: {
@ -226,6 +240,9 @@ export default {
}, },
statusReadOnly() { statusReadOnly() {
return !hasPermission('PROJECT_TRACK_PLAN:READ+RUN'); return !hasPermission('PROJECT_TRACK_PLAN:READ+RUN');
},
pageTotal() {
return this.total / this.pageSize;
} }
}, },
methods: { methods: {
@ -290,6 +307,10 @@ export default {
}; };
}, },
saveCase(next, noTip) { saveCase(next, noTip) {
if (next && this.index === this.testCases.length - 1) {//
this.handleNext();
return;
}
let param = {}; let param = {};
param.id = this.testCase.id; param.id = this.testCase.id;
param.status = this.testCase.status; param.status = this.testCase.status;
@ -320,7 +341,7 @@ export default {
} }
this.updateTestCases(param); this.updateTestCases(param);
this.setPlanStatus(this.testCase.planId); this.setPlanStatus(this.testCase.planId);
if (next && this.index < this.testCases.length - 1) { if (next) {
this.handleNext(); this.handleNext();
} }
}); });
@ -337,8 +358,15 @@ export default {
} }
}, },
handleNext() { handleNext() {
if (this.index === this.testCases.length - 1 && this.pageNum === this.pageTotal) {
this.$warning('已经是最后一页');
return;
} else if (this.index === this.testCases.length - 1) {
this.$emit('nextPage');
return;
}
this.index++; this.index++;
this.getTestCase(this.index); this.getTestCase(this.testCases[this.index].id);
this.reloadOtherInfo(); this.reloadOtherInfo();
}, },
reloadOtherInfo() { reloadOtherInfo() {
@ -348,15 +376,20 @@ export default {
}) })
}, },
handlePre() { handlePre() {
if (this.index === 0 && this.pageNum === 1) {
this.$warning('已经是第一页');
return;
} else if (this.index === 0) {
this.$emit('prePage');
return;
}
this.index--; this.index--;
this.getTestCase(this.index); this.getTestCase(this.testCases[this.index].id);
this.reloadOtherInfo(); this.reloadOtherInfo();
}, },
getTestCase(index) { getTestCase(id) {
this.testCase = {};
let testCase = this.testCases[index];
// id TestPlanTestCase id // id TestPlanTestCase id
this.result = this.$get('/test/plan/case/get/' + testCase.id, response => { this.result = this.$get('/test/plan/case/get/' + id, response => {
let item = {}; let item = {};
Object.assign(item, response.data); Object.assign(item, response.data);
if (item.results) { if (item.results) {
@ -400,19 +433,30 @@ export default {
this.getComments(item); this.getComments(item);
}); });
}, },
openTestCaseEdit(testCase) { openTestCaseEdit(testCase, tableData) {
this.showDialog = true; this.showDialog = true;
this.activeTab = 'detail'; this.activeTab = 'detail';
this.hasTapdId = false; this.hasTapdId = false;
this.hasZentaoId = false; this.hasZentaoId = false;
this.isReadOnly = !hasPermission('PROJECT_TRACK_PLAN:READ+RELEVANCE_OR_CANCEL'); this.isReadOnly = !hasPermission('PROJECT_TRACK_PLAN:READ+RELEVANCE_OR_CANCEL');
if (tableData) {
this.testCases = tableData;
for (let i = 0; i < this.testCases.length; i++) {
let item = this.testCases[i];
if (item.id === testCase.id) {
this.index = i;
break;
}
}
}
listenGoBack(this.handleClose); listenGoBack(this.handleClose);
let initFuc = this.initData; let initFuc = this.getTestCase;
getTemplate('field/template/case/get/relate/', this) getTemplate('field/template/case/get/relate/', this)
.then((template) => { .then((template) => {
this.testCaseTemplate = template; this.testCaseTemplate = template;
initFuc(testCase); initFuc(testCase.id);
}); });
if (this.$refs.otherInfo) { if (this.$refs.otherInfo) {
this.$refs.otherInfo.reset(); this.$refs.otherInfo.reset();
@ -432,17 +476,6 @@ export default {
saveReport(reportId) { saveReport(reportId) {
this.$post('/test/plan/case/edit', {id: this.testCase.id, reportId: reportId}); this.$post('/test/plan/case/edit', {id: this.testCase.id, reportId: reportId});
}, },
initData(testCase) {
this.result = this.$post('/test/plan/case/list/ids', this.searchParam, response => {
this.testCases = response.data;
for (let i = 0; i < this.testCases.length; i++) {
if (this.testCases[i].id === testCase.id) {
this.index = i;
this.getTestCase(i);
}
}
});
},
openTest(item) { openTest(item) {
const type = item.testType; const type = item.testType;
const id = item.testId; const id = item.testId;

View File

@ -248,8 +248,14 @@
<functional-test-case-edit <functional-test-case-edit
ref="testPlanTestCaseEdit" ref="testPlanTestCaseEdit"
:search-param.sync="condition" :search-param.sync="condition"
:page-num="currentPage"
:page-size="pageSize"
@nextPage="nextPage"
@prePage="prePage"
@refresh="initTableData" @refresh="initTableData"
:test-cases="tableData"
:is-read-only="isReadOnly" :is-read-only="isReadOnly"
:total="total"
@refreshTable="search"/> @refreshTable="search"/>
<batch-edit ref="batchEdit" @batchEdit="batchEdit" <batch-edit ref="batchEdit" @batchEdit="batchEdit"
@ -448,7 +454,7 @@ export default {
hub.$on("openFailureTestCase", row => { hub.$on("openFailureTestCase", row => {
this.isReadOnly = true; this.isReadOnly = true;
this.condition.status = 'Failure'; this.condition.status = 'Failure';
this.$refs.testPlanTestCaseEdit.openTestCaseEdit(row); this.$refs.testPlanTestCaseEdit.openTestCaseEdit(row, this.tableData);
}); });
this.refreshTableAndPlan(); this.refreshTableAndPlan();
this.hasEditPermission = hasPermission('PROJECT_TRACK_PLAN:READ+EDIT'); this.hasEditPermission = hasPermission('PROJECT_TRACK_PLAN:READ+EDIT');
@ -460,6 +466,18 @@ export default {
hub.$off("openFailureTestCase"); hub.$off("openFailureTestCase");
}, },
methods: { methods: {
nextPage() {
this.currentPage++;
this.initTableData(() => {
this.$refs.testPlanTestCaseEdit.openTestCaseEdit(this.tableData[0], this.tableData);
});
},
prePage() {
this.currentPage--;
this.initTableData(() => {
this.$refs.testPlanTestCaseEdit.openTestCaseEdit(this.tableData[this.tableData.length - 1], this.tableData);
});
},
getTemplateField() { getTemplateField() {
this.result.loading = true; this.result.loading = true;
let p1 = getProjectMember((data) => { let p1 = getProjectMember((data) => {
@ -478,7 +496,7 @@ export default {
getCustomFieldValue(row, field) { getCustomFieldValue(row, field) {
return getCustomFieldValue(row, field, this.members); return getCustomFieldValue(row, field, this.members);
}, },
initTableData() { initTableData(callback) {
initCondition(this.condition, this.condition.selectAll); initCondition(this.condition, this.condition.selectAll);
this.enableOrderDrag = this.condition.orders.length > 0 ? false : true; this.enableOrderDrag = this.condition.orders.length > 0 ? false : true;
@ -515,6 +533,9 @@ export default {
this.$set(this.tableData[i], "issuesContent", JSON.parse(this.tableData[i].issues)); this.$set(this.tableData[i], "issuesContent", JSON.parse(this.tableData[i].issues));
} }
} }
if (callback) {
callback();
}
}); });
} }
}, },
@ -527,7 +548,7 @@ export default {
}, },
showDetail(row, event, column) { showDetail(row, event, column) {
this.isReadOnly = !this.hasEditPermission; this.isReadOnly = !this.hasEditPermission;
this.$refs.testPlanTestCaseEdit.openTestCaseEdit(row); this.$refs.testPlanTestCaseEdit.openTestCaseEdit(row, this.tableData);
}, },
refresh() { refresh() {
this.condition = {components: TEST_PLAN_TEST_CASE_CONFIGS}; this.condition = {components: TEST_PLAN_TEST_CASE_CONFIGS};
@ -556,7 +577,7 @@ export default {
}, },
handleEdit(testCase, index) { handleEdit(testCase, index) {
this.isReadOnly = false; this.isReadOnly = false;
this.$refs.testPlanTestCaseEdit.openTestCaseEdit(testCase); this.$refs.testPlanTestCaseEdit.openTestCaseEdit(testCase, this.tableData);
}, },
handleDelete(testCase) { handleDelete(testCase) {
this.$alert(this.$t('test_track.plan_view.confirm_cancel_relevance') + ' ' + testCase.name + " ", '', { this.$alert(this.$t('test_track.plan_view.confirm_cancel_relevance') + ' ' + testCase.name + " ", '', {
@ -678,14 +699,6 @@ export default {
margin-left: 10px; margin-left: 10px;
} }
/*.ms-table-header >>> .table-title {*/
/* height: 0px;*/
/*}*/
/*/deep/ .el-table__fixed-body-wrapper {*/
/* top: 59px !important;*/
/*}*/
.ms-table-header { .ms-table-header {
margin-bottom: 10px; margin-bottom: 10px;
} }