mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-15 01:11:15 +08:00
e9f2e3a67f
* feat: 添加 json-schema 渲染器 * draft: 组件层添加 form 逻辑 * 补充组件form相关逻辑 * json-schema-editor 组件内部实现调整 * 添加 json-schema 渲染器 * 补充外部 value 变化更新成员的逻辑 * 补充外部 value 变化更新成员的逻辑 * 优化 json-schema 交互 * 修改 snapshot * 可能死循环 * 补充文档 * 优化逻辑 * 具备远程获取能力 * 固定值优化
138 lines
3.1 KiB
Markdown
138 lines
3.1 KiB
Markdown
---
|
|
title: JSONSchema
|
|
description:
|
|
type: 0
|
|
group: null
|
|
menuName: JSONSchema
|
|
icon:
|
|
order: 61
|
|
---
|
|
|
|
## 基本用法
|
|
|
|
> 1.10.0 及以上版本
|
|
|
|
> 此组件还在实验阶段,很多 json-schema 属性没有对应实现,使用前请先确认你要的功能满足了需求
|
|
|
|
基于 json-schema 定义生成表单输入项。
|
|
|
|
```schema: scope="body"
|
|
{
|
|
"type": "form",
|
|
"api": "/api/mock2/form/saveForm",
|
|
debug: true,
|
|
"body": [
|
|
{
|
|
"type": "json-schema",
|
|
"name": "value",
|
|
"label": "字段值",
|
|
"schema": {
|
|
type: 'object',
|
|
properties: {
|
|
id: {
|
|
type: 'number',
|
|
title: 'ID'
|
|
},
|
|
name: {
|
|
type: 'string',
|
|
title: '名称'
|
|
},
|
|
description: {
|
|
type: 'string',
|
|
title: '描述'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
## 复杂 case
|
|
|
|
```schema: scope="body"
|
|
{
|
|
"type": "form",
|
|
"api": "/api/mock2/form/saveForm",
|
|
debug: true,
|
|
"body": [
|
|
{
|
|
"type": "json-schema",
|
|
"name": "value",
|
|
"label": "字段值",
|
|
"schema": {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['id', 'name'],
|
|
properties: {
|
|
id: {
|
|
type: 'number',
|
|
title: 'ID'
|
|
},
|
|
name: {
|
|
type: 'string',
|
|
title: '名称'
|
|
},
|
|
description: {
|
|
type: 'string',
|
|
title: '描述'
|
|
},
|
|
date: {
|
|
type: 'object',
|
|
title: '日期',
|
|
additionalProperties: false,
|
|
required: ['year', 'month', 'day'],
|
|
properties: {
|
|
year: {
|
|
type: 'number',
|
|
title: '年'
|
|
},
|
|
month: {
|
|
type: 'number',
|
|
title: '月'
|
|
},
|
|
day: {
|
|
type: 'number',
|
|
title: '日'
|
|
}
|
|
}
|
|
},
|
|
tag: {
|
|
type: 'array',
|
|
title: '个人标签',
|
|
items: {
|
|
type: 'string'
|
|
},
|
|
minContains: 2,
|
|
maxContains: 10
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
## 远程获取 schema
|
|
|
|
```schema: scope="body"
|
|
{
|
|
"type": "form",
|
|
debug: true,
|
|
"body": [
|
|
{
|
|
"type": "json-schema",
|
|
"name": "value",
|
|
"label": "字段值",
|
|
"schema": "/api/mock2/json-schema"
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
## 属性表
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
| ------ | -------------------- | ------ | ---------------- |
|
|
| schema | `object` \| `string` | | 指定 json-schema |
|