✨(component): update
This commit is contained in:
parent
e05781963d
commit
716af194bd
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@layui/layui-vue",
|
||||
"version": "1.4.0",
|
||||
"version": "1.4.0-alpha.1",
|
||||
"author": "就眠儀式",
|
||||
"license": "MIT",
|
||||
"description": "a component library for Vue 3 base on layui-vue",
|
||||
|
@ -60,7 +60,6 @@ const ruleItems = computed(() => {
|
||||
if (!prop) {
|
||||
return {};
|
||||
}
|
||||
|
||||
let rulesArrs: RuleItem[] = [];
|
||||
if (isRequired.value) {
|
||||
rulesArrs.push({ required: true });
|
||||
@ -78,6 +77,7 @@ const ruleItems = computed(() => {
|
||||
const filedValue = computed(() =>
|
||||
props.prop ? layForm.model[props.prop] : undefined
|
||||
);
|
||||
|
||||
watch(
|
||||
() => filedValue.value,
|
||||
(val) => validate(),
|
||||
@ -92,29 +92,22 @@ 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;
|
||||
}
|
||||
// 自定义校验消息
|
||||
layForm.requiredErrorMessage &&
|
||||
(validateMessage = Object.assign(validateMessage, {
|
||||
required: layForm.requiredErrorMessage,
|
||||
}));
|
||||
// @ts-ignore 自定义消息验证
|
||||
layForm.requiredErrorMessage && (validateMessage = Object.assign(validateMessage, { required: layForm.requiredErrorMessage}));
|
||||
validateMessage && validator.messages(validateMessage);
|
||||
|
||||
// 开始校验
|
||||
@ -123,15 +116,14 @@ const validate = (callback?: ValidateCallback) => {
|
||||
const slotParentDiv = slotParent.value as HTMLDivElement;
|
||||
if (errorStatus.value) {
|
||||
const _errors = errors as FieldValidateError[];
|
||||
// 如果是中文,将错误信息转换成FieldValidateError类型
|
||||
// 如果是中文,将错误信息转换成 FieldValidateError 类型
|
||||
layForm.useCN &&
|
||||
_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();
|
||||
@ -168,10 +160,7 @@ 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`,
|
||||
|
@ -402,7 +402,6 @@ let scrollWidthCell = ref(0);
|
||||
const getScrollWidth = () => {
|
||||
const clientWidth: number = tableBody.value?.clientWidth || 0;
|
||||
const offsetWidth: number = tableBody.value?.offsetWidth || 0;
|
||||
|
||||
if (clientWidth < offsetWidth) {
|
||||
scrollWidthCell.value = offsetWidth - clientWidth;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user