From 039cd582e2bb49af7b3ad126c49ef988b7d8853f Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Wed, 18 Oct 2023 16:27:11 +0800 Subject: [PATCH] 页面结构组件,支持手动滚动 --- forms/form/CFormItem.vue | 54 +++++++++++++++++++++++++++++++----------------------- 1 files changed, 31 insertions(+), 23 deletions(-) diff --git a/forms/form/CFormItem.vue b/forms/form/CFormItem.vue index 3913dc1..1187f85 100644 --- a/forms/form/CFormItem.vue +++ b/forms/form/CFormItem.vue @@ -37,10 +37,13 @@ // transform (value) => any 将字段值转换成目标值后进行校验 // message string 错误信息,不设置时会通过模板自动生成 rules: Array, + // 表单是否禁用 + disabled: Boolean, }, data() { return { error: false, + errTimer: -1, }; }, computed: { @@ -50,6 +53,7 @@ name: this.name, label: this.label, required: this.isRequired, + disabled: this.disabled, error: this.error, onChange: evt => this.onChange(evt), }; @@ -94,34 +98,38 @@ [this.name]: evt, }); }, + $setError() { + this.error = true; + clearTimeout(this.errTimer); + this.errTimer = setTimeout(() => { + this.error = false; + }, 5000); + }, }, mounted() { this.$nextTick(() => { - // 未设置验证 - if (!this.required && !this.rules) { - this.formRes.$regItemValidator(this.name, validateType => { + // 注册验证 + this.formRes.$regItemValidator(this.name, validateType => { + // 未设置验证 + if (!this.required && !this.rules) { this.error = false; return Promise.resolve({ name: this.name, passed: true, }); - }); - } else { - // 验证规则 - const descriptor = this.rules || []; - if (this.required) { - descriptor.unshift({ - required: true, + } else { + // 验证规则 + const descriptor = this.rules || []; + if (this.required) { + descriptor.unshift({ + required: true, + }); + } + const validator = new Schema({ + [this.name]: descriptor, }); - } - const validator = new Schema({ - [this.name]: descriptor, - }); - // 汉化通用验证消息 - validator.messages(validateMsgs); - // 注册验证 - let errTimer = null; - this.formRes.$regItemValidator(this.name, validateType => { + // 汉化通用验证消息 + validator.messages(validateMsgs); return validator .validate({ [this.name]: this.formRes.formData[this.name], @@ -137,8 +145,8 @@ ({ errors, fields }) => { if (validateType !== 'msgOnly') { this.error = true; - clearTimeout(errTimer); - errTimer = setTimeout(() => { + clearTimeout(this.errTimer); + this.errTimer = setTimeout(() => { this.error = false; }, 5000); } @@ -152,8 +160,8 @@ }; } ); - }); - } + } + }); }); }, beforeDestroy() { -- Gitblit v1.9.1