Appearance
数据协议规则文档
基础概念
页面结构的 JSON 格式,称为 FormJSON,用于描述创建页面的整体结构,包含样式。
数据结构的 JSON 格式,称为 SchemaJSON,是 FormJSON 的简版,用于描述数据库以及字段的相关格式,验证规则,关联关系,个性化配置等信息。
总体流程:
用户前端拖拉拽创建数据表单形成 FormJSON->调用 Schema 服务->转成 SchemaJSON->调用表结构服务->生成实际的数据库表
FormJSON 结构
结构示例
json
{
"list": [
{
"name": "标题",
"type": "title",
"icon": "icon-input",
"options": {
"width": "",
"defaultValue": "",
"required": false,
"requiredMessage": "",
"dataType": "",
"dataTypeCheck": false,
"dataTypeMessage": "",
"pattern": "",
"patternCheck": false,
"patternMessage": "",
"validatorCheck": false,
"validator": "",
"placeholder": "",
"customClass": "",
"disabled": false,
"labelWidth": 100,
"isLabelWidth": false,
"hidden": false,
"dataBind": true,
"showPassword": false,
"clearable": false,
"maxlength": "",
"showWordLimit": false,
"customProps": {},
"tip": "",
"alignRight": false,
"remoteFunc": "func_m4ix31rj",
"remoteOption": "option_m4ix31rj",
"tableColumn": false,
"subform": false,
"isDynamicValue": false,
"dynamicValueType": "datasource"
},
"events": {
"onChange": "",
"onFocus": "",
"onBlur": ""
},
"key": "m4ix31rj",
"model": "title_m4ix31rj",
"rules": []
}
],
"config": {
"labelWidth": 100,
"labelPosition": "right",
"size": "small",
"customClass": "",
"ui": "element",
"layout": "horizontal",
"width": "100%",
"hideLabel": false,
"hideErrorMessage": false,
"platform": "pc",
"eventScript": []
}
}
FormJSON 包含两大块,
1、组件列表,list 。
list 中包含 0 到多个组件属性的描述。
2、表单属性 config。
config 中包含表单属性的描述。
组件属性
属性 | 类型 | 描述 |
---|---|---|
name | String | 标题 |
type | String | 组件的类型 |
icon | String | 组件相关的图标 |
options | Object | 该组件的具体配置选项 |
events | Object | 对于该组件事件的处理规则 |
key | String | 唯一标识 |
model | String | 组件类型_key |
rules | Object | 验证规则,用于规定该组件输入数据的校验条件 |
组件 options 属性
属性 | 类型 | 描述 |
---|---|---|
width | String | 组件的宽度 |
defaultValue | String | 默认值 |
required | Boolean | 是否必填 |
requiredMessage | String | 当组件为必填时,自定义出错提示 |
dataType | String | 数据类型,url、email 等 |
dataTypeMessage | String | 数据类型校验失败后的提示 |
pattern | String | 用于输入验证的正则表达式模式 |
patternMessage | String | 正则校验出错时的提示 |
validatorCheck | Boolean | 是否自定义校验规则 |
validator | String | 自定义校验规则 |
placeholder | String | 占位符 |
customClass | String | 自定义类 |
disabled | Boolean | 是否显示 |
labelWidth | int | 标签宽度 |
isLabelWidth | Boolean | 是否显示标签 |
hidden | Boolean | 是否隐藏 |
dataBind | Boolean | 是否绑定数据 |
showPassword | Boolean | 是否为密码框 |
clearable | Boolean | 是否显示清楚按钮 |
maxlength | int | 最大长度 |
showWordLimit | Boolean | |
customProps | Object | |
tip | String | 提示说明文字 |
alignRight | Boolean | |
remoteFunc | String | |
remoteOption | String | |
tableColumn | Boolean | |
subform | Boolean | |
isDynamicValue | Boolean | |
dynamicValueType | String |
表单属性
属性 | 类型 | 描述 |
---|---|---|
labelWidth | int | 标签宽度 |
labelPosition | string | 标签对齐方式 left right top |
size | string | 组件尺寸 large default small |
customClass | 自定义样式的 key | |
ui | ||
layout | ||
width | ||
hideLabel | ||
hideErrorMessage | ||
platform | ||
eventScript |
SchemaJSON 结构
结构示例
json
{
"bsonType": "object",
"persistField": true,
"properties": {
"id": {
"bsonType": "bigint",
"description": "主键ID",
"idType": 3,
"isRequired": true,
"key": "7y37biq3",
"name": "id",
"persistField": true,
"primaryKey": true,
"title": "主键ID",
"type": "number"
},
"input_usmzqxkg": {
"bsonType": "string",
"defaultValue": "",
"description": "单行文本",
"errorMessage": {
"required": ""
},
"isRequired": false,
"key": "usmzqxkg",
"name": "input_usmzqxkg",
"persistField": true,
"title": "单行文本",
"type": "string"
},
"create_user": {
"bsonType": "bigint",
"description": "创建人",
"enum": {
"collection": "blade_user",
"field": "id as value, real_name as text"
},
"forceDefaultValue": {
"$env": "uid",
"update": false
},
"foreignKey": "blade_user.id",
"key": "56jzmrh5",
"name": "create_user",
"persistField": true,
"title": "创建人",
"type": "number"
},
"create_dept": {
"bsonType": "bigint",
"description": "创建部门",
"enum": {
"collection": "blade_user",
"field": "id as value, real_name as text"
},
"forceDefaultValue": {
"$env": "did",
"update": false
},
"foreignKey": "blade_dept.id",
"key": "0sgbkln8",
"name": "create_dept",
"persistField": true,
"title": "创建部门",
"type": "number"
},
"create_time": {
"bsonType": "date",
"description": "创建时间",
"forceDefaultValue": {
"$env": "now",
"update": false
},
"format": "date",
"key": "pxjduric",
"name": "create_time",
"persistField": true,
"title": "创建时间",
"type": "string"
},
"update_user": {
"bsonType": "bigint",
"description": "更新人",
"enum": {
"collection": "blade_user",
"field": "id as value, real_name as text"
},
"forceDefaultValue": {
"$env": "uid"
},
"foreignKey": "blade_user.id",
"key": "fpjyd6kb",
"name": "update_user",
"persistField": true,
"title": "更新人",
"type": "number"
},
"update_time": {
"bsonType": "date",
"description": "修改时间",
"forceDefaultValue": {
"$env": "now",
"update": true
},
"format": "date",
"key": "t11huk7x",
"name": "update_time",
"persistField": true,
"title": "修改时间",
"type": "string"
},
"is_deleted": {
"bsonType": "int",
"defaultValue": 0,
"description": "删除状态",
"forceDefaultValue": 0,
"key": "jnfrlvv8",
"name": "is_deleted",
"persistField": true,
"systemKey": true,
"title": "删除状态",
"type": "integer"
},
"tenant_id": {
"bsonType": "string",
"description": "租户Id",
"forceDefaultValue": {
"$env": "tid",
"update": false
},
"key": "qjguwboi",
"name": "tenant_id",
"persistField": true,
"systemKey": true,
"title": "租户Id",
"type": "string"
}
},
"type": "object"
}
BsonType 与 Type
BsonType 类型 | type(JsonType 用于字段验证) | 描述 |
---|---|---|
bool | boolean | 布尔值 |
string | string | 字符串 |
password | string | 密码 |
int | integer | 整数 |
double | number | 小数 |
object | object | 对象 |
file | object | 文件对象 |
array | array | 数组 |
timestamp | integer | 时间戳 |
date | date | 日期 |
time | string | 时间 |
objectId | string | Mongodb 主键类型 |
bigint | number | 长整数 |
结构框架
属性 | 类型 | 描述 |
---|---|---|
bsonType | String | 默认为 object |
persistField | Boolean | 是否持久化 |
properties | Object | 具体配置项 |
type | String | 默认为 object |
required |
Properties 中的字段结构
属性 | 类型 | 描述 |
---|---|---|
key1 | String | 前端组件唯一标识 |
title | String | 字段中文名 |
name | String | 字段英文名 |
bsonType | String | 数据类型 |
arrayType | String | 当bsonType是array时,array中的bsonType |
type | String | Json Scheam类型,用于数据格式验证 |
primaryKey | Boolean | 是否是数据库主键 |
titleKey | Boolean | 是否是标题字段(标题组件,会自动设置titleKey为true) |
systemKey | Boolean | 是否是系统生成字段,如ID,创建人,更新人等字段为true |
uniqueKey | Boolean | 唯一不能重复 |
historyKey | Boolean | 记录修改历史字段 |
encryptedKey | Boolean | 加密字段 |
encryptionAlgorithm | String | 加密算法 |
immutableKey | Boolean | 新增后不可变字段 |
persistField | Boolean | 是否持久化,为true时,应对数据库中某张表的一列 |
showType | String | 显示类型,当是时间组件的时候,存放 |
defaultValue | String | 默认值 |
forceDefaultValue | String | 强制默认值,不可通过DB命令的代码修改,常用于存放用户id、时间、客户端ip等固定值 |
description | String | 描述 |
isRequired | Boolean | 是否必须,默认为false |
trim | String | 去除空白字符,支持 none|both|start|end,默认none,仅bsonType="string"时有效 |
pattern | String | 正则表达式,如设置为手机号的正则表达式后,不符合该正则表达式则校验失败,无法入库 |
format | String | 数据格式,不符合格式的数据无法入库。目前只支持'url'和'email',未来会扩展其他格式 |
mutiple | Boolean | 是否多选,如果是关联其他表,并且是多选,则会生成和关联表关联的第三方中间表 |
validator | String | 自定义JS方法验证 |
enum | Object 或 Array | |
静态基础类型数据 | Array | "enum": [0,1,2] |
静态字典类型数据 | Array | 例如: "enum": [{ "text": "待同步", "value": "Stay" }, { "text": "同步中", "value": "Have" }, { "text": "已同步", "value": "Already" }] |
表关联关系 | Object | 示例 "enum": { "collection": "su_code_data_sources", "field": "id as value, name as text" } |
enumType | String | 字段值枚举类型,可选值tree。设为tree时,代表enum里的数据为树形结构。此时schema2code可生成多级级联选择组件 |
junctionTableName | String | 当enum类型是表关联关系时,foreignKey指向关联表的关联字段 |
parentKey | String | 如果表结构是树类型时,parentKey指向父子级存储的key |
parentSelf | Boolean | parent是自己,自关联 |
errorMessage | Object | 自定义错误对象 |
required | String | {title}不能为空 |
minLength | String | {title}不能小于 {minLength} 个字符 |
format | String | 格式不正确提示 |
pattern | String | 正则不匹配提示 |
fileMediaType | String | 文件类型,bsonType="file" 时有效,可选值 all|image|video 默认值为all,表示所有文件,image表示图片类型文件,video表示视频类型文件 |
fileExtName | String | 文件扩展名过滤,bsonType="file" 时有效,多个文件扩展名用 "," 分割,例如: jpg,png |
maximum | Number | 如果bsonType为数字时,可接受的最大值 |
exclusiveMaximum | Boolean | 是否排除 maximum也就是小于最大值,还是小于等于最大值 |
minimum | Number | 如果bsonType为数字时,可接受的最小值 |
exclusiveMinimum | Boolean | 是否排除 minimum |
minLength | Integer | 限制字符串或数组的最小长度 |
maxLength | Integer | 限制字符串或数组的最大长度 |
component | Object | 组件对象(用于存储自定义的组件参数,用于个性化业务逻辑) |
name | String | 组件名称 |
props | JSONObject | 组件的配置字段 |
precision | Integer | 精度(小数点后的位数),当bsonTyep是double的时候有效 |
FormJSON->SchemaJSON映射
基础属性映射关系:
FormJSON属性 | SchemaJSON属性 | 描述 |
---|---|---|
name | title | 组件名称 |
model | name | 通过FromJSON中组件的model属性,可以在ScheemaJSON中找到同名对象,该对象描述记录了这个组件的SchemaJSON |
type | bsonType | 见"type与bsontype映射关系" |
key | key | 关键组 |
options.defaultValue | defaultValue | 默认值 |
options.min | minimum | 最小数值 |
options.max | maximum | 最大数值 |
options.precision | ++bsonType++ | 已计数器为例,当FormJSON中options.precision等于0时,SchemaJSON 中bsonType为int,options.precision大于0时,SchemaJSON 中bsonType为double |
options.rules | errorMessage | 当 FormJSON中rules属性中required值为true时,message值映射到 SchemaJSON properties.[key].errorMessage对象中的required |
options.rules.required | isRequired | rules中的required |
options.value | parentKey | 当FormJSON,type是tree组件的时,取options.value放入 |
options.remoteInnerDataSource+"."+options.props.value | foreignKey | 当设置为动态数据源时,foreignKey的设置公式 |
options.pattern | pattern | 正则 |
format | ||
options.validator | validator | |
options.multiple | multiple | |
FormJSON type与SchemaJSON bsonType/type映射关系
FormJSON type | SchemaJSON bsonType | SchemaJSON type | 描述 |
---|---|---|---|
input | string | string | 单行文本框 |
input | password | string | 密码框。FormJSON中showPassword为true时 |
title | string | string | 标题 |
textarea | string | string | 多行文本 |
number | int/double | number | 计数器 |
radio | string | string | 单选框组 |
checkbox | array(arrayType: string) | array | 多选框组 |
select | string | string | 下拉选择框 |
time | time | string | 时间选择器 |
date | date | string | 日期选择器 |
rate | int | integer | 评分 |
color | string | string | 颜色选择器 |
switch | int | integer | 开关 |
slider | int | integer | 滑块 |
text | string | string | 文字 |
html | string | string | HTML |
link | string | string | 文字链接 |
cascader | array | array | 级联选择器 |
treeselect | string | string | 树选择 |
steps | int | integer | 步骤条 |
transfer | array | array | 穿梭框 |
fileupload | array(arrayType: file) | array | 文件 |
imgupload | array(arrayType: file) | array | 图片 |
table | array(arrayType: object) | 无 | 子表单 |
subform | array(arrayType: object) | 无 | 子表单+ |
group | object | ||
button | 无 | 无 | 按钮 |
segmented | 无 | 无 | 分段器 |
SchemaJSON->数据库映射
SchemaJSON属性 | 数据库属性 | 描述 |
---|---|---|
properties.[key] | COLUMN_NAME | |
properties.[key].bsonType | DATA_TYPE 见SchemaJSON bsonType 与数据库字段类型映射关系 | |
properties.[key].defaultValue | COLUMN_DEFAULT | |
properties.[key].description | COLUMN_COMMENT | |
properties.[key].errorMessage | 无 | |
properties.[key].isRequired | 无 | 没有跟数据库IS_NULLABLE关联 |
properties.[key].key | 无 | |
properties.[key].name | 同properties.[key] | |
properties.[key].persistField | 无 | false 代表无需生成数据库字段 |
properties.[key].title | 无 | |
properties.[key].type | 无 |
SchemaJSON bsonType 与数据库字段类型映射关系(常规)
SchemaJSON bsonType | 数据库字段类型及默认值 |
---|---|
string | varchar(255) |
int | int |
array | varchar(255) |
date | timestamp |
time | time |
SchemaJSON bsonType 与数据库字段类型映射关系(特殊)
FormJSON type | SchemaJSON bsonType | 数据库字段类型 |
---|---|---|
transfer | array | json |
fileupload | array(arrayType: file) | json |
imgupload | array(arrayType: file) | json |
table | array | json |
subform | array | json |
input | string | maxlength>5000时,数据库字段类型为text,超出text类型最大范围无效; maxlength<=5000时,数据库字段类型为varchar(maxlength) |