From af17f22289f65c27a1a76eb3465ae13996144ff7 Mon Sep 17 00:00:00 2001 From: handongxun Date: Tue, 10 Nov 2020 14:28:14 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85schem=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=87=BD=E6=95=B0=E7=A4=BA=E4=BE=8B=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0enum=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/uniCloud/schema.md | 133 +++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 69 deletions(-) diff --git a/docs/uniCloud/schema.md b/docs/uniCloud/schema.md index ccb3c60ac2..f7a1621086 100644 --- a/docs/uniCloud/schema.md +++ b/docs/uniCloud/schema.md @@ -344,10 +344,39 @@ uniCloud推出了`openDB`开源数据库规范,包括用户表、文章表、 // value 当前规则校验数据 // data 全部校验数据 // callback 可选,一般用于自定义 errorMessage,如果执行了callback return 值无效,callback 传入的 message 将替换 errorMessage - // callback(new Error('message')) 传入 Error 类型时校验不通过 - // callback('message') 传入 String 类型时通过 + // callback('message') 传入错误消息时校验不通过 + // callback() 无参时通过 + // 注意 callback 不支持异步调用,异步请使用 Promise/await/async return value.length < 10 } + + // 异步校验 Promise + export = function (rule, value, data) { + return new Promise((resolve, reject) => { + setTimeout(() => { + if (value > 10) { + // 校验通过 + resolve() + } else { + // 校验失败 + resolve('error') // 等于 reject(new Error('error')) + // reject(new Error('error')) + } + }, 3000); + }) + } + + // 异步校验 await/async + export = async function (rule, value, data) { + let result = await uni.request({...}) + if (result > 10) { + // 校验通过 + return true + } else { + // 校验失败 + return 'error message' + } + } ``` 3. 在表结构 schema 编辑页面中的`validateFunction`属性中配置上面编写的 扩展校验函数 的名称,保存生效 @@ -478,7 +507,7 @@ errorMessage支持字符串,也支持json object。类型为object时,可定 }, "properties": { "_id":{}, - "name":{}, + "name":{}, "pwd": {} } } @@ -828,7 +857,7 @@ DCloud提供了`uni-forms`前端组件,该组件的校验规范完全符合`DB @@ -913,45 +942,41 @@ DCloud提供了`uni-forms`前端组件,该组件的校验规范完全符合`DB "bsonType": "array", "description": "爱好", "label": "爱好", - "component": { - "name": "checkbox-group", - "childrenData": [{ - "label": "游泳", - "value": 1 - }, - { - "label": "骑行", - "value": 2 - }, - { - "label": "音乐", - "value": 3 - }, - { - "label": "美术", - "value": 4 - } - ] - } + "enum": [ + { + "text": "游泳", + "value": 1 + }, + { + "text": "骑行", + "value": 2 + }, + { + "text": "音乐", + "value": 3 + }, + { + "text": "美术", + "value": 4 + } + ] }, "gender": { "bsonType": "int", - "enum": [0, 1, 2], "description": "用户性别:0 未知 1 男性 2 女性", "label": "性别", - "component": { - "name": "radio-group", - "childrenData": [{ - "label": "男", - "value": 1 - }, - { - "label": "女", - "value": 2 - } - ] - }, - "errorMessage": "{label}无效" + "errorMessage": "{label}无效", + "defaultValue": 0, + "enum": [{ + "text": "未知", + "value": 0 + }, { + "text": "男", + "value": 1 + }, { + "text": "女", + "value": 2 + }] }, "email": { "bsonType": "string", @@ -965,7 +990,7 @@ DCloud提供了`uni-forms`前端组件,该组件的校验规范完全符合`DB "label": "自定义children", "component": { "name": "select", - "children": "", + "children": "", "childrenData": [{"label": "中文简体", "value": "zh-cn"}] } } @@ -974,36 +999,6 @@ DCloud提供了`uni-forms`前端组件,该组件的校验规范完全符合`DB ``` -component 类型为数组 - -```json -{ - "bsonType": "object", - "required": [], - "properties": { - "mobile": { - "bsonType": "string", - "label": "多个组件", - "component": [ - { - "name": "input", - "props": { - "placeholder": "电话1" - } - }, - { - "name": "input", - "props": { - "placeholder": "电话2" - } - } - ] - } - } -} -``` - - #### group属性 将多个表单项合并在一个分组里显示。前端渲染时,group相同的表单项会自动合并在一个uni-group组件中,不同分组的表单项之间有间隔。该组件详见:[https://ext.dcloud.net.cn/plugin?id=3281](https://ext.dcloud.net.cn/plugin?id=3281) -- GitLab