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 b58d973cf3
commit 7cb2cc70e3
4 changed files with 38 additions and 33 deletions

View File

@ -275,7 +275,9 @@ export default {
} }
}, },
setScrollToBottom() { 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: "", method: "",
prerequisite: "", prerequisite: "",
testId: "", testId: "",
nodeId: '',
steps: [ steps: [
{ {
num: 1, num: 1,
@ -1539,31 +1540,8 @@ export default {
} }
}); });
} }
let detailForm = this.$refs.otherInfo.validateForm(); if (!this.$refs.testCaseBaseInfo.validateWithTip()) {
let baseInfoValidate = this.$refs.testCaseBaseInfo.validateForm() && this.$refs.testCaseBaseInfo.validateCaseFrom(); isValidate = false;
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;
} }
return isValidate; return isValidate;
}, },

View File

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

View File

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