Skip to content

数据协议规则文档

基础概念

页面结构的 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 中包含表单属性的描述。

组件属性

属性类型描述
nameString标题
typeString组件的类型
iconString组件相关的图标
optionsObject该组件的具体配置选项
eventsObject对于该组件事件的处理规则
keyString唯一标识
modelString组件类型_key
rulesObject验证规则,用于规定该组件输入数据的校验条件

组件 options 属性

属性类型描述
widthString组件的宽度
defaultValueString默认值
requiredBoolean是否必填
requiredMessageString当组件为必填时,自定义出错提示
dataTypeString数据类型,url、email 等
dataTypeCheckBoolean是否校验数据类型
dataTypeMessageString数据类型校验失败后的提示
patternString用于输入验证的正则表达式模式
patternCheckBoolean是否正则校验
patternMessageString正则校验出错时的提示
validatorCheckBoolean是否自定义校验规则
validatorString自定义校验规则
placeholderString占位符
customClassString自定义类
disabledBoolean是否显示
labelWidthint标签宽度
isLabelWidthBoolean是否显示标签
hiddenBoolean是否隐藏
dataBindBoolean是否绑定数据
showPasswordBoolean是否为密码框
clearableBoolean是否显示清楚按钮
maxlengthint最大长度
showWordLimitBoolean
customPropsObject
tipString提示说明文字
alignRightBoolean
remoteFuncString
remoteOptionString
tableColumnBoolean
subformBoolean
isDynamicValueBoolean
dynamicValueTypeString

表单属性

属性类型描述
labelWidthint标签宽度
labelPositionstring标签对齐方式  left right top
sizestring组件尺寸  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 用于字段验证)描述
boolboolean布尔值
stringstring字符串
passwordstring密码
intinteger整数
doublenumber小数
objectobject对象
fileobject文件对象
arrayarray数组
timestampinteger时间戳
datedate日期
timestring时间
objectIdstringMongodb 主键类型
bigintnumber长整数

结构框架

属性类型描述
bsonTypeString默认为 object
persistFieldBoolean是否持久化
propertiesObject具体配置项
typeString默认为 object
required

Properties 中的字段结构

属性类型描述
key1String前端组件唯一标识
titleString字段中文名
nameString字段英文名
bsonTypeString数据类型
arrayTypeString当bsonType是array时,array中的bsonType
typeStringJson Scheam类型,用于数据格式验证
primaryKeyBoolean是否是数据库主键
titleKeyBoolean是否是标题字段(标题组件,会自动设置titleKey为true)
systemKeyBoolean是否是系统生成字段,如ID,创建人,更新人等字段为true
uniqueKeyBoolean唯一不能重复
historyKeyBoolean记录修改历史字段
encryptedKeyBoolean加密字段
encryptionAlgorithmString加密算法
immutableKeyBoolean新增后不可变字段
persistFieldBoolean是否持久化,为true时,应对数据库中某张表的一列
showTypeString显示类型,当是时间组件的时候,存放
defaultValueString默认值
forceDefaultValueString强制默认值,不可通过DB命令的代码修改,常用于存放用户id、时间、客户端ip等固定值
descriptionString描述
isRequiredBoolean是否必须,默认为false
trimString去除空白字符,支持 none|both|start|end,默认none,仅bsonType="string"时有效
patternString正则表达式,如设置为手机号的正则表达式后,不符合该正则表达式则校验失败,无法入库
formatString数据格式,不符合格式的数据无法入库。目前只支持'url'和'email',未来会扩展其他格式
mutipleBoolean是否多选,如果是关联其他表,并且是多选,则会生成和关联表关联的第三方中间表
validatorString自定义JS方法验证
enumObject 或 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"     }
enumTypeString字段值枚举类型,可选值tree。设为tree时,代表enum里的数据为树形结构。此时schema2code可生成多级级联选择组件
junctionTableNameString当enum类型是表关联关系时,foreignKey指向关联表的关联字段
parentKeyString如果表结构是树类型时,parentKey指向父子级存储的key
parentSelfBooleanparent是自己,自关联
errorMessageObject自定义错误对象
requiredString{title}不能为空
minLengthString{title}不能小于 {minLength} 个字符
formatString格式不正确提示
patternString正则不匹配提示
fileMediaTypeString文件类型,bsonType="file" 时有效,可选值 all|image|video 默认值为all,表示所有文件,image表示图片类型文件,video表示视频类型文件
fileExtNameString文件扩展名过滤,bsonType="file" 时有效,多个文件扩展名用 "," 分割,例如: jpg,png
maximumNumber如果bsonType为数字时,可接受的最大值
exclusiveMaximumBoolean是否排除 maximum也就是小于最大值,还是小于等于最大值
minimumNumber如果bsonType为数字时,可接受的最小值
exclusiveMinimumBoolean是否排除 minimum
minLengthInteger限制字符串或数组的最小长度
maxLengthInteger限制字符串或数组的最大长度
componentObject组件对象(用于存储自定义的组件参数,用于个性化业务逻辑)
nameString组件名称
propsJSONObject组件的配置字段
precisionInteger精度(小数点后的位数),当bsonTyep是double的时候有效

FormJSON->SchemaJSON映射

基础属性映射关系:

FormJSON属性SchemaJSON属性描述
nametitle组件名称
modelname通过FromJSON中组件的model属性,可以在ScheemaJSON中找到同名对象,该对象描述记录了这个组件的SchemaJSON
typebsonType见"type与bsontype映射关系"
keykey关键组
options.defaultValuedefaultValue默认值
options.minminimum最小数值
options.maxmaximum最大数值
options.precision++bsonType++已计数器为例,当FormJSON中options.precision等于0时,SchemaJSON 中bsonType为int,options.precision大于0时,SchemaJSON 中bsonType为double
options.ruleserrorMessage当 FormJSON中rules属性中required值为true时,message值映射到 SchemaJSON properties.[key].errorMessage对象中的required
options.rules.requiredisRequiredrules中的required
options.valueparentKey当FormJSON,type是tree组件的时,取options.value放入
options.remoteInnerDataSource+"."+options.props.valueforeignKey当设置为动态数据源时,foreignKey的设置公式
options.patternpattern正则
format
options.validatorvalidator
options.multiplemultiple

FormJSON type与SchemaJSON bsonType/type映射关系

FormJSON typeSchemaJSON bsonTypeSchemaJSON type描述
inputstringstring单行文本框
inputpasswordstring密码框。FormJSON中showPassword为true时
titlestringstring标题
textareastringstring多行文本
numberint/doublenumber计数器
radiostringstring单选框组
checkboxarray(arrayType: string)array多选框组
selectstringstring下拉选择框
timetimestring时间选择器
datedatestring日期选择器
rateintinteger评分
colorstringstring颜色选择器
switchintinteger开关
sliderintinteger滑块
textstringstring文字
htmlstringstringHTML
linkstringstring文字链接
cascaderarrayarray级联选择器
treeselectstringstring树选择
stepsintinteger步骤条
transferarrayarray穿梭框
fileuploadarray(arrayType: file)array文件
imguploadarray(arrayType: file)array图片
tablearray(arrayType: object)子表单
subformarray(arrayType: object)子表单+
groupobject
button按钮
segmented分段器

SchemaJSON->数据库映射

SchemaJSON属性数据库属性描述
properties.[key]COLUMN_NAME
properties.[key].bsonTypeDATA_TYPE 见SchemaJSON bsonType 与数据库字段类型映射关系
properties.[key].defaultValueCOLUMN_DEFAULT
properties.[key].descriptionCOLUMN_COMMENT
properties.[key].errorMessage
properties.[key].isRequired没有跟数据库IS_NULLABLE关联
properties.[key].key
properties.[key].name同properties.[key]
properties.[key].persistFieldfalse 代表无需生成数据库字段
properties.[key].title
properties.[key].type

SchemaJSON bsonType 与数据库字段类型映射关系(常规)

SchemaJSON bsonType数据库字段类型及默认值
stringvarchar(255)
intint
arrayvarchar(255)
datetimestamp
timetime

SchemaJSON bsonType 与数据库字段类型映射关系(特殊)

FormJSON typeSchemaJSON bsonType数据库字段类型
transferarrayjson
fileuploadarray(arrayType: file)json
imguploadarray(arrayType: file)json
tablearrayjson
subformarrayjson
inputstringmaxlength>5000时,数据库字段类型为text,超出text类型最大范围无效; maxlength<=5000时,数据库字段类型为varchar(maxlength)