From ce92da5a95a263a72a3a05198e36ebd22ec922aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E5=84=80=E5=BC=8F?= <854085467@qq.com> Date: Tue, 9 Aug 2022 10:00:52 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(component):=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/component/formItem/index.vue | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/package/component/src/component/formItem/index.vue b/package/component/src/component/formItem/index.vue index 68d9a6ca..f25239e8 100644 --- a/package/component/src/component/formItem/index.vue +++ b/package/component/src/component/formItem/index.vue @@ -92,22 +92,30 @@ const validate = (callback?: ValidateCallback) => { if (props.prop && (ruleItems.value as RuleItem[]).length > 0) { // 校验规则 const descriptor: Rules = {}; - descriptor[layForm.useCN ? props.label || props.prop : props.prop] = ruleItems.value; + descriptor[layForm.useCN ? props.label || props.prop : props.prop] = + ruleItems.value; const validator = new Schema(descriptor); let model: { [key: string]: any } = {}; let validateMessage = null; // 使用中文错误提示 if (layForm.useCN) { - validateMessage = Object.assign({},cnValidateMessage,layForm.validateMessage + validateMessage = Object.assign( + {}, + cnValidateMessage, + layForm.validateMessage ); model[props.label || props.prop] = filedValue.value; } else { layForm.validateMessage && (validateMessage = layForm.validateMessage); model[props.prop] = filedValue.value; } - // @ts-ignore 自定义消息验证 - layForm.requiredErrorMessage && (validateMessage = Object.assign(validateMessage, { required: layForm.requiredErrorMessage})); + // 自定义消息验证 + layForm.requiredErrorMessage && + // @ts-ignore + (validateMessage = Object.assign(validateMessage, { + required: layForm.requiredErrorMessage, + })); validateMessage && validator.messages(validateMessage); // 开始校验 @@ -118,12 +126,13 @@ const validate = (callback?: ValidateCallback) => { const _errors = errors as FieldValidateError[]; // 如果是中文,将错误信息转换成 FieldValidateError 类型 layForm.useCN && - _errors.forEach((error) => { - error.label = props.label; + _errors.forEach((error) => { + error.label = props.label; error.field = props.prop; }); errorMsg.value = props.errorMessage ?? _errors[0].message; - slotParentDiv.childElementCount > 0 && slotParentDiv.firstElementChild?.classList.add("layui-form-danger"); + slotParentDiv.childElementCount > 0 && + slotParentDiv.firstElementChild?.classList.add("layui-form-danger"); callback && callback(_errors, fields); } else { clearValidate(); @@ -160,7 +169,10 @@ onMounted(() => { const getMarginLeft = computed(() => { if (props.mode == "block") { if (props.labelPosition != "top") { - let labelWidth = typeof props.labelWidth === "string" ? parseFloat(props.labelWidth) : props.labelWidth; + let labelWidth = + typeof props.labelWidth === "string" + ? parseFloat(props.labelWidth) + : props.labelWidth; labelWidth += 15; return { "margin-left": `${labelWidth}px`,