diff --git a/src/views/Form_Demo3.vue b/src/views/Form_Demo3.vue index 375d5d5..23a4233 100644 --- a/src/views/Form_Demo3.vue +++ b/src/views/Form_Demo3.vue @@ -58,6 +58,7 @@ export default { name: "Form_Demo1", data() { + const that = this; return { form: { name: "", @@ -75,7 +76,24 @@ export default { {required: true, message: '请输入活动名称', trigger: 'blur'}, {min: 3, max: 10, message: '长度在3到10个字符', trigger: 'blur'}, {pattern: /^[a-zA-Z][a-zA-Z0-9_-]/, message: '活动名需要以字母开头,仅包含字母数字_-', trigger: 'blur'} - ] + ], + region: [{required: true, message: '请选择活动区域', trigger: 'change'}], + date1: [{required: true, message: '请选择活动日期', trigger: 'change'}], + date2: [ + {required: true, message: '请选择活动时间', trigger: 'change'}, + { + validator: (rule, value, callback) => { + const h = new Date(value).getHours() + if (that.form.type.includes('线下活动') && (h > 20 || h < 6)) { + return callback(new Error('线下活动不能夜间举行')) + } + return callback() + }, + trigger: 'change' + } + ], + type: [{required: true, type: 'array', message: '至少选择一个活动类型', trigger: 'change'}], + resource: [{required: true, message: '请选择活动资源', trigger: 'change'}] }, } }, @@ -106,4 +124,4 @@ export default { .text-center { text-align: center } - \ No newline at end of file +