refactor(测试跟踪): 编辑用例校验优化

--bug=1024236 --user=陈建星 【测试跟踪】多个必填字段,第一次有弹窗报错,后面没有报错提示 https://www.tapd.cn/55049933/s/1349421
This commit is contained in:
chenjianxing 2023-03-14 13:09:57 +08:00 committed by jianxing
parent bb52658197
commit 2f0b3660d5
4 changed files with 38 additions and 33 deletions

View File

@ -275,7 +275,9 @@ export default {
}
},
setScrollToBottom() {
this.$refs['scrollbar'].wrap.scrollTop = this.$refs['scrollbar'].wrap.scrollHeight;
if (this.$refs['scrollbar']) {
this.$refs['scrollbar'].wrap.scrollTop = this.$refs['scrollbar'].wrap.scrollHeight;
}
}
}
,

View File

@ -461,6 +461,7 @@ export default {
method: "",
prerequisite: "",
testId: "",
nodeId: '',
steps: [
{
num: 1,
@ -1539,31 +1540,8 @@ export default {
}
});
}
let detailForm = this.$refs.otherInfo.validateForm();
let baseInfoValidate = this.$refs.testCaseBaseInfo.validateForm() && this.$refs.testCaseBaseInfo.validateCaseFrom();
let customValidate = this.$refs.testCaseBaseInfo.validateCustomForm();
if (!detailForm || !baseInfoValidate) {
return false;
}
if (!customValidate) {
let customFieldFormFields =
this.$refs.testCaseBaseInfo.getCustomFields();
for (let i = 0; i < customFieldFormFields.length; i++) {
let customField = customFieldFormFields[i];
if (customField.validateState === "error") {
let name = customField.label || customField.labelFor;
if (this.currentValidateName) {
this.currentValidateName =
this.currentValidateName + "," + name;
} else {
this.currentValidateName = name;
}
}
}
this.isValidate = true;
this.$warning(this.currentValidateName + this.$t("commons.cannot_be_null"), false);
this.currentValidateName = "";
return false;
if (!this.$refs.testCaseBaseInfo.validateWithTip()) {
isValidate = false;
}
return isValidate;
},

View File

@ -109,7 +109,7 @@
>
<template v-slot:content="{ onClick, hoverEditable }">
<div :class="hoverEditable ? 'selectHover' : ''">
<el-form-item prop="module">
<el-form-item prop="nodeId">
<ms-select-tree
:disabled="readOnly"
:data="treeNodes"
@ -423,7 +423,7 @@ export default {
},
headerRules: {
customNum: [
{ required: true, message: "ID必填", trigger: "blur" },
{ required: true, message: 'ID' + this.$t('commons.cannot_be_null'), trigger: "blur" },
{
max: 50,
message: this.$t("test_track.length_less_than") + "50",
@ -433,7 +433,7 @@ export default {
nodeId: [
{
required: true,
message: this.$t("test_track.case.input_module"),
message: this.$t("api_test.environment.module_warning"),
trigger: "change",
},
],
@ -451,6 +451,7 @@ export default {
demandList: [],
defaultModuleKey: '',
treeNodes: null,
validateTip: ''
};
},
props: {
@ -640,33 +641,55 @@ export default {
this.handleSaveEvent();
}
},
validateWithTip() {
this.validateTip = '';
//
if (!this.validateForm() | !this.validateCustomForm() | !this.validateCaseFrom()) {
if (this.validateTip) {
this.$error(this.validateTip.substring(0, this.validateTip.length - 1));
this.validateTip = '';
}
return false;
}
return true;
},
validateForm() {
let isValidate = true;
this.$refs["baseCaseFrom"].validate((valid) => {
this.$refs["baseCaseFrom"].validate((valid, msg) => {
if (!valid) {
isValidate = false;
this.recordTip(msg);
}
});
return isValidate;
},
validateCustomForm() {
let isValidate = true;
this.$refs["customFieldForm"].validate((valid) => {
this.$refs["customFieldForm"].validate((valid, msg) => {
if (!valid) {
isValidate = false;
this.recordTip(msg);
}
});
return isValidate;
},
validateCaseFrom() {
let isValidate = true;
this.$refs["caseFrom"].validate((valid) => {
this.$refs["caseFrom"].validate((valid, msg) => {
if (!valid) {
isValidate = false;
this.recordTip(msg);
}
});
return isValidate;
},
recordTip(msg) {
for (const field in msg) {
if (msg[field]) {
msg[field].forEach(item => this.validateTip += item.message + ',');
}
}
},
getCustomFields() {
let caseFromFields = this.$refs["caseFrom"].fields;
let customFields = this.$refs["customFieldForm"].fields;

View File

@ -372,7 +372,9 @@ export default {
this.$emit('importChangeConfirm', isSave);
},
closeExport() {
this.$refs.testCaseExport.close();
if (this.$refs.testCaseExport) {
this.$refs.testCaseExport.close();
}
}
}
};