// 表单校验规则由 schema2code 生成,不建议直接修改校验规则,而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema const validator = { "title": { "rules": [ { required:true, errorMessage:"请输入标题", }, { format: "string", errorMessage:"请输入正确的标题格式", } ], "title": "标题", "label": "标题" }, "content": { "rules": [ { required:true, errorMessage:"请输入内容", }, { format: "string", errorMessage:"请输入正确的内容格式", } ], "title": "内容", "label": "内容" }, "start_date": { "rules": [ { "format": "string" } ], "title": "开始时间", "label": "开始时间" }, "end_date": { "rules": [ { "format": "string" } ], "title": "结束时间", "label": "结束时间" }, "owner_id": { "rules": [ { "format": "string" } ], "title": "发布者id", "label": "发布者id" }, "background_picture": { "rules": [ { "format": "string" } ], "title": "背景图片", "label": "背景图片" }, "place": { "rules": [ { required:true, errorMessage:"请输入地点", }, { format: "string", errorMessage:"请输入正确的地点格式", } ], "title": "地点", "label": "地点" }, "status": { "rules": [ { "format": "int" } ], "title": "活动状态", "label": "活动状态" }, "participants": { "rules": [ { "format": "Number" } ], "title": "参与人数", "label": "参与人数" }, "contact": { "rules": [ { required:true, errorMessage:"请输入联系方式", }, { pattern:/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/, errorMessage:"请输入正确的联系方式", } ], "title": "联系方式", "label": "联系方式" }, "team_id": { "rules": [ { "format": "string" } ], "title": "小队id", "label": "小队id" } } const enumConverter = {} function filterToWhere(filter, command) { let where = {} for (let field in filter) { let { type, value } = filter[field] switch (type) { case "search": if (typeof value === 'string' && value.length) { where[field] = new RegExp(value) } break; case "select": if (value.length) { let selectValue = [] for (let s of value) { selectValue.push(command.eq(s)) } where[field] = command.or(selectValue) } break; case "range": if (value.length) { let gt = value[0] let lt = value[1] where[field] = command.and([command.gte(gt), command.lte(lt)]) } break; case "date": if (value.length) { let [s, e] = value let startDate = new Date(s) let endDate = new Date(e) where[field] = command.and([command.gte(startDate), command.lte(endDate)]) } break; case "timestamp": if (value.length) { let [startDate, endDate] = value where[field] = command.and([command.gte(startDate), command.lte(endDate)]) } break; } } return where } export { validator, enumConverter, filterToWhere }