(component): update

This commit is contained in:
就眠儀式 2022-08-09 10:00:52 +08:00
parent 716af194bd
commit ce92da5a95

View File

@ -92,22 +92,30 @@ const validate = (callback?: ValidateCallback) => {
if (props.prop && (ruleItems.value as RuleItem[]).length > 0) { if (props.prop && (ruleItems.value as RuleItem[]).length > 0) {
// //
const descriptor: Rules = {}; 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); const validator = new Schema(descriptor);
let model: { [key: string]: any } = {}; let model: { [key: string]: any } = {};
let validateMessage = null; let validateMessage = null;
// 使 // 使
if (layForm.useCN) { if (layForm.useCN) {
validateMessage = Object.assign({},cnValidateMessage,layForm.validateMessage validateMessage = Object.assign(
{},
cnValidateMessage,
layForm.validateMessage
); );
model[props.label || props.prop] = filedValue.value; model[props.label || props.prop] = filedValue.value;
} else { } else {
layForm.validateMessage && (validateMessage = layForm.validateMessage); layForm.validateMessage && (validateMessage = layForm.validateMessage);
model[props.prop] = filedValue.value; 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); validateMessage && validator.messages(validateMessage);
// //
@ -118,12 +126,13 @@ const validate = (callback?: ValidateCallback) => {
const _errors = errors as FieldValidateError[]; const _errors = errors as FieldValidateError[];
// , FieldValidateError // , FieldValidateError
layForm.useCN && layForm.useCN &&
_errors.forEach((error) => { _errors.forEach((error) => {
error.label = props.label; error.label = props.label;
error.field = props.prop; error.field = props.prop;
}); });
errorMsg.value = props.errorMessage ?? _errors[0].message; 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); callback && callback(_errors, fields);
} else { } else {
clearValidate(); clearValidate();
@ -160,7 +169,10 @@ onMounted(() => {
const getMarginLeft = computed(() => { const getMarginLeft = computed(() => {
if (props.mode == "block") { if (props.mode == "block") {
if (props.labelPosition != "top") { 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; labelWidth += 15;
return { return {
"margin-left": `${labelWidth}px`, "margin-left": `${labelWidth}px`,