vendor: amis 6.13.0 base (fork root)

This commit is contained in:
2026-06-16 22:14:57 +08:00
commit 8c8e4247a9
3840 changed files with 2467374 additions and 0 deletions

View File

@@ -0,0 +1,451 @@
---
title: Button-Group-Select 按钮点选
description:
type: 0
group: null
menuName: Button-Group-Select
icon:
order: 6
---
## 基本用法
按钮集合当 select 点选用。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
]
}
]
}
```
## 垂直模式
配置`"vertical": true`,实现垂直模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"vertical": true,
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
]
}
]
}
```
## 平铺模式
配置 `"tiled": true` 实现平铺模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"tiled": true,
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
]
}
]
}
```
## 按钮主题样式
配置 `btnLevel` 统一设置按钮主题样式,注意 `buttons ` 或 `options` 中的`level`属性优先级高于`btnLevel`。配置 `btnActiveLevel` 为按钮设置激活态时的主题样式。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"btnLevel": "light",
"btnActiveLevel": "warning",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c",
"level": "primary"
}
]
}
]
}
```
## 支持角标
按钮可支持角标,在 options 中配置
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b",
"badge": {
"mode": "text",
"text": 15
}
},
{
"label": "Option C",
"value": "c",
"badge": {
"mode": "ribbon",
"text": "HOT"
}
}
]
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| -------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------- | ------- |
| type | `string` | `"button-group-select"` | 指定为 button-group-select 渲染器 |
| vertical | `boolean` | `false` | 是否使用垂直模式 |
| tiled | `boolean` | `false` | 是否使用平铺模式 |
| btnLevel | `'link' \| 'primary' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | `"default"` | 按钮样式 |
| btnActiveLevel | `'link' \| 'primary' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | `"default"` | 选中按钮样式 |
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
| option.badge | `object` | | [角标](../badge#属性表) | `2.8.1` |
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
| multiple | `boolean` | `false` | [多选](./options#%E5%A4%9A%E9%80%89-multiple) |
| labelField | `boolean` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
| valueField | `boolean` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
| autoFill | `object` | | [自动填充](./options#%E8%87%AA%E5%8A%A8%E5%A1%AB%E5%85%85-autofill) |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | ---------------- |
| change | `[name]: string` 组件的值 | 选中值变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
],
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
| setValue | `value: string` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"id": "clear_type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
],
"value": "b"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_type"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"data": {
"abc": {
"type": "c"
}
},
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"id": "reset_type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
],
"value": "b"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_type"
}
]
}
}
}
]
}
```
### reload
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"id": "reload_type",
"source": "/api/mock2/form/getOptions?waitSeconds=1"
},
{
"type": "button",
"label": "重新加载",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reload",
"componentId": "reload_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "button-group-select",
"label": "选项",
"name": "type",
"id": "setvalue_type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
],
"value": "b"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_type",
"args": {
"value": "c"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,59 @@
---
title: Button-Toolbar 按钮工具栏
description:
type: 0
group: null
menuName: Button-Toolbar
icon:
order: 5
---
默认按钮会独占一行,如果想让多个按钮并排方式,可以使用 `button-toolbar` 组件包裹起来,另外还有能用 [button-group](./button-group) 来在展现上更紧凑。
## 基本使用
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-text",
"name": "test",
"label": "Text"
},
{
"type": "button-toolbar",
"label": "按钮组",
"buttons": [
{
"type": "button",
"label": "按钮",
"actionType": "dialog",
"dialog": {
"title": "提示",
"body": "对,你刚点击了!"
}
},
{
"type": "submit",
"label": "提交"
},
{
"type": "reset",
"label": "重置"
}
]
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| ------- | --------------------------- | ------------------ | ------------------------- |
| type | `string` | `"button-toolbar"` | 指定为 ButtonToolbar 组件 |
| buttons | Array<[行为按钮](./action)> | | 按钮组 |

View File

@@ -0,0 +1,246 @@
---
title: Chained-Select 链式下拉框
description:
type: 0
group: null
menuName: Chained-Select
icon:
order: 7
---
## 基本用法
用于实现无限级别下拉,只支持单选,且必须和 `source` 搭配,通过 API 拉取数据,只要 API 有返回结果,就能一直无限级别下拉。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "select3",
"type": "chained-select",
"label": "链式下拉",
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
"value": "a,b"
}
]
}
```
> `source`接口中配置的参数`waitSeconds=1`和`maxLevel=4`是测试接口所需参数,实际使用自己接口时不需要添加这两个参数
## 暴露参数
为了帮助后端接口获取当前选择器状态,chained-select 会默认给 source 接口的数据域中,添加若干个参数:
- `value`: 选中的表单项值;
- `level`: 当前拉取数据时的层级,
- `parentId`: 上一级选项的值,数据格式基于配置的`joinValues`和`extractValue`属性
- `parent`: 上一级选项的完整的数据格式
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------ | ----------------------------------------- | --------- | ------------------------------------------------------------------------------------------- |
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
| autoComplete | `string`或 [API](../../../docs/types/api) | | [自动选中](./options#%E8%87%AA%E5%8A%A8%E8%A1%A5%E5%85%A8-autocomplete) |
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
| labelField | `boolean` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
| valueField | `boolean` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | ---------------- |
| change | `[name]: string` 组件的值 | 选中值变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "select3",
"type": "chained-select",
"label": "链式下拉",
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
"value": "a,b",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
| setValue | `value: string` 更新的值 | 更新数据,多个值用`,`分隔 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "type",
"id": "clear_type",
"type": "chained-select",
"label": "链式下拉",
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
"value": "a,b"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_type"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "type",
"id": "reset_type",
"type": "chained-select",
"label": "链式下拉",
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
"value": "a,b"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_type"
}
]
}
}
}
]
}
```
### reload
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "type",
"id": "reload_type",
"type": "chained-select",
"label": "链式下拉",
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
"value": "a,b"
},
{
"type": "button",
"label": "重新加载",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reload",
"componentId": "reload_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "type",
"id": "setvalue_type",
"type": "chained-select",
"label": "链式下拉",
"source": "/api/mock2/options/chainedOptions?waitSeconds=1&parentId=$parentId&level=$level&maxLevel=4",
"value": "a,b"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_type",
"args": {
"value": "c"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,57 @@
---
title: ChartRadios 图表单选框
description:
type: 0
group: ⚙ 组件
menuName: ChartRadios 图表单选框
icon:
order: 34
---
图表点选功能,用来做多个图表联动。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "chart-radios",
name: 'main',
chartValueField: 'num',
"options": [
{
"label": "A",
"num": 100,
value: 'a'
},
{
"label": "B",
"num": 120,
value: 'b'
},
{
"label": "C",
"num": 30,
value: 'c'
},
{
"label": "D",
"num": 40,
value: 'd'
}
]
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 ## 二级标题 |
| ---------------------- | --------- | --------- | -------------------------- |
| config | `object` | | echart 图表配置 |
| showTooltipOnHighlight | `boolean` | `false` | 高亮的时候是否显示 tooltip |
| chartValueField | `string` | `"value"` | 图表数值字段名 |

View File

@@ -0,0 +1,254 @@
---
title: Checkbox 勾选框
description:
type: 0
group: null
menuName: Checkbox
icon:
order: 8
---
用于实现勾选,功能和 [Switch](./switch) 类似,只是展现上不同。
## 基本用法
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "checkbox",
"type": "checkbox",
"label": "勾选框",
"option": "选项说明"
}
]
}
```
## 配置真假值
默认情况:
- 勾选框勾选时,表单项值为:true
- 勾选框取消勾选时,表单项值为:false
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "checkbox",
"type": "checkbox",
"label": "勾选框",
"option": "选项说明"
}
]
}
```
如果你想调整这个值,可以配置`trueValue`和`falseValue`
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "checkbox",
"type": "checkbox",
"label": "勾选框",
"option": "选项说明",
"trueValue": 1,
"falseValue": 0
}
]
}
```
勾选上例中的勾选框,观察数据域变化,会发现勾选后值为`1`,而取消勾选后为`0`
## 按钮模式
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "checkbox",
"type": "checkbox",
"label": "勾选框",
"trueValue": true,
"falseValue": false,
"optionType": "button",
"option": "选项说明"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ---------- | ------------------------- | --------- | ---------------- |
| option | `string` | | 选项说明 |
| trueValue | `string|number|boolean` | `true` | 标识真值 |
| falseValue | `string|number|boolean` | `false` | 标识假值 |
| optionType | `default|button` | `default` | 设置 option 类型 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | -------------------------- | ------------------ |
| change | `[name]: boolean` 组件的值 | 选中状态变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "checkbox",
"type": "checkbox",
"label": "勾选框",
"option": "选项说明",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string \|number \|boolean` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "checkbox",
"label": "选项",
"name": "type",
"id": "clear_type",
"option": "选项说明",
"value": true
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_type"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "checkbox",
"label": "选项",
"name": "type",
"id": "reset_type",
"option": "选项说明",
"value": true
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "checkbox",
"label": "选项",
"name": "type",
"id": "setvalue_type",
"option": "选项说明",
"value": true
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_type",
"args": {
"value": false
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,864 @@
---
title: Checkboxes 复选框
description:
type: 0
group: null
menuName: Checkboxes
icon:
order: 9
---
用于实现多选。
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 结果是数组模式
默认是拼接成字符串,如果希望结果是数组,可以设置 `"joinValues": false`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"joinValues": false,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
如果只想提取 value,需要加上 `"extractValue": true`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"joinValues": false,
"extractValue": true,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 显示全选
通过 `checkAll` 属性配置全选
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"checkAll": true,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 按钮模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"optionType": "button",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 按列显示
设置 `"inline": false`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"inline": false,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 展示多行
可以配置`columnsCount`属性调整展示列的个数
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "checkboxes1",
"type": "checkboxes",
"label": "默认的复选框",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
},
{
"type": "divider"
},
{
"name": "checkboxes2",
"type": "checkboxes",
"label": "显示两列的复选框",
"columnsCount": 2,
"inline": false,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
> 1.8.0 及以上版本
`columnsCount` 还有一种数组形式,可以手动控制每行显示的列数
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "checkboxes1",
"type": "checkboxes",
"label": "默认的复选框",
"columnsCount": [1, 2, 3],
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
},
{
"label": "OptionE",
"value": "e"
},
{
"label": "OptionF",
"value": "f"
}
]
}
]
}
```
## 分组显示
`"inline": false` 下,选项中配置 `children` 字段可以实现分组展示效果。
```schema: scope="body"
{
"type": "form",
"mode": "horizontal",
"debug": true,
"body": [
{
"type": "checkboxes",
"name": "checkboxes",
"label": "城市选择",
"inline": false,
"checkAll": true,
"options": [
{
"label": "A类型",
"children": [
{
"label": "选项 A-1",
"value": "a-1"
},
{
"label": "选项 A-2",
"value": "a-2"
}
]
},
{
"label": "B类型",
"children": [
{
"label": "选项 B-1",
"value": "b-1"
},
{
"label": "选项 B-2",
"value": "b-2"
},
{
"label": "选项 B-3",
"value": "b-3"
},
{
"label": "选项 B-4",
"value": "b-4"
}
]
}
]
}
]
}
```
## 自定义选项渲染
> 2.0.0 及以上版本
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"menuTpl": "<span class='label label-${klass}'>${label}</span>",
"options": [
{
"label": "OptionA",
"value": "a",
"klass": "success"
},
{
"label": "OptionB",
"value": "b",
"klass": "danger"
},
{
"label": "OptionC",
"value": "c",
"klass": "warning"
},
{
"label": "OptionD",
"value": "d",
"klass": "info"
}
]
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| --------------- | ----------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------- |
| options | `Array<object>`或`Array<string>` | | [选项组](./#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
| labelField | `string` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
| valueField | `string` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
| columnsCount | `number` | `1` | 选项按几列显示,默认为一列 |
| menuTpl | `string` | | 支持自定义选项渲染 |
| checkAll | `boolean` | `false` | 是否支持全选 |
| inline | `boolean` | `true` | 是否显示为一行 |
| defaultCheckAll | `boolean` | `false` | 默认是否全选 |
| creatable | `boolean` | `false` | [新增选项](./options#%E5%89%8D%E7%AB%AF%E6%96%B0%E5%A2%9E-creatable) |
| createBtnLabel | `string` | `"新增选项"` | [新增选项](./options#%E6%96%B0%E5%A2%9E%E9%80%89%E9%A1%B9) |
| addControls | Array<[表单项](./formitem)> | | [自定义新增表单项](./options#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B0%E5%A2%9E%E8%A1%A8%E5%8D%95%E9%A1%B9-addcontrols) |
| addApi | [API](../../docs/types/api) | | [配置新增选项接口](./options#%E9%85%8D%E7%BD%AE%E6%96%B0%E5%A2%9E%E6%8E%A5%E5%8F%A3-addapi) |
| editable | `boolean` | `false` | [编辑选项](./options#%E5%89%8D%E7%AB%AF%E7%BC%96%E8%BE%91-editable) |
| editControls | Array<[表单项](./formitem)> | | [自定义编辑表单项](./options#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BC%96%E8%BE%91%E8%A1%A8%E5%8D%95%E9%A1%B9-editcontrols) |
| editApi | [API](../../docs/types/api) | | [配置编辑选项接口](./options#%E9%85%8D%E7%BD%AE%E7%BC%96%E8%BE%91%E6%8E%A5%E5%8F%A3-editapi) |
| removable | `boolean` | `false` | [删除选项](./options#%E5%88%A0%E9%99%A4%E9%80%89%E9%A1%B9) |
| deleteApi | [API](../../docs/types/api) | | [配置删除选项接口](./options#%E9%85%8D%E7%BD%AE%E5%88%A0%E9%99%A4%E6%8E%A5%E5%8F%A3-deleteapi) |
| optionType | `default` \| `button` | `default` | 按钮模式 |
| itemClassName | `string` | | 选项样式类名 |
| labelClassName | `string` | | 选项标签样式类名 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------------------------------- | ----------------------------------------------------------------------------------------- | ------------------ |
| change | `[name]: string` 选中值 | 选中值变化时触发 |
| addConfirm (3.6.4 及以上版本) | `[name]: string` 组件的值<br/>`item: object` 新增的节点信息<br/>`items: object[]`选项集合 | 新增节点提交时触发 |
| editConfirm (3.6.4 及以上版本) | `[name]: object` 组件的值<br/>`item: object` 编辑的节点信息<br/>`items: object[]`选项集合 | 编辑节点提交时触发 |
| deleteConfirm (3.6.4 及以上版本) | `[name]: string` 组件的值<br/>`item: object` 删除的节点信息<br/>`items: object[]`选项集合 | 删除节点提交时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
],
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value}"
}
}
]
}
}
}
]
}
```
### addConfirm
配置 `creatable`后,可监听确认新增操作。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"creatable": true,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
],
"onEvent": {
"addConfirm": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.item|json}"
}
}
]
}
}
}
]
}
```
### editConfirm
配置 `editable`后,可监听确认编辑操作。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"editable": true,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
],
"onEvent": {
"editConfirm": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.item|json}"
}
}
]
}
}
}
]
}
```
### deleteConfirm
配置 `removable`后,可监听确认删除操作。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "checkboxes",
"type": "checkboxes",
"label": "复选框",
"removable": true,
"labelField": "label2",
"valueField": "value2",
"options": [
{
"label2": "OptionA",
"value2": "a"
},
{
"label2": "OptionB",
"value2": "b"
},
{
"label2": "OptionC",
"value2": "c"
},
{
"label2": "OptionD",
"value2": "d"
}
],
"onEvent": {
"deleteConfirm": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.item|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
| setValue | `value: string` 更新的值 | 更新数据,多个值用`,`分隔 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "checkboxes",
"label": "选项",
"name": "type",
"id": "clear_type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
],
"value": "b"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_type"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "checkboxes",
"label": "选项",
"name": "type",
"id": "reset_type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
],
"value": "b"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_type"
}
]
}
}
}
]
}
```
### reload
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "checkboxes",
"label": "选项",
"name": "type",
"id": "reload_type",
"source": "/api/mock2/form/getOptions?waitSeconds=1"
},
{
"type": "button",
"label": "重新加载",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reload",
"componentId": "reload_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "checkboxes",
"label": "选项",
"name": "type",
"id": "setvalue_type",
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
],
"value": "b"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_type",
"args": {
"value": "c"
}
}
]
}
}
}
]
}
```

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,78 @@
---
title: Control 表单项包裹
description:
type: 0
group: null
menuName: Control
icon:
order: 24
---
展示类的组件,如果直接放在表单项里面,不会有 `label` 和 `description` 之类的信息展示。
```schema: scope="body"
{
"type": "form",
"mode": "horizontal",
"body": [
{
"type": "input-text",
"label": "文本输入"
},
{
"type": "image",
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
},
{
"type": "qr-code",
"codeSize": 128,
"backgroundColor": "#108cee",
"foregroundColor": "#000",
"value": "https://www.baidu.com"
}
]
}
```
如果想像文本输入框一样,可以配置 `label` 和 `description`,则可以通过这个组件包裹一下。
```schema: scope="body"
{
"type": "form",
"mode": "horizontal",
"body": [
{
"type": "input-text",
"label": "文本输入"
},
{
"type": "control",
"label": "图片",
body: [
{
"type": "image",
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
}
]
},
{
"type": "control",
"label": "二维码",
"description": "还可以来点描述",
body: [
{
"type": "qr-code",
"codeSize": 128,
"backgroundColor": "#108cee",
"foregroundColor": "#000",
"value": "https://www.baidu.com"
}
]
}
]
}
```

View File

@@ -0,0 +1,245 @@
---
title: DiffEditor 对比编辑器
description:
type: 0
group: null
menuName: DiffEditor 对比编辑器
icon:
order: 17
---
## 基本使用
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "diff-editor",
"name": "diff",
"label": "Diff-Editor",
"diffValue": "hello world",
"value": "hello"
}
]
}
```
## 禁用编辑器
左侧编辑器始终不可编辑,右侧编辑器可以通过设置`disabled`或`disabledOn`,控制是否禁用
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "diff-editor",
"name": "diff",
"label": "Diff-Editor",
"diffValue": "hello world",
"value": "hello",
"disabledOn": "this.isDisabled"
},
{
"type": "switch",
"name": "isDisabled",
"label": "是否禁用"
}
]
}
```
## diff 数据域中的两个变量
如下例,左侧编辑器中的值,通过`"diffValue": "${value1}"`获取,右侧编辑器的值,通过设置`"name": "value2"`,自动映射数据域中`value2`的值
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"data": {
"value1": "hello world",
"value2": "hello wrold"
},
"body": [
{
"type": "diff-editor",
"name": "value2",
"label": "Diff-Editor",
"diffValue": "${value1}"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| --------- | ------------- | ------------ | ------------------------------------------------------------------------------------------- |
| language | `string` | `javascript` | 编辑器高亮的语言,可选 [支持的语言](./editor#%E6%94%AF%E6%8C%81%E7%9A%84%E8%AF%AD%E8%A8%80) |
| diffValue | [Tpl](../tpl) | | 左侧值 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | ------------------------ |
| change | `[name]: string` 组件的值 | 代码变化时触发 |
| focus | `[name]: string` 组件的值 | 右侧输入框获取焦点时触发 |
| blur | `[name]: string` 组件的值 | 右侧输入框失去焦点时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| focus | - | 获取焦点,焦点落在右侧编辑面板 |
| setValue | `value: string` 更新的右侧编辑面板中的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "diff-editor",
"name": "diff",
"id": "clear_text",
"label": "Diff-Editor",
"diffValue": "hello world",
"value": "hello"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"id": "reset_text",
"type": "diff-editor",
"name": "diff",
"label": "Diff-Editor",
"diffValue": "hello world",
"value": "hello"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### focus
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"id": "focus_text",
"type": "diff-editor",
"name": "diff",
"label": "Diff-Editor",
"diffValue": "hello world",
"value": "hello"
},
{
"type": "button",
"label": "聚焦",
"onEvent": {
"click": {
"actions": [
{
"actionType": "focus",
"componentId": "focus_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"id": "setvalue_text",
"type": "diff-editor",
"name": "diff",
"label": "Diff-Editor",
"diffValue": "hello world",
"value": "hello"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "amis go go go!"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,322 @@
---
title: Editor 编辑器
description:
type: 0
group: null
menuName: Editor
icon:
order: 19
---
用于实现代码编辑,如果要实现富文本编辑请使用 [Rich-Text](./input-rich-text)。
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "editor",
"name": "editor",
"label": "编辑器",
placeholder: "function() {\n console.log('hello world')\n}"
}
]
}
```
## 支持的语言
可以设置`language`配置高亮的语言,支持的语言有:
`bat`、 `c`、 `coffeescript`、 `cpp`、 `csharp`、 `css`、 `dockerfile`、 `fsharp`、 `go`、 `handlebars`、 `html`、 `ini`、 `java`、 `javascript`、 `json`、 `less`、 `lua`、 `markdown`、 `msdax`、 `objective-c`、 `php`、 `plaintext`、 `postiats`、 `powershell`、 `pug`、 `python`、 `r`、 `razor`、 `ruby`、 `sb`、 `scss`、`shell`、 `sol`、 `sql`、 `swift`、 `typescript`、 `vb`、 `xml`、 `yaml`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "editor",
"name": "editor",
"label": "JSON编辑器",
"language": "json"
}
]
}
```
> 因为性能原因,上面的例子不支持实时修改 language 生效
当然你也可以使用`xxx-editor`这种形式,例如`"type": "json-editor"`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "json-editor",
"name": "editor",
"label": "JSON编辑器"
}
]
}
```
## 只读模式
使用 `disabled: true`。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "json-editor",
"name": "editor",
"disabled": true,
"label": "JSON编辑器"
}
]
}
```
## 全屏模式
设置`allowFullscreen`属性为`true`,显示编辑器的全屏模式开关,开关开启后编辑器进入全屏模式。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "editor",
"name": "editor",
"label": "支持全屏模式的编辑器",
"allowFullscreen": true
}
]
}
```
## 编辑器展现控制
通过 `options` 来控制编辑器展现,比如下面的配置可以关闭行号
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "editor",
"name": "editor",
"label": "编辑器",
"options": {
"lineNumbers": "off"
}
}
]
}
```
## 编辑器自定义开发
amis 的编辑器是基于 monaco 开发的,如果想进行深度定制,比如自动完成功能,可以通过自定义 `editorDidMount` 属性来获取到 monaco 实例,它有两种写法,一种是在 JS 中直接用函数,示例如下:
```javascript
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "editor",
"name": "editor",
"label": "编辑器",
"language": "myLan",
"editorDidMount": (editor, monaco) => {
// editor 是 monaco 实例,monaco 是全局的名称空间
const dispose = monaco.languages.registerCompletionItemProvider('myLan', {
/// 其他细节参考 monaco 手册
});
// 如果返回一个函数,这个函数会在编辑器组件卸载的时候调用,主要用于清理资源
return dispose;
}
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| --------------- | --------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| language | `string` | `javascript` | 编辑器高亮的语言,支持通过 `${xxx}` 变量获取 |
| size | `string` | `md` | 编辑器高度,取值可以是 `md`、`lg`、`xl`、`xxl` |
| allowFullscreen | `boolean` | `false` | 是否显示全屏模式开关 |
| options | `object` | | monaco 编辑器的其它配置,比如是否显示行号等,请参考[这里](https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IEditorOptions.html),不过无法设置 readOnly,只读模式需要使用 `disabled: true` |
| placeholder | `string` | | 占位描述,没有值的时候展示 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------- |
| change | `[name]: string` 组件的值 | 代码变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| focus | - | 获取焦点 |
| setValue | `value: string` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "editor",
"name": "editor",
"label": "编辑器",
"id": "clear_text",
"value": "hello"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "editor",
"id": "reset_text",
"name": "editor",
"label": "编辑器",
"value": "hello"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### focus
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "editor",
"id": "focus_text",
"name": "editor",
"label": "编辑器",
"value": "hello"
},
{
"type": "button",
"label": "聚焦",
"onEvent": {
"click": {
"actions": [
{
"actionType": "focus",
"componentId": "focus_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "editor",
"id": "setvalue_text",
"name": "editor",
"label": "编辑器",
"value": "hello"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "amis go go go!"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,245 @@
---
title: FieldSet 表单项集合
description:
type: 0
group: null
menuName: FieldSet
icon:
order: 20
---
FieldSet 是用于分组展示表单项的一种容器型组件,可以折叠。
## 基本用法
可以通过配置标题`title`和表单项数组`body`,实现多个表单项分组展示
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "fieldSet",
"title": "基本配置",
"body": [
{
"name": "text1",
"type": "input-text",
"label": "文本1"
},
{
"name": "text2",
"type": "input-text",
"label": "文本2"
}
]
}
]
}
```
## 展示模式
可以通过设置`mode`调整展示模式,用法同 [Form 展示模式](./index#%E8%A1%A8%E5%8D%95%E5%B1%95%E7%A4%BA)
下面`group`我们配置了`"mode": "horizontal"`,观察显示情况
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-text",
"name": "text",
"label": "文本"
},
{
"type": "divider"
},
{
"type": "fieldSet",
"title": "基本配置",
"mode": "horizontal",
"body": [
{
"name": "text1",
"type": "input-text",
"label": "文本1"
},
{
"name": "text2",
"type": "input-text",
"label": "文本2"
}
]
}
]
}
```
## 可折叠
配置`"collapsable": true`可以实现点击标题折叠显隐表单项。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "fieldSet",
"title": "基本配置",
"collapsable": true,
"body": [
{
"name": "text1",
"type": "input-text",
"label": "文本1"
},
{
"name": "text2",
"type": "input-text",
"label": "文本2"
}
]
}
]
}
```
### 默认是否折叠
默认是展开的,如果想默认折叠,那么配置`"collapsed": true`默认折叠。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "fieldSet",
"title": "基本配置",
"collapsable": true,
"collapsed": true,
"body": [
{
"name": "text1",
"type": "input-text",
"label": "文本1"
},
{
"name": "text2",
"type": "input-text",
"label": "文本2"
}
]
}
]
}
```
## 标题放底部
fieldSet 的另一种标题展现样式,不同的是展开的时候收起文本是在下方的,如果组件比较多的时候更容易收起。
设置 `"titlePosition": "bottom"`。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "fieldSet",
"title": "展开更多设置",
"collapseTitle": "收起设置",
"titlePosition": "bottom",
"collapsable": true,
"collapsed": true,
"body": [
{
"name": "text1",
"type": "input-text",
"label": "文本1"
},
{
"name": "text2",
"type": "input-text",
"label": "文本2"
}
]
}
]
}
```
## 嵌套使用
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "fieldSet",
"title": "基本配置",
"collapsable": true,
"body": [
{
"name": "text1",
"type": "input-text",
"label": "文本1"
},
{
"name": "text2",
"type": "input-text",
"label": "文本2"
},
{
"type": "fieldSet",
"title": "基本配置",
"collapsable": true,
"collapsed": true,
size: 'base',
"body": [
{
"name": "text1",
"type": "input-text",
"label": "文本1"
},
{
"name": "text2",
"type": "input-text",
"label": "文本2"
}
]
}
]
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| ---------------- | -------------------------------------------- | ------- | -------------------------------------------------------------------------- |
| className | `string` | | CSS 类名 |
| headingClassName | `string` | | 标题 CSS 类名 |
| bodyClassName | `string` | | 内容区域 CSS 类名 |
| title | [SchemaNode](../../../docs/types/schemanode) | | 标题 |
| body | Array<[表单项](./formitem)> | | 表单项集合 |
| mode | `string` | | 展示默认,同 [Form](./index#%E8%A1%A8%E5%8D%95%E5%B1%95%E7%A4%BA) 中的模式 |
| collapsable | `boolean` | `false` | 是否可折叠 |
| collapsed | `booelan` | `false` | 默认是否折叠 |
| collapseTitle | [SchemaNode](../../../docs/types/schemanode) | `收起` | 收起的标题 |
| size | string | `` | 大小,支持 xs、sm、base、md、lg |

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,255 @@
---
title: Formula 公式
description:
type: 0
group: null
menuName: Formula
icon:
order: 22
---
可以设置公式,将公式结果设置到指定表单项上。
> 该表单项是隐藏的
## 基本用法
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-number",
"name": "a",
"label": "A"
},
{
"type": "input-number",
"name": "b",
"label": "B"
},
{
"type": "input-number",
"name": "sum",
"label": "和",
"disabled": true,
"description": "自动计算 A + B"
},
{
"type": "formula",
"name": "sum",
"value": 0,
"formula": "a + b"
}
]
}
```
## 自动应用
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-number",
"name": "a",
"label": "A"
},
{
"type": "input-number",
"name": "b",
"label": "B"
},
{
"type": "input-number",
"name": "sum",
"label": "和",
"disabled": true,
"description": "自动计算 A + B"
},
{
"type": "formula",
"name": "sum",
"value": 0,
"formula": "a + b"
}
]
}
```
## 手动应用
配置`"autoSet": false`,然后按钮上配置`target`,配置值为`formula`的`id`值,就可以实现手动触发公式应用
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-number",
"name": "a",
"label": "A"
},
{
"type": "input-number",
"name": "b",
"label": "B"
},
{
"type": "group",
"body": [
{
"type": "input-number",
"name": "sum",
"label": "和",
"disabled": true,
"columnClassName": "col-sm-11"
},
{
"type": "button",
"label": "计算",
"columnClassName": "col-sm-1 v-bottom",
"target": "theFormula"
}
]
},
{
"type": "formula",
"name": "sum",
"id": "theFormula",
"value": 0,
"formula": "a + b",
"initSet": false,
"autoSet": false
}
]
}
```
> 为什么设置`id`而不是设置`name`?
>
> 因为`name`值已经用来设置目标变量名了,这个表单项肯定已经存在了,所以不是唯一了,不能够被按钮指定。
## 条件应用
可以配置`condition`用来指定作用条件,有两种写法:
- 用 tpl 语法,把关联的字段写上如: `${xxx} ${yyy}` 意思是当 xxx 和 yyy 的取值结果变化了就再应用一次公式结果。
- 自己写判断如: `this.xxx == "a" && this.xxx !== this.__prev.xxx` 当 xxx 变化了,且新的值是字符 "a" 时应用,可以写更加复杂的判断。
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "radios",
"name": "radios",
"label": "radios",
"options": [
{
"label": "a",
"value": "a"
},
{
"label": "b",
"value": "b"
}
],
"description": "radios 变化会自动清空 B"
},
{
"type": "input-text",
"name": "b",
"label": "B"
},
{
"type": "formula",
"name": "b",
"value": "some string",
"formula": "''",
"condition": "${radios}",
"initSet": false
}
]
}
```
## 使用新表达式语法
> 1.5.0 及以上版本
通过新的[表达式](../../../docs/concepts/expression)语法,可以调用其中的函数,比如
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "static",
"value": "这个表单没有内容,通过上面的 debug 可以看到输出当前日期"
},
{
"type": "formula",
"name": "date",
"formula": "${DATETOSTR(NOW(), 'YYYY-MM-DD')}"
}
]
}
```
这种写法默认会解决浮点数计算问题(需要更新到 amis 1.6.4 及以上版本),比如
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-number",
"name": "a",
"value": 0.1,
"label": "A"
},
{
"type": "input-number",
"name": "b",
"value": 0.2,
"label": "B"
},
{
"type": "input-number",
"name": "sum",
"label": "直接相加",
"disabled": true
},
{
"type": "formula",
"name": "sum",
"formula": "a + b"
},
{
"type": "input-number",
"name": "sum-new",
"label": "使用新表达式",
"disabled": true
},
{
"type": "formula",
"name": "sum-new",
"formula": "${a + b}"
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| --------- | ------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------- |
| name | `string` | | 需要应用的表单项`name`值,公式结果将作用到此处指定的变量中去。 |
| formula | [表达式](../../../docs/concepts/expression) | | 应用的公式 |
| condition | [表达式](../../../docs/concepts/expression) | | 公式作用条件 |
| initSet | `boolean` | `true` | 初始化时是否设置 |
| autoSet | `boolean` | `true` | 观察公式结果,如果计算结果有变化,则自动应用到变量上 |
| id | `string` | | 定义个名字,当某个按钮的目标指定为此值后,会触发一次公式应用。这个机制可以在 `autoSet` 为 false 时用来手动触发 |

View File

@@ -0,0 +1,232 @@
---
title: Group 表单项组
description:
type: 0
group: null
menuName: Group
icon:
order: 24
---
表单项,默认都是一行显示一个,Group 组件用于在一行展示多个表单项,会自动根据表单项数量均分宽度。
## 基本用法
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "group",
"body": [
{
"type": "input-text",
"name": "text1",
"label": "文本1"
},
{
"type": "input-text",
"name": "text2",
"label": "文本2"
}
]
},
{
"type": "divider"
},
{
"type": "group",
"body": [
{
"type": "input-text",
"name": "text3",
"label": "文本3"
},
{
"type": "input-text",
"name": "text4",
"label": "文本4"
},
{
"type": "input-text",
"name": "text5",
"label": "文本5"
}
]
}
]
}
```
## 展示
可以给`group`组件设置`mode`调整展示模式,用法同 [Form 展示](./index#%E8%A1%A8%E5%8D%95%E5%B1%95%E7%A4%BA)
下面`group`我们配置了`"mode": "horizontal"`,观察显示情况
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-text",
"name": "text",
"label": "文本"
},
{
"type": "divider"
},
{
"type": "group",
"mode": "horizontal",
"body": [
{
"type": "input-text",
"name": "text1",
"label": "文本1"
},
{
"type": "input-text",
"name": "text2",
"label": "文本2"
}
]
}
]
}
```
当表单在水平模式下时,如果`group`内表单项设置`"label": false`,会导致布局错乱,如下
```schema: scope="body"
{
"type": "form",
"mode": "horizontal",
"body": [
{
"type": "input-text",
"name": "text",
"label": "文本"
},
{
"type": "divider"
},
{
"type": "group",
"body": [
{
"type": "input-text",
"name": "text1",
"label": false
},
{
"type": "input-text",
"name": "text2",
"label": false
}
]
}
]
}
```
这时可以给`group`配置`label`属性,保持和其他表单项布局统一
```schema: scope="body"
{
"type": "form",
"mode": "horizontal",
"body": [
{
"type": "input-text",
"name": "text",
"label": "文本"
},
{
"type": "divider"
},
{
"type": "group",
"label": "文本组",
"body": [
{
"type": "input-text",
"name": "text1",
"label": false
},
{
"type": "input-text",
"name": "text2",
"label": false
}
]
}
]
}
```
## 宽度占比
在表单项内部可以通过 `columnRatio` 来控制宽度,整体是 12 等分
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "group",
"body": [
{
"type": "input-text",
"name": "text1",
"label": "text1",
"columnRatio": 8
},
{
"type": "input-text",
"name": "text2",
"label": "text2",
"columnRatio": 4
}
]
},
{
"type": "divider"
},
{
"type": "group",
"body": [
{
"type": "input-text",
"name": "text1",
"label": "text1",
"columnRatio": 6
},
{
"type": "input-text",
"name": "text2",
"label": "text2",
"columnRatio": 4
},
{
"type": "input-text",
"name": "text3",
"label": "text3"
}
]
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| --------- | --------------------------- | -------------- | -------------------------------------------------------------------------- |
| className | `string` | | CSS 类名 |
| label | `string` | | group 的标签 |
| body | Array<[表单项](./formitem)> | | 表单项集合 |
| mode | `string` | | 展示默认,同 [Form](./index#%E8%A1%A8%E5%8D%95%E5%B1%95%E7%A4%BA) 中的模式 |
| gap | `string` | | 表单项之间的间距,可选:`xs`、`sm`、`normal` |
| direction | `string` | `"horizontal"` | 可以配置水平展示还是垂直展示。对应的配置项分别是:`vertical`、`horizontal` |

View File

@@ -0,0 +1,38 @@
---
title: Hidden 隐藏字段
description:
type: 0
group: null
menuName: Hidden 隐藏字段
icon:
order: 26
---
## 基本用法
默认表单提交,在没有 [自定义 API 请求数据](../../../docs/types/api#%E9%85%8D%E7%BD%AE%E8%AF%B7%E6%B1%82%E6%95%B0%E6%8D%AE) 的情况下,只会发送 `body` 里面的这些成员,对于隐藏的字段同时又希望提交表单的时候带过去,可以使用 `hidden` 组件
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "hidden",
"name": "id",
"value": 1
},
{
"type": "input-text",
"name": "name",
"label": "姓名:"
},
{
"name": "email",
"type": "input-email",
"label": "邮箱:"
}
]
}
```

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
---
title: InputArray 数组输入框
description:
type: 0
group: null
menuName: InputArray 数组输入框
icon:
order: 3
---
InputArray 是一种简化的 [Combo](./combo),用于输入多个某种类型的[表单项](./formitem),提交的时将以数组的形式提交。
## 基本用法
```schema: scope="form2"
[
{
"name": "array",
"label": "颜色集合",
"type": "input-array",
"value": ["red"],
"inline": true,
"items": {
"type": "input-color",
"clearable": false
}
}
]
```
## 新增成员默认值
部分情况下,期望新增元素时使用默认值,这时可以通过设置`scaffold`属性配置新增成员的默认值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"debugConfig": {
"levelExpand": 2
},
"body": [
{
"name": "array",
"label": "整数集合",
"mode": "horizontal",
"type": "input-array",
"value": [123, 456],
"scaffold": 0,
"inline": true,
"items": {
"type": "input-number",
"clearable": false
}
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------- | ------------------------------------------- | --------- | ------------------------------------------------------------------------ |
| type | `string` | `"input-array"` | 指明为`array`组件 |
| items | [`SchemaNode`](../../docs/types/schemanode) | | 配置单项表单类型 |
| addable | `boolean` | | 是否可新增。 |
| removable | `boolean` | | 是否可删除 |
| draggable | `boolean` | `false` | 是否可以拖动排序, 需要注意的是当启用拖动排序的时候,会多一个\$id 字段 |
| draggableTip | `string` | | 可拖拽的提示文字,默认为:`"可通过拖动每行中的【交换】按钮进行顺序调整"` |
| addButtonText | `string` | `"新增"` | 新增按钮文字 |
| minLength | `number` | | 限制最小长度 |
| maxLength | `number` | | 限制最大长度 |
| scaffold | `any` | | 新增成员时的默认值,一般根据`items`的数据类型指定需要的默认值 |

View File

@@ -0,0 +1,253 @@
---
title: InputCity 城市选择器
description:
type: 0
group: null
menuName: InputCity
icon:
order: 10
---
城市选择器,方便输入城市,可以理解为自动配置了国内城市选项的 Select,支持到县级别。
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "city",
"type": "input-city",
"label": "城市",
"searchable": true
}
]
}
```
观察数据域中表单项的值,存储的是位置邮编。
## 配置选择级别
可以通过设置 `allowDistrict` 和 `allowCity` 设置用户选择级别,例如只选择省份:
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "city",
"type": "input-city",
"label": "城市",
"allowDistrict": false,
"allowCity": false
}
]
}
```
## 获取更多选项信息
表单项值默认格式是编码(即 `code`),如果你想要详细点的信息,可以把 `extractValue` 设置成 `false`。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "city",
"type": "input-city",
"label": "城市",
"extractValue": false
}
]
}
```
## 配置下拉框样式
可以通过 `itemClassName` 指定下拉框样式,如配置最小宽度
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "city",
"type": "input-city",
"label": "城市",
"itemClassName": "min-w-xs",
"searchable": true
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------- | --------- | ------- | --------------------------------------------------------------------------------------------------------------------- |
| allowCity | `boolean` | `true` | 允许选择城市 |
| allowDistrict | `boolean` | `true` | 允许选择区域 |
| searchable | `boolean` | `false` | 是否出搜索框 |
| extractValue | `boolean` | `true` | 默认 `true` 是否抽取值,如果设置成 `false` 值格式会变成对象,包含 `code`、`province`、`city` 和 `district` 文字信息。 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ----------------------------------- | ---------------- |
| change | `[name]: number \| string` 组件的值 | 选中值变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "city",
"type": "input-city",
"label": "城市",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string \| number` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "city",
"type": "input-city",
"label": "城市",
"id": "clear_text",
"value": "110000"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "city",
"type": "input-city",
"label": "城市",
"id": "reset_text",
"value": "110000"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "city",
"type": "input-city",
"label": "城市",
"id": "setvalue_text",
"value": "110000"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "110100"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,115 @@
---
title: InputColor 颜色选择器
description:
type: 0
group: null
menuName: InputColor
icon:
order: 11
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-color",
"name": "color",
"label": "普通色盘"
}
]
}
```
## 选择器预设颜色值
颜色选择器底部预设有会写可选的颜色值,默认为:
```
['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF']
```
你可以配置`presetColors`数组进行自定义。颜色支持两种格式`string` 和 `{color: string; title: string}`,并支持两种格式混合使用。`string`格式支持所有合法的 CSS 颜色码,`object`类型下的`color`属性为 CSS 颜色码,`title`属性为颜色名称,鼠标悬浮于色块时会显示对应颜色名称。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-color",
"name": "color",
"label": "自定义预设色盘",
"presetColors": [
{"color": "#d4380d", "title": "熔岩红"},
{"color": "#ffa940", "title": "金桔橙"},
{"color": "#ffec3d", "title": "土豪金"},
{"color": "#73d13d", "title": "苹果绿"},
{"color": "#73E3EC", "title": "蒂芙尼青"},
{"color": "#2f54eb", "title": "冰川蓝"},
{"color": "#9254de", "title": "薰衣草紫"},
{"color": "#ffc0cb", "title": "樱花粉"},
"rgb(212, 56, 13)", "rgba(255, 169, 64, 1.0)", "hsl(54,100%,62%)", "hsla(98, 62%, 53%, 1.0)", "#73E3EC", "#2f54eb", "#9254de", "pink"
]
}
]
}
```
## rgba
将 `format` 设置为 rgba 就能改变颜色透明度。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-color",
"name": "color",
"label": "带透明度调节的色盘",
"format": "rgba"
}
]
}
```
## hexa (8 digits HEX)
将 `format` 设置为 hexa 支持 8位 HEX,参考 `https://drafts.csswg.org/css-color/`。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-color",
"name": "color",
"label": "带透明度调节的色盘, 8 digits HEX",
"value": "#73E3EC88",
"format": "hexa"
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ---------------- | --------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| format | `string` | `hex` | 请选择 `hex`、`hexa`、`hls`、`rgb`或者`rgba`。 |
| presetColors | `Array<string>` | [选择器预设颜色值](./input-color#%E9%80%89%E6%8B%A9%E5%99%A8%E9%A2%84%E8%AE%BE%E9%A2%9C%E8%89%B2%E5%80%BC) | 选择器底部的默认颜色,数组内为空则不显示默认颜色 |
| allowCustomColor | `boolean` | `true` | 为`false`时只能选择颜色,使用 `presetColors` 设定颜色选择范围 |
| clearable | `boolean` | `"label"` | 是否显示清除按钮 |
| resetValue | `string` | `""` | 清除后,表单项值调整成该值 |

View File

@@ -0,0 +1,477 @@
---
title: InputDateRange 日期范围
description:
type: 0
group: null
menuName: InputDateRange
icon:
order: 15
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "select",
"label": "日期范围"
}
]
}
```
## 默认值
通过 value 设置默认值,除了实际值,比如
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "date",
"label": "日期范围",
"value": "1659283200,1661961599"
}
]
}
```
还可以是相对值,比如最近一周内
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "date",
"label": "日期范围",
"value": "today,+1weeks"
}
]
}
```
支持的相对值关键字有:
- today: 当前日期
- day 或 days: 天
- week 或 weeks: 周
- month 或 months: 月
- year 或 years: 年
或者用公式来配置复杂情况, 比如本周一到周日
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "date",
"label": "日期范围",
"value": "${DATETOSTR(DATEMODIFY(STARTOF(NOW(), 'week'), 1, 'day'), 'X') + ',' + DATETOSTR(DATEMODIFY(ENDOF(NOW(), 'week'), '1', 'day'), 'X')}"
}
]
}
```
> 因为默认周日是第一天,所以需要往后加一天
再看个上月第一天到上月最后一天的例子
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "date",
"label": "日期范围",
"value": "${DATETOSTR(STARTOF(DATEMODIFY(NOW(), -1, 'month'), 'month'), 'X') + ',' + DATETOSTR(ENDOF(DATEMODIFY(NOW(), -1, 'month'), 'month'), 'X')}"
}
]
}
```
## 快捷键
`shortcuts`属性支持自定义快捷选择日期范围快捷键
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "select",
"label": "日期范围",
"shortcuts": [
"7daysago",
"15dayslater",
"2weeksago",
"1weekslater",
"thismonth",
"2monthsago",
"3monthslater"
]
}
]
}
```
支持的快捷键有
- `today`: 今天
- `yesterday`: 昨天
- `tomorrow`: 明天
- `prevweek`: 上周
- `thisweek`: 这个周
- `thismonth`: 本月
- `prevmonth`: 上个月
- `prevquarter`: 上个季度
- `thisquarter`: 这个季度
- `thisyear`: 今年
- `lastYear`: 去年
- `{n}daysago` : 最近 n 天,例如:`7daysago`,下面用法相同
- `{n}dayslater`: n 天以内
- `{n}weeksago`: 最近 n 周
- `{n}weekslater`: n 周以内
- `{n}monthsago`: 最近 n 月
- `{n}monthslater`: n 月以内
- `{n}quartersago`: 最近 n 季度
- `{n}quarterslater`: n 季度以内
- `{n}yearsago`: 最近 n 年
- `{n}yearslater`: n 年以内
快捷键也支持使用表达式的写法,可以使用这种方式自定义快捷键
> 3.1.0 及以上版本
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "select",
"label": "日期范围",
"shortcuts": [
{
"label": "1天前",
"startDate": "${DATEMODIFY(NOW(), -1, 'day')}",
"endDate": "${NOW()}"
},
{
"label": "1个月前",
"startDate": "${DATEMODIFY(NOW(), -1, 'months')}",
"endDate": "${NOW()}"
},
{
"label": "本季度",
"startDate": "${STARTOF(NOW(), 'quarter')}",
"endDate": "${ENDOF(NOW(), 'quarter')}"
}
]
}
]
}
```
## 内嵌模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-date-range",
"name": "date",
"label": "日期范围",
"embed": true
}
]
}
```
## 存成两个字段
默认日期范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "begin",
"extraName": "end",
"label": "日期范围"
}
]
}
```
## 数据处理函数
> `3.5.0`及以上版本
默认情况下,日期范围选择器组件的绑定值的开始时间为所选时间当天的 0 点(使用`moment().startOf('day')`处理),结束时间为所选时间当天的 23 时 59 分 59 秒 999 毫秒(使用`moment().endOf('day')`处理)。如果设置了`timeFormat`(时间格式),则会基于`timeFormat`配置决定**最小时间单位**,举例:
- 不设置`timeFormat`(时间格式),默认按照天(day)级处理:
```typescript
moment().startOf('day'); // 2008-08-08 00:00:00.000
moment().endOf('day'); // 2008-08-08 23:59:59.999
```
- `timeFormat`(时间格式)为 `"HH:mm:ss"`,则会按照秒(second)级处理:
```typescript
moment().startOf('second'); // 2008-08-08 08:08:08.000
moment().endOf('second'); // 2008-08-08 08:08:08.999
```
- `timeFormat`(时间格式)为 `"HH:mm"`,则会按照分钟(minute)级处理:
```typescript
moment().startOf('minute'); // 2008-08-08 08:08:00.000
moment().endOf('minute'); // 2008-08-08 08:08:59.999
```
- `timeFormat`(时间格式)为 `"HH"`,则会按照小时(hour)级处理:
```typescript
moment().startOf('hour'); // 2008-08-08 08:00:00.000
moment().endOf('hour'); // 2008-08-08 08:59:59.999
```
部分情况下,即使配置`timeFormat`也无法满足需求,此时可以使用`transform`函数对时间值做进一步处理, 函数签名如下:
```typescript
interface TransFormFunc {
(
/* 当前值,Moment对象 */
value: moment.Moment,
config: {
/* 操作类型,start:起始时间;end:结束时间 */
type: 'start' | 'end';
/* 初始值,最近一次选择的时间值 */
originValue: moment.Moment;
/* 时间格式 */
timeFormat: string;
},
/* 当前组件的属性 */
props: any,
/* 当前组件数据域 */
data: any,
/* moment函数 */
moment: moment
): moment.Moment;
}
```
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date-range",
"name": "range1",
"label": "日期范围(默认)",
"valueFormat": "YYYY-MM-DDTHH:mm:ss[Z]"
},
{
"type": "input-date-range",
"name": "range2",
"label": "日期范围(使用transform函数)",
"valueFormat": "YYYY-MM-DDTHH:mm:ss[Z]",
"transform": "const now = moment(); if (config.type === 'end') {value.set({hours: now.hours(), minutes: now.minutes(), seconds: now.seconds(), milliseconds: now.milliseconds()})}; return value;"
}
]
}
```
上面的示例使用 `transform` 函数,将结束时间的值设置为当前时间
```typescript
function transform(value, config, props, data) {
const now = moment();
if (config.type === 'end') {
value.set({
hours: now.hours(),
minutes: now.minutes(),
seconds: now.seconds(),
milliseconds: now.milliseconds()
});
}
return value;
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | ---------------------------------------------------------------------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------- | ----------------------- |
| valueFormat | `string` | `X` | [日期选择器值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) | 3.4.0 版本后支持 |
| displayFormat | `string` | `YYYY-MM-DD` | [日期选择器显示格式](./date#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) | 3.4.0 版本后支持 |
| placeholder | `string` | `"请选择日期范围"` | 占位文本 |
| shortcuts | `string \| string[] \| Array<{label: string; startDate: string; endDate: string}>` | `"yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter"` | 日期范围快捷键 | `3.1.0`版本后支持表达式 |
| minDate | `string` | | 限制最小日期,用法同 [限制范围](./date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| maxDate | `string` | | 限制最大日期,用法同 [限制范围](./date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| minDuration | `string` | | 限制最小跨度,如: 2days |
| maxDuration | `string` | | 限制最大跨度,如:1year |
| utc | `boolean` | `false` | [保存 UTC 值](./date#utc) |
| clearable | `boolean` | `true` | 是否可清除 |
| embed | `boolean` | `false` | 是否内联模式 |
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
| extraName | `string` | | 是否存成两个字段 | `3.3.0` |
| transform | `string` | | 日期数据处理函数,用来处理选择日期之后的的值,返回值为 `Moment`对象 | `3.5.0` |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------------- | ----------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,,依赖格式`format`,例如:'1650556800,1652889599' |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-date-range",
"name": "date",
"label": "日期",
"id": "clear_text",
"value": "1714060800,1714319999"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-date-range",
"name": "date",
"label": "日期",
"id": "reset_text",
"value": "1714060800,1714319999"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-date-range",
"name": "date",
"label": "日期",
"id": "setvalue_text",
"value": "1714060800,1714319999"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "1714060800,1714492799"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,552 @@
---
title: InputDate 日期
description:
type: 0
group: null
menuName: Date
icon:
order: 13
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期"
}
]
}
```
## 显示格式
选中任意日期,可以看到默认显示日期的格式是像`2020-04-14`这样的格式,如果你想要自定义显示格式,那么可以配置`inputFormat`。
例如你想显示`2020年04月14日`这样的格式,查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY年MM月DD日`,即:
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"inputFormat": "YYYY年MM月DD日"
}
]
}
```
选中任意日期,观察显示格式
## 值格式
选中任意日期,可以看到默认表单项的值格式是像`1591862818`这样的时间戳格式。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期"
}
]
}
```
如果你想要其他格式的日期值,那么可以配置`format`参数用于调整表单项的值格式。
例如你调整值为`2020-04-14`这样的格式,查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY-MM-DD`,即:
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"format": "YYYY-MM-DD"
}
]
}
```
选中任意日期,观察数据域中表单项值的变化
## 默认值
可以设置`value`属性,设置日期选择器的默认值
### 基本配置
配置符合当前 [值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) 的默认值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"value": "1591862818"
}
]
}
```
### 相对值
`value` 还支持类似像`"+1days"`这样的相对值,更加便捷的配置默认值
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"value": "+1days"
}
]
}
```
上例中配置了`"value": "+1days"`,默认就会选中明天。
支持的相对值关键字有:
- `today`: 当前日期
- `day`或`days`: 天
- `week`或`weeks`: 周
- `month`或`months`: 月
- `year`或`years`: 年
### 通过公式配置默认值
> 1.7.0 及以上版本
可以通过日期公式来动态计算。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"value": "${DATEMODIFY(NOW(), 2, 'days')}"
}
]
}
```
## 限制范围
可以通过配置`maxDate`和`minDate`显示可选范围
### 固定时间值
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "start",
"label": "开始时间",
"minDate": "1591862818",
"description": "限制可选最小日期是 <code>2020-06-11 16:06:58</code>"
},
{
"type": "input-date",
"name": "end",
"label": "结束时间",
"maxDate": "1591862818",
"description": "限制可选最大日期是 <code>2020-06-11 16:06:58</code>"
}
]
}
```
### 支持相对值
范围限制也支持设置 [相对值](./input-date#%E7%9B%B8%E5%AF%B9%E5%80%BC)。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "start",
"label": "开始时间",
"minDate": "-1days",
"description": "限制可选最小日期是昨天"
}
]
}
```
### 支持模板
也支持通过[模板](./template),设置自定义值。
来一个常见例子,配置两个选择`开始时间`和`结束时间`的时间选择器,需要满足:`开始时间`不能大于`结束时间`,`结束时间`也不能小于`开始时间`。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "start",
"label": "开始日期",
"maxDate": "$end"
},
{
"type": "input-date",
"name": "end",
"label": "结束日期",
"minDate": "$start"
}
]
}
```
### 通过 js 来控制
> 3.3.0 及以上版本
可以通过 `disabledDate` 字符函数来控制,比如不允许选择周一、周六、周日
函数签名: `(currentDate: moment.Moment, props: any) => boolean`
示例: `"return currentDate.day() == 1 || currentDate.day() == 0 || currentDate.day() == 6"`
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "start",
"label": "开始时间",
"description": "限制不能选周一、周六、周日",
"disabledDate": "return currentDate.day() == 1 || currentDate.day() == 0 || currentDate.day() == 6"
}
]
}
```
## 快捷键
你也可以配置`shortcuts`属性支持快捷选择日期
> 注:移动端 picker 的形式不支持快捷键
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"shortcuts": ["yesterday", "today", "tomorrow"]
}
]
}
```
上例中我们配置了`"shortcuts": ["yesterday" ,"today", "tomorrow"]`,选择器顶部有将会显示快捷键`昨天`,`今天`和`明天`
支持的快捷键有
- `today`: 今天
- `yesterday`: 昨天
- `thisweek`: 本周一
- `thismonth`: 本月初
- `prevmonth`: 上个月初
- `prevquarter`: 上个季节初
- `thisquarter`: 本季度初
- `tomorrow`: 明天
- `endofthisweek`: 本周日
- `endofthismonth`:本月底
- `endoflastmonth`:上月底
- `{n}daysago` : n 天前,例如:`2daysago`,下面用法相同
- `{n}dayslater`: n 天后
- `{n}weeksago`: n 周前
- `{n}weekslater`: n 周后
- `{n}monthsago`: n 月前
- `{n}monthslater`: n 月后
- `{n}quartersago`: n 季度前
- `{n}quarterslater`: n 季度后
快捷键也支持使用表达式的写法,可以使用这种方式自定义快捷键
> 3.1.0 及以上版本
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"shortcuts": [
{
"label": "前天",
"date": "${STARTOF(DATEMODIFY(NOW(), -2, 'day'))}"
},
"yesterday",
"today"
]
}
]
}
```
## UTC
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "date",
"label": "普通日期",
"format": "YYYY-MM-DD"
},
{
"type": "input-date",
"name": "date-utc",
"label": "UTC日期",
"utc": true,
"format": "YYYY-MM-DD"
}
]
}
```
## 内嵌模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "static-date",
"name": "date",
"label": "当前值"
},
{
"type": "input-date",
"name": "date",
"label": "日期",
"embed": true
}
]
}
```
## 原生日期组件
原生数字日期将直接使用浏览器的实现,最终展现效果和浏览器有关,而且只支持 `min`、`max`、`step` 这几个属性设置。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "native-date",
"name": "date",
"label": "日期"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | -------------------------------------------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------- |
| value | `string` | | [默认值](./date#%E9%BB%98%E8%AE%A4%E5%80%BC) |
| valueFormat | `string` | `X` | 日期选择器值格式,更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 3.4.0 版本后支持 |
| displayFormat | `string` | `YYYY-MM-DD` | 日期选择器显示格式,即时间戳格式,更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 3.4.0 版本后支持 |
| closeOnSelect | `boolean` | `false` | 点选日期后,是否马上关闭选择框 |
| placeholder | `string` | `"请选择日期"` | 占位文本 |
| shortcuts | `string \| string[] \| Array<{"label": string; date: string}>` | | 日期快捷键,字符串格式为预设值,对象格式支持写表达式 | `3.1.0`版本后支持表达式 |
| minDate | `string` | | 限制最小日期 |
| maxDate | `string` | | 限制最大日期 |
| utc | `boolean` | `false` | 保存 utc 值 |
| clearable | `boolean` | `true` | 是否可清除 |
| embed | `boolean` | `false` | 是否内联模式 |
| disabledDate | `string` | | 用字符函数来控制哪些天不可以被点选 |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`format`,例如:'1650556800' |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"id": "clear_text",
"value": "1714060800"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"id": "reset_text",
"value": "1714060800"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-date",
"name": "date",
"label": "日期",
"id": "setvalue_text",
"value": "1714060800"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "1714233600"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,163 @@
---
title: InputDatetimeRange 日期时间范围
description:
type: 0
group: null
menuName: InputDatetimeRange
icon:
order: 16
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime-range",
"name": "select",
"label": "日期时间范围"
}
]
}
```
## 时间显示到秒
通过 `"timeFormat": "HH:mm:ss"` 设置时间输入框显示秒
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime-range",
"name": "select",
"timeFormat": "HH:mm:ss",
"label": "日期时间范围"
}
]
}
```
## 快捷键
`shortcuts`属性支持自定义日期时间范围快捷键
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime-range",
"name": "select",
"label": "日期范围",
"shortcuts": "today,yesterday,1dayago,7daysago"
}
]
}
```
快捷键也支持使用表达式的写法,可以使用这种方式自定义快捷键
> 3.1.0 及以上版本
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime-range",
"name": "select",
"label": "日期范围",
"inputFormat": "YYYY-MM-DD HH:mm:ss",
"timeFormat": "HH:mm:ss",
"format": "x",
"shortcuts": [
{
"label": "1天前",
"startDate": "${DATEMODIFY(NOW(), -1, 'day')}",
"endDate": "${NOW()}"
},
{
"label": "1个月前",
"startDate": "${DATEMODIFY(NOW(), -1, 'months')}",
"endDate": "${NOW()}"
},
{
"label": "本季度",
"startDate": "${STARTOF(NOW(), 'quarter')}",
"endDate": "${ENDOF(NOW(), 'quarter')}"
}
]
}
]
}
```
## 存成两个字段
默认日期范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime-range",
"name": "begin",
"extraName": "end",
"label": "日期范围"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | ---------------------------------------------------------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ----------------------- |
| valueFormat | `string` | `X` | [日期时间选择器值格式](./input-datetime#%E5%80%BC%E6%A0%BC%E5%BC%8F) | 3.4.0 版本后支持 |
| displayFormat | `string` | `YYYY-MM-DD` | [日期时间选择器显示格式](./input-datetime#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) | 3.4.0 版本后支持 |
| placeholder | `string` | `"请选择日期范围"` | 占位文本 |
| shortcuts | `string \| string[] \| Array<{label: string; startDate: string; endDate: string}>` | `"yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter"` | 日期范围快捷键,详情参考[快捷键](./input-date-range#快捷键) | `3.1.0`版本后支持表达式 |
| minDate | `string` | | 限制最小日期时间,用法同 [限制范围](./input-datetime#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| maxDate | `string` | | 限制最大日期时间,用法同 [限制范围](./input-datetime#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| utc | `boolean` | `false` | [保存 UTC 值](./input-datetime#utc) |
| clearable | `boolean` | `true` | 是否可清除 |
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
| extraName | `string` | | 是否存成两个字段 | `3.3.0` |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------------- | -------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,依赖格式`format`,例如 '1650556800,1652889599' |

View File

@@ -0,0 +1,451 @@
---
title: InputDatetime 日期时间
description:
type: 0
group: null
menuName: InputDatetime
icon:
order: 14
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期时间"
}
]
}
```
## 显示格式
选中任意日期时间,可以看到默认显示日期的格式是像`2020-04-14 12:20:10`这样的格式,如果你想要自定义显示格式,那么可以配置`inputFormat`。
例如你想显示`2020年04月14日 12时20分10秒`这样的格式,查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY年MM月DD日 HH时mm分ss秒`,即:
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期时间",
"inputFormat": "YYYY年MM月DD日 HH时mm分ss秒"
}
]
}
```
选中任意日期时间,观察显示格式
## 值格式
选中任意日期时间,可以看到默认表单项的值格式是像`1591862818`这样的时间戳格式。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期时间"
}
]
}
```
如果你想要其他格式的日期值,那么可以配置`format`参数用于调整表单项的值格式。
例如你调整值为`2020-04-14 12:20:10`这样的格式,查找 [moment 文档](https://momentjs.com/docs/#/displaying/format/) 可知配置格式应为 `YYYY-MM-DD HH:mm:ss`,即:
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期时间",
"format": "YYYY-MM-DD HH:mm:ss"
}
]
}
```
选中任意日期时间,观察数据域中表单项值的变化
## 默认值
可以设置`value`属性,设置日期选择器的默认值
### 基本配置
配置符合当前 [值格式](./datetime#%E5%80%BC%E6%A0%BC%E5%BC%8F) 的默认值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期时间",
"value": "1591862818"
}
]
}
```
### 相对值
`value` 还支持类似像`"+1hours"`这样的相对值,更加便捷的配置默认值
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期",
"value": "+1hours"
}
]
}
```
上例中配置了`"value": "+1hours"`,默认就会选中一小时后的时间。
支持的相对值关键字除了 [Date](./input-date#%E7%9B%B8%E5%AF%B9%E5%80%BC) 中的以外,还支持:
- `now`: 当前时间
- `minute`或`minutes`或`min`或`mins`: 分钟
- `hour`或`hours`: 小时
## 限制范围
### 控制时间范围
通过 `timeConstraints` 属性可以控制时间输入范围
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期时间",
"timeConstraints": {
"hours": {
"min": 12,
"max": 18
},
"minutes": {
"step": 15
}
}
}
]
}
```
可以通过配置`maxDate`和`minDate`显示可选范围
### 固定时间值
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "start",
"label": "开始时间",
"minDate": "1591862818",
"description": "限制可选最小日期是 <code>2020-06-11 16:06:58</code>"
},
{
"type": "input-datetime",
"name": "end",
"label": "结束时间",
"maxDate": "1591862818",
"description": "限制可选最大日期是 <code>2020-06-11 16:06:58</code>"
}
]
}
```
### 支持相对值
范围限制也支持设置 [相对值](./input-date#%E7%9B%B8%E5%AF%B9%E5%80%BC)。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "start",
"label": "开始时间",
"minDate": "-1days",
"description": "限制可选最小日期是昨天"
}
]
}
```
### 支持模板
也支持通过[模板](./template),设置自定义值。
来一个常见例子,配置两个选择`开始时间`和`结束时间`的时间选择器,需要满足:`开始时间`不能小于`结束时间`,`结束时间`也不能大于`开始时间`。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "start",
"label": "开始时间",
"maxDate": "$end"
},
{
"type": "input-datetime",
"name": "end",
"label": "结束时间",
"minDate": "$start"
}
]
}
```
### 通过 js 来控制
> 3.3.0 及以上版本
可以通过 `disabledDate` 字符函数来控制,比如不允许选择周一、周六、周日
函数签名: `(currentDate: moment.Moment, props: any) => boolean`
示例: `"return currentDate.day() == 1 || currentDate.day() == 0 || currentDate.day() == 6"`
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "start",
"label": "开始时间",
"description": "限制不能选周一、周六、周日",
"disabledDate": "return currentDate.day() == 1 || currentDate.day() == 0 || currentDate.day() == 6"
}
]
}
```
## 快捷键
你也可以配置`shortcuts`属性支持快捷选择日期
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期",
"shortcuts": ["yesterday" ,"today", "tomorrow"]
}
]
}
```
上例中我们配置了`"shortcuts": ["yesterday" ,"today", "tomorrow"]`,选择器顶部有将会显示快捷键`昨天`,`今天`和`明天`
除了支持 的快捷键有
支持的快捷键除了 [Date](./date#%E5%BF%AB%E6%8D%B7%E9%94%AE) 中的以外,还支持:
- `now`: 现在
- `{n}hoursago` : n 小时前,例如:`2hoursago`,下面用法相同
- `{n}hourslater` : n 小时后,例如:`2hourslater`,下面用法相同
快捷键也支持使用表达式的写法,可以使用这种方式自定义快捷键
> 3.1.0 及以上版本
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期",
"shortcuts": [
{
"label": "前天",
"date": "${STARTOF(DATEMODIFY(NOW(), -2, 'day'))}"
},
"yesterday",
"today"
]
}
]
}
```
## UTC
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "普通日期时间",
"format": "YYYY-MM-DD HH:mm:ss"
},
{
"type": "input-datetime",
"name": "datetime-utc",
"label": "UTC日期时间",
"utc": true,
"format": "YYYY-MM-DD HH:mm:ss"
}
]
}
```
## 内嵌模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "static-date",
"name": "date",
"format": "LLL",
"label": "当前值"
},
{
"type": "input-datetime",
"name": "date",
"label": "日期时间",
"embed": true
}
]
}
```
## 确认模式
> `3.6.0`及以上版本
设置`"closeOnSelect": false`,点选日期时间后,不会自动关闭浮层,需要点击底部工具栏的确认才会关闭。点击**取消按钮**或者**浮层外部区域**也会关闭浮层,并将值重置为初始状态。
> 注意:该特性仅对`input-datetime`有效,其他日期时间组件无效。开启内嵌模式后,该特性无效。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-datetime",
"name": "datetime",
"label": "日期时间",
"shortcuts": ["yesterday", "today", "tomorrow"],
"closeOnSelect": false,
"valueFormat": "YYYY-MM-DD HH:mm:ss",
"displayFormat": "YYYY-MM-DD HH:mm:ss",
"clearable": true
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | -------------------------------------------------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------- | ----------------------- |
| value | `string` | | [默认值](./datetime#%E9%BB%98%E8%AE%A4%E5%80%BC) |
| valueFormat | `string` | `X` | 日期时间选择器值格式,更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 3.4.0 版本后支持 |
| displayFormat | `string` | `YYYY-MM-DD HH:mm:ss` | 日期时间选择器显示格式,即时间戳格式,更多格式类型请参考 [文档](https://momentjs.com/docs/#/displaying/format/) | 3.4.0 版本后支持 |
| placeholder | `string` | `"请选择日期以及时间"` | 占位文本 |
| shortcuts | `string \| string[] \| Array<{"label": string; date: string}>` | | 日期时间快捷键 | `3.1.0`版本后支持表达式 |
| minDate | `string` | | 限制最小日期时间 |
| maxDate | `string` | | 限制最大日期时间 |
| utc | `boolean` | `false` | 保存 utc 值 |
| clearable | `boolean` | `true` | 是否可清除 |
| embed | `boolean` | `false` | 是否内联 |
| timeConstraints | `object` | `true` | 请参考 [input-time](./input-time#控制输入范围) 里的说明 |
| isEndDate | `boolean` | `false` | 如果配置为 true,会自动默认为 23:59:59 秒 |
| disabledDate | `string` | | 用字符函数来控制哪些天不可以被点选 |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0`版本后支持 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`format`,例如:'1650556800' |

View File

@@ -0,0 +1,438 @@
---
title: InputExcel 解析 Excel
description:
type: 0
group: null
menuName: InputExcel
icon:
order: 14
---
这个组件是通过前端对 Excel 进行解析,将结果作为表单项,使用它有两个好处:
1. 节省后端开发成本,无需再次解析 Excel
2. 可以前端实时预览效果,比如配合 input-table 组件进行二次修改
> 2.10.0 以上版本支持 xls 文件格式,2.9.0 及以下版本只支持 xlsx
## 基本使用
默认情况下只解析第一个 sheet 的内容,下面的例子中,选择上传文件后,就能知道最终会解析成什么数据
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"label": "上传 Excel"
}
]
}
```
默认模式是解析成对象数组,将第一行作为对象里的键,可以上传一个类似这样的 Excel 内容试试
```
|名称|网址|
|amis|https://baidu.gitee.io/amis|
|百度|https://www.baidu.com|
```
解析后的的数据格式将会是
```json
[
{
"名称": "amis",
"网址": "https://baidu.gitee.io/amis"
},
{
"名称": "百度",
"网址": "https://www.baidu.com"
}
]
```
可以配合 `input-table` 来实现上传后二次编辑
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-excel",
"name": "excel",
"label": "上传 Excel",
"placeholder": "请拖拽Excel文件到当前区域"
},
{
"type": "input-table",
"name": "excel",
"visibleOn": "data.excel",
"columns": [
{
"name": "名称",
"label": "名称",
"type": "input-text"
},
{
"name": "网址",
"label": "网址",
"type": "input-text"
}
]
}
]
}
```
需要保证 `input-table` 的 `name` 和 `input-excel` 一致,同时 `columns` 中的 `name` 也需要和 Excel 的列名一致。
## 二维数组模式
除了默认配置的对象数组格式,还可以使用二维数组方式,方法是设置 `"parseMode": "array"`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"parseMode": "array",
"label": "上传 Excel"
}
]
}
```
如果是前面的例子,解析结果将会是
```json
[
["名称", "网址"],
["amis", "https://baidu.gitee.io/amis"],
["百度", "https://www.baidu.com"]
]
```
## 解析多个 sheet
默认配置只解析第一个 sheet,如果要解析多个 sheet,可以通过 `"allSheets": true` 开启多个 sheet 的读取,这时的数据会增加一个层级。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"allSheets": true,
"label": "上传 Excel"
}
]
}
```
如果按之前的例子,结果将会是
```json
[
{
"sheetName": "Sheet1",
"data": [
{
"名称": "amis",
"网址": "https://baidu.gitee.io/amis"
},
{
"名称": "百度",
"网址": "https://www.baidu.com"
}
]
}
]
```
## 解析多个文件
可以配置"multiple": true,来开启多文件解析功能,通过"maxLength": 5,来限制最多上传5个文件。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"allSheets": true,
"label": "上传 Excel",
"multiple": true,
"maxLength": 5
}
]
}
```
## 解析图片
> 2.6.0 及以上版本
通过配置 `parseImage` 来支持解析 excel 里的图片
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"parseImage": true,
"label": "上传 Excel"
}
]
}
```
默认情况下解析结果是 data URI 格式,如果不想要这个前缀可以通过 `"imageDataURI": false` 关闭
## 富文本模式
默认情况下 Excel 内容将会解析为纯文本,如果要使用富文本格式,可以通过 `plainText` 属性控制
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"plainText": false,
"label": "上传 Excel"
}
]
}
```
开启这个模式后,对于富文本的内容会解析成对象的形式,有以下几种
- 富文本,内容放在 richText 属性下
```
{
"richText": [
{text: 'This is '},
{font: {italic: true}, text: 'italic'}
]
}
```
- 出错
```
{ error: '#N/A' }
```
- 公式
```
{ formula: 'A1+A2', result: 7 };
```
- 超链接
```
{
text: 'www.mylink.com',
hyperlink: 'http://www.mylink.com',
tooltip: 'www.mylink.com'
}
```
## 解析文件名称
> `3.5.0`及以上版本
文件解析成功后,可以使用`autoFill`属性,在当前组件所在的数据域中填充值,`input-excel`组件特有的保留字段请查看下方定义,`InputExcelData`中的字段可以用变量获取。通常可以利用这个属性为`input-excel`所在的表单追加文件名称。
```typescript
interface InputExcelData {
/* 文件名称 */
filename: string;
}
```
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"label": "上传 Excel",
"autoFill": {
"operator": "amis",
"time": "${DATETOSTR(NOW(), 'YYYY-MM-DD HH:mm:ss')}",
"fileName": "${filename}"
}
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
|--------------|--------------------------|-----------------------|--------------|----------|
| allSheets | `boolean` | false | 是否解析所有 sheet |
| parseMode | `'array'` 或 `'object'` | 'object' | 解析模式 |
| includeEmpty | `boolean` | true | 是否包含空值 |
| plainText | `boolean` | true | 是否解析为纯文本 |
| placeholder | `string` | `"拖拽 Excel 到这,或点击上传"` | 占位文本提示 | `2.8.1` |
| autoFill | `Record<string, string>` | | 自动填充 | `3.5.0` |
| multiple | `boolean` | | 解析多个文件 | `6.13.0` |
| maxLength | `number` | | 解析文件最大数 | `6.13.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------------------------------------ | ------------------------ |
| change | `[name]: Array<object>` 组件的值(excel 解析后的数据) | excel 上传解析完成后触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: Array<object>` 更新的 excel 解析后数据 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"label": "上传 Excel",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"label": "上传 Excel",
"id": "reset_text",
"value": [
{
"ID": "1",
"NAME": "amis"
}
]
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-excel",
"name": "excel",
"label": "上传 Excel",
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": [
{
"ID": "1",
"NAME": "amis"
}
]
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,538 @@
---
title: InputFile 文件上传
description:
type: 0
group: null
menuName: InputFile
icon:
order: 21
---
## 基本用法
用来负责文件上传,文件上传成功后会返回文件地址,这个文件地址会作为这个表单项的值,整个表单提交的时候,其实提交的是文件地址,文件上传已经在这个控件中完成了。
> 如果希望文件内容伴随表单一起提交,可以配置 `asBlob` 或者 `asBase64`。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-file",
"name": "file",
"label": "File",
"accept": "*",
"receiver": "/api/upload/file"
}
]
}
```
### 接口说明
这是单文件上传模式,通过配置 `receiver` 来接管文件上传。
接口发送方式是 POST, 数据体为 form-data 格式。对应的文件字段名为 `file`。这个可以通过 `fileField` 来配置。要求返回的数据格式如下。
```json
{
"status": 0,
"msg": "",
"data": {
"value": "xxxx"
}
}
```
- value:必须返回该字段用作回显,一般是文件资源地址
> 注意这只是单文件上传部分,如果允许上传的文件比较大,建议用分块上传,请阅读下面的分块上传部分。
## 限制文件类型
可以配置`accept`来限制可选择的文件类型,格式是文件后缀名`.xxx`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-file",
"name": "file",
"label": "限制只能上传csv文件",
"accept": ".csv",
"receiver": "/api/upload/file"
}
]
}
```
想要限制多个类型,则用逗号分隔,例如:`.csv,.md`
## 限制文件大小
可以配置`maxSize`来限制文件大小
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-file",
"name": "file",
"label": "不能上传超过 1M 的文件",
"maxSize": 1048576,
"receiver": "/api/upload/file"
}
]
}
```
## 手动上传
默认`"autoUpload": true`,即添加文件后自动上传。可以设置`"autoUpload": false`关闭自动上传,此时通过点击上传按钮上传。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"data": {
"file": {
"id":"2ba48d02d348",
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"filename":"file(single).md",
"name":"file(single).md",
"state":"uploaded"
},
"files": [
{
"id":"2ba48d02d349",
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"filename":"file1.md",
"name":"file1.md",
"state":"uploaded"
},
{
"id":"14723e0bc640",
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"filename":"file2.md",
"name":"file2.md",
"state":"uploaded"
}
]
},
"body": [
{
"type": "input-file",
"name": "files",
"label": "File(多选)",
"mode": "horizontal",
"labelAlign": "left",
"accept": "*",
"receiver": "/api/upload/file",
"multiple": true,
"autoUpload": false,
"joinValues": false,
"onEvent": {
"success": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "info",
"msg": "「${event.data.path}」上传成功"
}
}
]
}
}
},
{
"type": "input-file",
"name": "file",
"label": "File(单选)",
"mode": "horizontal",
"labelAlign": "left",
"accept": "*",
"receiver": "/api/upload/file",
"multiple": false,
"autoUpload": false,
"joinValues": false,
"onEvent": {
"success": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "info",
"msg": "「${event.data.path}」上传成功"
}
}
]
}
}
}
]
}
```
## 作为表单项上传
如果不希望 InputFile 组件在提交 Form 之前上传,可以配置 `asBlob` 或者 `asBase64`,采用这种方式后,组件不再自己上传了,而是直接把文件数据作为表单项的值,文件内容会在 Form 表单提交的接口里面一起带上。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-file",
"name": "file",
"label": "File",
"accept": "*",
"asBlob": true
}
]
}
```
上例中,选择任意文件,然后观察数据域变化;点击提交,amis 自动会调整接口数据格式为`FormData`
## 分块上传
如果文件过大,则可能需要使用分块上传,默认大于 5M(chunkSize 配置决定) 的文件是会自动开启,可以通过 `useChunk` 配置成 false 关闭。
分块上传需要配置三个接口来完成分别是:
- `startChunkApi` 用来做分块前的准备工作
- `chunkApi` 用来接收每个分块上传
- `finishChunkApi` 用来收尾分块上传
还可以通过 `concurrency` 控制并行数量,默认是 3
### startChunkApi
用来做分块前的准备工作,一个文件只会调用一次。如果出错了,后续的分块上传就会中断。
发送说明:默认是 post,发送的数据中会包含 `filename` 字段,记录文件名,默认的数据体格式为 json。可以额外配置参数,请参考 API 的配置说明。
要求返回的数据中必须包含:
- `uploadId` 这次上传的唯一 ID。
- `key` 有点类似 `uploadId`,可有可无,爱速搭中用来记录后端文件存储路径。
其他属性返回目前是没有任何作用的。
如:
```
{
"status": 0,
"msg": "",
"data": {
"key": "images/JSSDK_page-xxxx.zip",
"uploadId": "036f64cd5dd95750d4bcb33556b629c6"
}
}
```
### chunkApi
用来接收每个分块上传,大文件会根据 chunkSize 分割成多块,然后每块上传都会调用这个接口。
发送说明:默认为 post,发送体格式为 form-data。包含以下信息:
- `uploadId` startChunkApi 返回的
- `key` startChunkApi 返回的
- `partNumber` 分块序号,从 1 开始。
- `partSize` 分块大小
- `file` 文件体
要求返回的数据中必须包含:
- `eTag` 通常为文件的内容戳。
如:
```
{
"status": 0,
"msg": "",
"data": {
"eTag": "016bd9b68ddd5cd7318875da3ea28207"
}
}
```
### finishChunkApi
等所有分块上传完后,将上传文件收集到的 `eTag` 信息合并一起,再次请求后端完成文件上传。
发送说明:默认为 post,数据体默认为 json,包含以下信息
- `filename` 文件名
- `key` startChunkApi 返回的
- `uploadId` startChunkApi 返回的
- `partList` 数组,每个成员为 `{partNumber: xxx, eTag: "xxxxx"}` 即分块编号和分块 `eTag` 信息。
数据返回,类似单文件上传一样,必须有 `value` 属性,可选返回 `url` 用来决定文件的下载地址。如:
```
{
"status": 0,
"msg": "",
"data": {
"value": "https://xxxx.cdn.bcebos.com/images/JSSDK_page-xxxxx.zip"
}
}
```
## 自动填充
上传成功后,可以通过配置 `autoFill` 将上传接口返回的值填充到某个表单项中(在非表单下暂不支持):
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-file",
"name": "file",
"label": "File",
"accept": "*",
"receiver": "/api/upload/file",
"autoFill": {
"myUrl": "${url}"
}
},
{
"type": "input-text",
"name": "myUrl",
"label": "url"
}
]
}
```
上例中,file 组件上传后,接口返回格式例如如下:
```json
{
"status": 0,
"msg": "",
"data": {
"value": "xxxxxxx",
"filename": "xxxx.csv",
"url": "http://xxxx.xxx.xxx"
}
}
```
然后 file 上配置:
```json
"autoFill": {
"myUrl": "${url}"
}
```
这样上传成功后,会把接口中的 `url` 变量,赋值给 `myUrl` 变量
**多选模式**
当表单项为多选模式时,不能再直接取选项中的值了,而是通过 `items` 变量来取,通过它可以获取当前选中的选项集合。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-file",
"name": "file",
"label": "File",
"multiple": true,
"receiver": "/api/upload/file",
"autoFill": {
"myUrl": "${items|pick:url}",
"lastUrl": "${items|last|pick:url}"
}
}
]
}
```
## 拖拽上传
把文件拖入指定区域,完成上传,同样支持点击上传。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-file",
"name": "file",
"label": "File",
"accept": "*",
"receiver": "/api/upload/file",
"drag": true
}
]
}
```
## 上传文件列表
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"data": {
"files": [
{
"id":"2ba48d02d349",
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"filename":"file1.md",
"name":"file1.md",
"state":"uploaded"
},
{
"id":"14723e0bc640",
"value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md",
"filename":"file2.md",
"name":"file2.md",
"state":"uploaded"
}
]
},
"body": [
{
"type": "input-file",
"name": "files",
"label": false,
"mode": "horizontal",
"accept": "*",
"receiver": "/api/mock2/upload/random",
"multiple": true,
"joinValues": false
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------------ | ------------------------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| receiver | [API](../../../docs/types/api) | | 上传文件接口 |
| accept | `string` | `text/plain` | 默认只支持纯文本,要支持其他类型,请配置此属性为文件后缀`.xxx` |
| capture | `string` | `undefined` | 用于控制 input[type=file] 标签的 capture 属性,在移动端可控制输入来源 |
| asBase64 | `boolean` | `false` | 将文件以`base64`的形式,赋值给当前组件 |
| asBlob | `boolean` | `false` | 将文件以二进制的形式,赋值给当前组件 |
| maxSize | `number` | | 默认没有限制,当设置后,文件大小大于此值将不允许上传。单位为`B` |
| maxLength | `number` | | 默认没有限制,当设置后,一次只允许上传指定数量文件。 |
| multiple | `boolean` | `false` | 是否多选。 |
| drag | `boolean` | `false` | 是否为拖拽上传 |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
| autoUpload | `boolean` | `true` | 否选择完就自动开始上传 |
| hideUploadButton | `boolean` | `false` | 隐藏上传按钮 |
| stateTextMap | object | `{ init: '', pending: '等待上传', uploading: '上传中', error: '上传出错', uploaded: '已上传', ready: '' }` | 上传状态文案 |
| fileField | `string` | `file` | 如果你不想自己存储,则可以忽略此属性。 |
| nameField | `string` | `name` | 接口返回哪个字段用来标识文件名 |
| valueField | `string` | `value` | 文件的值用那个字段来标识。 |
| urlField | `string` | `url` | 文件下载地址的字段名。 |
| btnLabel | `string` | | 上传按钮的文字 |
| downloadUrl | `boolean`或`string` | `""` 1.1.6 版本开始支持 `post:http://xxx.com/${value}` 这种写法 | 默认显示文件路径的时候会支持直接下载,可以支持加前缀如:`http://xx.dom/filename=` ,如果不希望这样,可以把当前配置项设置为 `false`。 |
| useChunk | `boolean`或`"auto"` | `"auto"` | amis 所在服务器,限制了文件上传大小不得超出 10M,所以 amis 在用户选择大文件的时候,自动会改成分块上传模式。 |
| chunkSize | `number` | `5 * 1024 * 1024` | 分块大小 |
| startChunkApi | [API](../../../docs/types/api) | | startChunkApi |
| chunkApi | [API](../../../docs/types/api) | | chunkApi |
| finishChunkApi | [API](../../../docs/types/api) | | finishChunkApi |
| concurrency | `number` | | 分块上传时并行个数 |
| documentation | `string` | | 文档内容 |
| documentLink | `string` | | 文档链接 |
| initAutoFill | `boolean` | `true` | 初表单反显时是否执行 |
| invalidTypeMessage | `string` | | 校验格式失败后的提示信息 可以用{{}}获取内部变量值,如{{accept}} |
| invalidSizeMessage | `string` | | 校验文件大小失败时显示的文字信息 可以用{{}}获取内部变量值,如{{maxSize}} |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`file`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| change | `[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传文件值变化时触发(上传失败同样会触发) |
| remove | `item: FileValue` 被移除的文件<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 移除文件时触发 |
| success | `item: FileValue` 上传的文件<br/>`result: any` 远程上传请求成功后接口返回的结果数据<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传成功时触发 |
| fail | `item: FileValue` 上传的文件 <br /> `error: object` 远程上传请求失败后返回的错误信息<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传文件失败时触发 |
### FileValue 属性表
| 属性名 | 类型 | 说明 |
| ------ | -------- | -------------------------------------------------- |
| name | `string` | 文件名称 |
| value | `string` | 上传成功后返回的 url |
| state | `string` | 文件当前状态,值可为 `pending` `uploaded` `invalid` |
| error | `string` | 错误信息 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | -------- | ---- |
| clear | - | 清空 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-file",
"name": "file",
"label": "File",
"accept": "*",
"receiver": "/api/upload/file",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,545 @@
---
title: InputFormula 公式编辑器
description:
type: 0
group: null
menuName: InputFormula
icon:
order: 21
---
## 基本用法
用来输入公式。还是 beta 版本,整体待优化。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-formula",
"name": "formula",
"label": "公式",
"evalMode": true,
"value": "SUM(1 , user.id)",
"variables": [
{
"label": "表单字段",
"children": [
{
"label": "文章名",
"value": "name",
"tag": "文本"
},
{
"label": "作者",
"value": "author",
"tag": "文本"
},
{
"label": "售价",
"value": "price",
"tag": "数字"
},
{
"label": "出版时间",
"value": "time",
"tag": "时间"
},
{
"label": "版本号",
"value": "version",
"tag": "数字"
},
{
"label": "出版社",
"value": "publisher",
"tag": "文本"
}
]
},
{
"label": "流程字段",
"children": [
{
"label": "联系电话",
"value": "telphone"
},
{
"label": "地址",
"value": "addr"
}
]
},
{
"label": "人员对象",
"value": "user",
"children": [
{
"label": "ID",
"value": "user.id"
},
{
"label": "用户名",
"value": "user.name"
},
]
},
{
"label": "长文本测试分类长文本测试分类长文本测试分类长文本测试分类",
"children": [
{
"label": "这是一段测试长文本这是一段测试长文本这是一段测试长文本",
"value": "longtext",
"tag": "文本"
}
]
}
],
}
]
}
```
## 展示模式
设置`"inputMode": "button"`可以切换编辑器的展示模式为按钮模式。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-formula",
"name": "formula",
"label": "公式",
"variableMode": "tree",
"evalMode": true,
"value": "SUM(1 , 2)",
"inputMode": "button",
"variables": [
{
"label": "表单字段",
"children": [
{
"label": "文章名",
"value": "name",
"tag": "文本"
},
{
"label": "作者",
"value": "author",
"tag": "文本"
},
{
"label": "售价",
"value": "price",
"tag": "数字"
},
{
"label": "出版时间",
"value": "time",
"tag": "时间"
},
{
"label": "版本号",
"value": "version",
"tag": "数字"
},
{
"label": "出版社",
"value": "publisher",
"tag": "文本"
}
]
},
{
"label": "流程字段",
"children": [
{
"label": "联系电话",
"value": "telphone"
},
{
"label": "地址",
"value": "addr"
}
]
}
],
}
]
}
```
设置`"inputMode": "input-group"`可以切换编辑器的展示模式为输入框组合模式,1.10.0 及以上版本。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-formula",
"name": "formula",
"label": "公式",
"variableMode": "tree",
"evalMode": true,
"value": "SUM(1 , 2)",
"inputMode": "input-group",
"variables": [
{
"label": "表单字段",
"children": [
{
"label": "文章名",
"value": "name",
"tag": "文本"
},
{
"label": "作者",
"value": "author",
"tag": "文本"
},
{
"label": "售价",
"value": "price",
"tag": "数字"
},
{
"label": "出版时间",
"value": "time",
"tag": "时间"
},
{
"label": "版本号",
"value": "version",
"tag": "数字"
},
{
"label": "出版社",
"value": "publisher",
"tag": "文本"
}
]
},
{
"label": "流程字段",
"children": [
{
"label": "联系电话",
"value": "telphone"
},
{
"label": "地址",
"value": "addr"
}
]
}
],
}
]
}
```
## 变量展示模式
设置不同`variableMode`字段切换变量展示模式,树形结构:
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-formula",
"name": "formula",
"label": "公式",
"variableMode": "tree",
"evalMode": true,
"variables": [
{
"label": "表单字段",
"children": [
{
"label": "文章名",
"value": "name",
"tag": "文本"
},
{
"label": "作者",
"value": "author",
"tag": "文本"
},
{
"label": "售价",
"value": "price",
"tag": "数字"
},
{
"label": "出版时间",
"value": "time",
"tag": "时间"
},
{
"label": "版本号",
"value": "version",
"tag": "数字"
},
{
"label": "出版社",
"value": "publisher",
"tag": "文本"
}
]
},
{
"label": "流程字段",
"children": [
{
"label": "联系电话",
"value": "telphone"
},
{
"label": "地址",
"value": "addr"
}
]
}
],
}
]
}
```
Tab 结构:
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-formula",
"name": "formula",
"label": "公式",
"variableMode": "tabs",
"evalMode": false,
"variables": [
{
"label": "表单字段",
"children": [
{
"label": "文章名",
"value": "name",
"tag": "文本"
},
{
"label": "作者",
"value": "author",
"tag": "文本"
},
{
"label": "售价",
"value": "price",
"tag": "数字"
},
{
"label": "出版时间",
"value": "time",
"tag": "时间"
},
{
"label": "版本号",
"value": "version",
"tag": "数字"
},
{
"label": "出版社",
"value": "publisher",
"tag": "文本"
}
]
},
{
"label": "流程字段",
"children": [
{
"label": "联系电话",
"value": "telphone"
},
{
"label": "地址",
"value": "addr"
}
]
}
],
}
]
}
```
## 模板模式
当配置 `evalMode` 为 false 时则为模板模式,意思是说默认不当做表达式,只有 `${`和`}`包裹的部分才是表达式。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-formula",
"name": "formula",
"label": "公式",
"evalMode": false,
"value": "my name is \\${name}",
"variables": [
{
"label": "表单字段",
"children": [
{
"label": "文章名",
"value": "name",
"tag": "文本"
},
{
"label": "作者",
"value": "author",
"tag": "文本"
},
{
"label": "售价",
"value": "price",
"tag": "数字"
},
{
"label": "出版时间",
"value": "time",
"tag": "时间"
},
{
"label": "版本号",
"value": "version",
"tag": "数字"
},
{
"label": "出版社",
"value": "publisher",
"tag": "文本"
}
]
},
{
"label": "流程字段",
"children": [
{
"label": "联系电话",
"value": "telphone"
},
{
"label": "地址",
"value": "addr"
}
]
}
],
}
]
}
```
## 混合模式
混合模式的意思是支持输入文本和输入公式两种格式的值,当输入公式时值会自动用 `${` 和 `}` 包裹,如果不是这种格式则认为是输入普通的字符串。通过 `mixedMode` 为 true 启用这种模式
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-formula",
"name": "value",
"label": "混合模式",
"mixedMode": true,
"value": "\\${SUM(1, 2)}",
"variables": [
{
"label": "表单字段",
"children": [
{
"label": "文章名",
"value": "name",
"tag": "文本"
},
{
"label": "作者",
"value": "author",
"tag": "文本"
},
{
"label": "售价",
"value": "price",
"tag": "数字"
},
{
"label": "出版时间",
"value": "time",
"tag": "时间"
},
{
"label": "版本号",
"value": "version",
"tag": "数字"
},
{
"label": "出版社",
"value": "publisher",
"tag": "文本"
}
]
},
{
"label": "流程字段",
"children": [
{
"label": "联系电话",
"value": "telphone"
},
{
"label": "地址",
"value": "addr"
}
]
}
],
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| ----------------- | ------------------------------------------------------------------------------------------ | -------------- | ------------------------------------------------------------------------------ |
| title | `string` | `'公式编辑器'` | 弹框标题 |
| header | `string` | - | 编辑器 header 标题,如果不设置,默认使用表单项`label`字段 |
| evalMode | `boolean` | `true` | 表达式模式 或者 模板模式,模板模式则需要将表达式写在 `${` 和 `}` 中间。 |
| variables | `{label: string; value: string; children?: any[]; tag?: string}[]` | `[]` | 可用变量 |
| variableMode | `string` | `list` | 可配置成 `tabs` 或者 `tree` 默认为列表,支持分组。 |
| functions | `Object[]` | - | 可以不设置,默认就是 amis-formula 里面定义的函数,如果扩充了新的函数则需要指定 |
| inputMode | `'button' \| 'input-button' \| 'input-group'` | - | 控件的展示模式 |
| icon | `string` | - | 按钮图标,例如`fa fa-list` |
| btnLabel | `string` | `'公示编辑'` | 按钮文本,`inputMode`为`button`时生效 |
| level | `'info' \| 'success' \| 'warning' \| 'danger' \| 'link' \| 'primary' \| 'dark' \| 'light'` | `default` | 按钮样式 |
| allowInput | `boolean` | - | 输入框是否可输入 |
| btnSize | `'xs' \| 'sm' \| 'md' \| 'lg'` | - | 按钮大小 |
| borderMode | `'full' \| 'half' \| 'none'` | - | 输入框边框模式 |
| placeholder | `string` | `'暂无数据'` | 输入框占位符 |
| className | `string` | - | 控件外层 CSS 样式类名 |
| variableClassName | `string` | - | 变量面板 CSS 样式类名 |
| functionClassName | `string` | - | 函数面板 CSS 样式类名 |

View File

@@ -0,0 +1,151 @@
---
title: Input-Group 输入框组合
description:
type: 0
group: null
menuName: Input-Group
icon:
order: 28
---
**输入框组合选择器** 可用于输入框与其他组件进行组合。
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-group",
"name": "input-group",
"label": "input 组合",
"body": [
{
"type": "input-text",
"placeholder": "搜索作业ID/名称",
"inputClassName": "b-r-none p-r-none",
"name": "input-group"
},
{
"type": "submit",
"label": "搜索",
"level": "primary"
}
]
},
{
"type": "input-group",
"label": "各种组合",
"body": [
{
"type": "select",
"name": "memoryUnits",
"options": [
{
"label": "Gi",
"value": "Gi"
},
{
"label": "Mi",
"value": "Mi"
},
{
"label": "Ki",
"value": "Ki"
}
],
"value": "Gi"
},
{
"type": "input-text",
"name": "memory"
},
{
"type": "select",
"name": "memoryUnits2",
"options": [
{
"label": "Gi",
"value": "Gi"
},
{
"label": "Mi",
"value": "Mi"
},
{
"label": "Ki",
"value": "Ki"
}
],
"value": "Gi"
},
{
"type": "button",
"label": "Go"
}
]
}
]
}
```
## 校验
input-group 配置校验方法较为特殊,需要配置下面步骤:
1. input-group 上配置任意`name`值 (必填, 否则表单内存在多个输入组合时无法定位)
2. input-group 的 body 内配置的表单项上配置校验规则
3. 如果 input-group 的子元素配置了`label`, 则会在校验失败时作为标识符展示, 否则仅使用索引值作为标识符
4. 单个子元素多条校验信息会使用`; `分隔
5. 可以使用`"errorMode": "full" | "partial"`设置错误提示风格, `full`整体飘红, `partial`仅错误元素飘红, 默认为`"full"`
> 细粒度错误提示需`2.7.1`及以上版本
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-group",
"name": "input-group",
"label": "输入组合校验",
"body": [
{
"type": "input-text",
"placeholder": "请输入长度不超过6的数字类型",
"name": "group-input1",
"label": "子元素一",
"validations": {
"isNumeric": true,
"maxLength": 6
},
},
{
"type": "input-text",
"placeholder": "请输入长度不少于5的文本",
"name": "group-input2",
"required": true,
"validations": {
"minLength": 5
}
}
]
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ---------------- | ----------------------------------------- | -------- | ----------------------------------------------------- | ------- |
| className | `string` | | CSS 类名 | |
| body | Array<[表单项](./formitem)> | | 表单项集合 | |
| validationConfig | `Record<'errorMode' \| 'delimiter', any>` | - | 校验相关配置, 具体配置属性如下 | `2.8.0` |
| +errorMode | `"full" \| "partial"` | `"full"` | 错误提示风格, `full`整体飘红, `partial`仅错误元素飘红 | `2.8.0` |
| +delimiter | `string` | `"; "` | 单个子元素多条校验信息的分隔符 | `2.8.0` |

View File

@@ -0,0 +1,770 @@
---
title: InputImage 图片
description:
type: 0
group: null
menuName: InputImage
icon:
order: 27
---
图片格式输入,需要实现接收器,提交时将以 url 的方式提交,如果需要以表单方式提交请使用 [InputFile](input-file#作为表单项上传)。
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "image",
"receiver": "/api/upload/file"
}
]
}
```
默认情况下,选中文件后,就会自动调用 `receiver` 配置里的接口进行上传,比如 node 版本的示例如下:
```javascript
const express = require('express');
const multer = require('multer');
const upload = multer({dest: 'uploads/'});
const app = express();
app.use(express.static('public'));
// 默认情况下是 file 字段名作为文件参数,也可以通过 fileField 配置来改成别的名字
app.post('/uploader', upload.single('file'), function (req, res, next) {
res.json({
status: 0,
data: {
value: '/' + req.file.path
}
});
});
// 配合上面的返回值,将 uploads 目录可读,这样返回的文件才能正常显示
app.get('uploads', express.static('uploads'));
app.listen(8080, function () {});
```
这个接口需要返回图片地址,比如下面的格式
```json
{
"status": 0,
"msg": "",
"data": {
"value": "https:/xxx.yy/zz.png"
}
}
```
点击表单提交的时候,实际提交的就是这个返回的图片地址,比如上面的例子是 `image`,则会提交
```
{
"image": "https:/xxx.yy/zz.png"
}
```
## 限制文件类型
可以配置`accept`来限制可选择的文件类型,格式是文件后缀名`.xxx`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "限制只能上传jpg图片",
"accept": ".jpg",
"receiver": "/api/upload/file"
}
]
}
```
想要限制多个类型,则用逗号分隔,例如:`.jpg,.png`
## 限制文件宽度
配置 `limit`,更多属性请参考后面的属性说明。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "限制只能上传宽度大于 1000 的图片",
"accept": ".jpg",
"limit": {
"minWidth": 1000
},
"receiver": "/api/upload/file"
}
]
}
```
## 限制文件大小
配置 `maxSize`,限制文件大小,单位为 `B`。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "上传文件不能大于 1K",
"accept": ".jpg",
"maxSize": 1024,
"receiver": "/api/upload/file"
}
]
}
```
## 支持裁剪
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "上传后裁剪",
"receiver": "/api/upload/file",
"crop": true
}
]
}
```
设置裁剪比例等配置,具体细节可以参考[这里](https://github.com/fengyuanchen/cropperjs#options)。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "上传后裁剪",
"receiver": "/api/upload/file",
"crop": {
"aspectRatio": 1.7777
}
}
]
}
```
默认情况下裁剪结果是 `png` 格式,如果要支持其它格式,请设置 `cropFormat`,比如下面设置为 `jpeg` 格式,同时设置质量为 `0.9`
> 1.4.0 及以上版本
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "上传后裁剪",
"receiver": "/api/upload/file",
"crop": true,
"cropFormat": "image/jpeg",
"cropQuality": 0.9
}
]
}
```
## 手动上传
默认`"autoUpload": true`,即添加文件后自动上传。可以设置`"autoUpload": false`关闭自动上传,此时通过点击底部上传按钮上传。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"data": {
"file": {
"id":"2ba48d02d348",
"value":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"url":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"filename":"file(single).md",
"name":"file(single).md",
"state":"uploaded"
},
"files": [
{
"id":"2ba48d02d349",
"value":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"url":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"preview": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"filename":"file1.md",
"name":"file1.md",
"state":"uploaded"
},
{
"id": "14723e0bc640",
"value": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"url": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"preview": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"filename":"file2.md",
"name":"file2.md",
"state":"uploaded"
}
]
},
"body": [
{
"type": "input-image",
"name": "files",
"label": "File(多选)",
"mode": "horizontal",
"labelAlign": "left",
"accept": "image/jpeg, image/jpg, image/png, image/gif",
"receiver": "/api/upload/file",
"multiple": true,
"autoUpload": false,
"joinValues": false,
"onEvent": {
"success": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "info",
"msg": "「${event.data.path}」上传成功"
}
}
]
}
}
},
{
"type": "input-image",
"name": "file",
"label": "File(单选)",
"mode": "horizontal",
"labelAlign": "left",
"accept": "image/jpeg, image/jpg, image/png, image/gif",
"receiver": "/api/upload/file",
"multiple": false,
"autoUpload": false,
"joinValues": false,
"onEvent": {
"success": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "info",
"msg": "「${event.data.path}」上传成功"
}
}
]
}
}
}
]
}
```
### 隐藏上传按钮
设置 `"hideUploadButton": true` 隐藏手动上传的按钮。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"data": {
"file": {
"id":"2ba48d02d348",
"value":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"url":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"filename":"file(single).md",
"name":"file(single).md",
"state":"uploaded"
},
"files": [
{
"id":"2ba48d02d349",
"value":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"url":"https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"preview": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"filename":"file1.md",
"name":"file1.md",
"state":"uploaded"
},
{
"id": "14723e0bc640",
"value": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"url": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"preview": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"filename":"file2.md",
"name":"file2.md",
"state":"uploaded"
}
]
},
"body": [
{
"type": "input-image",
"name": "files",
"label": "File(多选)",
"mode": "horizontal",
"labelAlign": "left",
"accept": "image/jpeg, image/jpg, image/png, image/gif",
"receiver": "/api/upload/file",
"multiple": true,
"autoUpload": false,
"joinValues": false,
"hideUploadButton": true,
"onEvent": {
"success": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "info",
"msg": "「${event.data.path}」上传成功"
}
}
]
}
}
},
{
"type": "input-image",
"name": "file",
"label": "File(单选)",
"mode": "horizontal",
"labelAlign": "left",
"accept": "image/jpeg, image/jpg, image/png, image/gif",
"receiver": "/api/upload/file",
"multiple": false,
"autoUpload": false,
"joinValues": false,
"hideUploadButton": true,
"onEvent": {
"success": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "info",
"msg": "「${event.data.path}」上传成功"
}
}
]
}
}
}
]
}
```
如果浏览器支持,还能设置为 `image/webp`
## 自动填充
上传成功后,可以通过配置 `autoFill` 将上传接口返回的值填充到某个表单项中:
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "image",
"receiver": "/api/upload/file",
"autoFill": {
"myUrl": "${url}"
}
},
{
"type": "text",
"name": "myUrl",
"label": "url"
}
]
}
```
上例中,image 组件上传后,接口返回格式例如如下:
```json
{
"status": 0,
"msg": "",
"data": {
"value": "xxxxxxx",
"filename": "xxxx.jpg",
"url": "http://xxxx.xxx.xxx"
}
}
```
然后 image 上配置:
```json
"autoFill": {
"myUrl": "${url}"
}
```
这样上传成功后,会把接口中的 `url` 变量,赋值给 `myUrl` 变量,这个里支持表达式,比如在前面加上域名
```json
"autoFill": {
"myUrl": "https://cdn.com/${filename}"
}
```
### 多选模式
当表单项为多选模式时,不能再直接取选项中的值了,而是通过 `items` 变量来取,通过它可以获取当前选中的选项集合。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "image",
"multiple": true,
"receiver": "/api/upload/file",
"autoFill": {
"myUrl": "${items|pick:url}",
"lastUrl": "${items|last|pick:url}"
}
},
{
"type": "tpl",
"label": false,
"inline": false,
"tpl": "<strong>myUrl集合</strong>"
},
{
"type": "each",
"name": "myUrl",
"className": "mb-1",
"items": {
"type": "tpl",
"tpl": "<span class='label label-info m-l-sm inline-block mb-1'>${item}</span>"
}
},
{
"type": "tpl",
"label": false,
"inline": false,
"tpl": "<strong>lastUrl</strong>"
},
{
"type": "text",
"name": "lastUrl",
"label": "lastUrl",
"inline": false
}
]
}
```
### 其他表单项填充
```schema: scope="body"
{
"type": "form",
"title": "表单",
"body": [
{
"type": "select",
"label": "选项",
"name": "imageUrl",
"delimiter": "|",
"autoFill": {
"inputImage": "${value}"
},
"options": [
{
"label": "imageURL",
"value": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80"
},
{
"label": "空链接",
"value": ""
}
]
},
{
"type": "input-image",
"label": "图片上传",
"name": "inputImage",
"imageClassName": "r w-full"
}
]
}
```
### initAutoFill 初始化时自动同步
当表单反显时,可通过`initAutoFill`控制`autoFill`在数据反显时是否执行。
```schema: scope="body"
{
type: 'crud',
api: '/api/mock2/crud/list',
perPage: 3,
columns: [
{
type: 'operation',
label: '操作',
buttons: [
{
type: 'button',
label: '修改',
level: 'link',
size: 'xs',
actionType: 'dialog',
dialog: {
title: '修改',
size: 'lg',
body: {
"type": "form",
"horizontal": {
"left": 3,
"right": 9
},
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/saveForm",
"body": [
{
"type": "input-image",
"name": "image",
"label": "image",
"receiver": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/upload/file",
"autoFill": {
"text": "${url}"
},
"initAutoFill": true
},
{
"type": "input-text",
"name": "text",
"label": "文本",
},
{
"type": "input-image",
"name": "carousel",
"label": "image",
"receiver": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/upload/file",
"autoFill": {
"id": "${url}"
},
"initAutoFill": false
},
{
"type": "input-text",
"name": "id",
"label": "ID",
},
]
}
},
},
]
},
{
name: 'id',
label: 'ID',
type: 'text'
},
{
name: 'text',
label: '文本',
type: 'text'
},
{
type: 'image',
label: '图片',
name: 'image',
enlargeAble: true,
title: '233',
thumbMode: 'cover'
},
{
name: 'carousel',
label: '轮播图',
type: 'carousel',
width: '300'
},
]
}
```
## 拖拽排序
可配置 `draggable` 为 `true` 启动拖拽排序。
```schema: scope="body"
{
"type": "form",
"title": "表单",
data: {
image: [
'http://www.sortablejs.com/assets/img/npm.png',
'http://www.sortablejs.com/assets/img/bower.png',
'http://www.sortablejs.com/assets/img/js.png'
]
},
"body": [
'Images: <br />${image|split|join:"<br />"}',
{
type: 'input-image',
name: 'image',
multiple: true,
draggable: true
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
|--------------------|-------------------------------------------------------|------------------------|-----------------------------------------------------------------------------------|
| receiver | [API](../../../docs/types/api) | | 上传文件接口 |
| accept | `string` | `.jpeg,.jpg,.png,.gif` | 支持的图片类型格式,请配置此属性为图片后缀,例如`.jpg,.png` |
| capture | `string` | `undefined` | 用于控制 input[type=file] 标签的 capture 属性,在移动端可控制输入来源 |
| maxSize | `number` | | 默认没有限制,当设置后,文件大小大于此值将不允许上传。单位为`B` |
| maxLength | `number` | | 默认没有限制,当设置后,一次只允许上传指定数量文件。 |
| multiple | `boolean` | `false` | 是否多选。 |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
| autoUpload | `boolean` | `true` | 否选择完就自动开始上传 |
| hideUploadButton | `boolean` | `false` | 隐藏上传按钮 |
| fileField | `string` | `file` | 如果你不想自己存储,则可以忽略此属性。 |
| crop | `boolean`或`{"aspectRatio":""}` | | 用来设置是否支持裁剪。 |
| crop.aspectRatio | `number` | | 裁剪比例。浮点型,默认 `1` 即 `1:1`,如果要设置 `16:9` 请设置 `1.7777777777777777` 即 `16 / 9`。。 |
| crop.rotatable | `boolean` | `false` | 裁剪时是否可旋转 |
| crop.scalable | `boolean` | `false` | 裁剪时是否可缩放 |
| crop.viewMode | `number` | `1` | 裁剪时的查看模式,0 是无限制 |
| cropFormat | `string` | `image/png` | 裁剪文件格式 |
| cropQuality | `number` | `1` | 裁剪文件格式的质量,用于 jpeg/webp,取值在 0 和 1 之间 |
| limit | Limit | | 限制图片大小,超出不让上传。 |
| frameImage | `string` | | 默认占位图地址 |
| fixedSize | `boolean` | | 是否开启固定尺寸,若开启,需同时设置 fixedSizeClassName |
| fixedSizeClassName | `string` | | 开启固定尺寸时,根据此值控制展示尺寸。例如`h-30`,即图片框高为 h-30,AMIS 将自动缩放比率设置默认图所占位置的宽度,最终上传图片根据此尺寸对应缩放。 |
| initAutoFill | `boolean` | `false` | 表单反显时是否执行 autoFill |
| uploadBtnText | `string` \| [SchemaNode](../../docs/types/schemanode) | | 上传按钮文案。支持 tpl、schema 形式配置。 |
| dropCrop | `boolean` | `true` | 图片上传后是否进入裁剪模式 |
| initCrop | `boolean` | `false` | 图片选择器初始化后是否立即进入裁剪模式 |
| draggable | `boolean` | false | 开启后支持拖拽排序改变图片值顺序 |
| draggableTip | `string` | '拖拽排序' | 拖拽提示文案 |
| showErrorModal | `boolean` | `true` | 校验失败后是否弹窗提醒 |
| invalidTypeMessage | `string` | '文件格式不正确' | 校验格式失败后的提示信息 | |
| invalidSizeMessage | `string` | '文件大小超出限制' | 校验文件大小失败时显示的文字信息 | |
### Limit 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| ----------- | -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| width | `number` | | 限制图片宽度。 |
| height | `number` | | 限制图片高度。 |
| minWidth | `number` | | 限制图片最小宽度。 |
| minHeight | `number` | | 限制图片最小高度。 |
| maxWidth | `number` | | 限制图片最大宽度。 |
| maxHeight | `number` | | 限制图片最大高度。 |
| aspectRatio | `number` | | 限制图片宽高比,格式为浮点型数字,默认 `1` 即 `1:1`,如果要设置 `16:9` 请设置 `1.7777777777777777` 即 `16 / 9`。 如果不想限制比率,请设置空字符串。 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`file`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| change | `[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传文件值变化时触发(上传失败同样会触发) |
| remove | `item: FileValue` 被移除的文件<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 移除文件时触发 |
| success | `item: FileValue` 上传的文件<br/>`result: any` 远程上传请求成功后接口返回的结果数据<br/>`id: string` id<br />`[name]: FileValue` 组件的值 | 上传成功时触发 |
| fail | `item: FileValue` 上传的文件 <br /> `error: object` 远程上传请求失败后返回的错误信息<br/>`[name]: FileValue` \| `Array<FileValue>` 组件的值 | 上传文件失败时触发 |
### FileValue 属性表
| 属性名 | 类型 | 说明 |
| ------ | -------- | -------------------------------------------------- |
| name | `string` | 图片名称 |
| value | `string` | 上传成功后返回的 url |
| state | `string` | 文件当前状态,值可为 `pending` `uploaded` `invalid` |
| error | `string` | 错误信息 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | -------- | ---- |
| clear | - | 清空 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-image",
"name": "image",
"label": "Image",
"receiver": "/api/upload/file",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,229 @@
---
title: InputKV 键值对
description:
type: 0
group: null
menuName: InputKV
icon:
order: 14
---
## 基本用法
`input-kv` 是用来支持对象形式的数据编辑,比如类似这样的数据:
```json
{
"css": {
"width": 1,
"height": 2
}
}
```
`css` 中的 key 是不确定的,没法用 combo 来实现,这时可以使用 `input-kv`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "kv"
}
]
}
```
最终发送的数据将会是
## 自定义 value 的格式
key 只能是字符串,因此输入格式是 `input-text`,但 value 格式可通过 `valueType` 自定义。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "kv",
"valueType": "input-number"
}
]
}
```
## 自定义 value 的默认值
通过 `defaultValue` 设置默认值
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "css",
"defaultValue": "1.0"
}
]
}
```
## 自定义 value 的 schema
> 3.1.0 及以上版本
默认创建的 value schema 是
```json
{
"placeholder": "Value",
"type": "input-text",
"name": "value"
}
```
前面的配置可以改其中的 type 或 placeholder,而这个新的 `valueSchema` 配置就能做到替换所有配置,比如
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "css",
"valueSchema": {
"type": "select",
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b"
},
{
"label": "C",
"value": "c"
}
]
}
}
]
}
```
## 自定义 key schema
> 3.1.0 及以上版本
和前面的 value schema 类似,还可以自定义 key 的 schema
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "css",
"keySchema": {
"type": "select",
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b"
},
{
"label": "C",
"value": "c"
}
]
}
}
]
}
```
## 关闭可拖拽排序
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "css",
"draggable": false
}
]
}
```
## 自定义提示信息
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kv",
"name": "css",
"keyPlaceholder": "属性",
"valuePlaceholder": "值"
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| ---------------- | --------- | -------------- | ---------------------------- |
| valueType | `type` | `"input-text"` | 值类型 |
| keyPlaceholder | `string` | | key 的提示信息的 |
| valuePlaceholder | `string` | | value 的提示信息的 |
| draggable | `boolean` | true | 是否可拖拽排序 |
| defaultValue | | `''` | 默认值 |
| autoParseJSON | `boolean` | `true` | 是否自动转换 json 对象字符串 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------------------------------------------------------------------ | ---------------- |
| add | `[name]: string \| string[]` 组件的值 | 添加组合项时触发 |
| delete | `key: number` 移除项的索引<br />`item: string` 移除项<br />`[name]: object` 组件的值 | 删除组合项时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: object` 更新的值 | 更新数据 |

View File

@@ -0,0 +1,320 @@
---
title: InputKVS 键值对象
description:
type: 0
group: null
menuName: InputKVS
icon:
order: 15
---
> 2.1.0 及以上版本
这个组件的功能和 `input-kv` 类似,`input-kv` 的 value 值只支持一个对象,`input-kvs` 的最大不同就是 value 支持对象和数组,可以用来支持深层结构编辑
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kvs",
"name": "field",
"addButtonText": "新增字段",
"keyItem": {
"label": "字段名"
},
"valueItems": [
{
"type": "switch",
"name": "primary",
"label": "是否是主键"
},
{
"type": "select",
"name": "type",
"label": "字段类型",
"options": [
"text",
"int",
"float"
]
}
]
}
]
}
```
其中 `keyItem` 可以用来修改 key 值控件,比如可以改成下拉框
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kvs",
"name": "field",
"addButtonText": "新增字段",
"keyItem": {
"label": "字段名",
"type": "select",
"options": [
"id",
"title",
"content"
]
},
"valueItems": [
{
"type": "switch",
"name": "primary",
"label": "是否是主键"
},
{
"type": "select",
"name": "type",
"label": "字段类型",
"options": [
"text",
"int",
"float"
]
}
]
}
]
}
```
而 `valueItems` 是用来控制值的控件,这里的配置和 combo 的 items 一样,唯一限制是不允许有 `"name": "_key"` 值的情况,因为这个值被当成对象 key 了。
## 水平模式
通过 `"mode": "horizontal"` 设置,需要分别在 `keyItem` 和 `valueItems` 里设置
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kvs",
"name": "field",
"addButtonText": "新增字段",
"keyItem": {
"label": "字段名",
"mode": "horizontal"
},
"valueItems": [
{
"type": "switch",
"name": "primary",
"mode": "horizontal",
"label": "是否是主键"
},
{
"type": "select",
"name": "type",
"label": "字段类型",
"mode": "horizontal",
"options": [
"text",
"int",
"float"
]
}
]
}
]
}
```
## 嵌套的场景
`valueItems` 可以进一步嵌套,比如里面又嵌一个 `input-kvs` 实现深层结构编辑
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kvs",
"name": "dataModel",
"addButtonText": "新增表",
"keyItem": {
"label": "表名",
"mode": "horizontal",
"type": "select",
"options": [
"table1",
"table2",
"table3"
]
},
"valueItems": [
{
"type": "input-kvs",
"addButtonText": "新增字段",
"name": "column",
"keyItem": {
"label": "字段名",
"mode": "horizontal",
"type": "select",
"options": [
"id",
"title",
"content"
]
},
"valueItems": [
{
"type": "switch",
"name": "primary",
"mode": "horizontal",
"label": "是否是主键"
},
{
"type": "select",
"name": "type",
"label": "字段类型",
"mode": "horizontal",
"options": [
"text",
"int",
"float"
]
}
]
}
]
}
]
}
```
前面的嵌套会多一个层级,如果想去掉这个层级 `column`,可以将 `"name": "column"` 改成 `"name": "_value"`,这时值就会直接放入
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kvs",
"name": "dataModel",
"addButtonText": "新增表",
"keyItem": {
"label": "表名",
"mode": "horizontal",
"type": "select",
"options": [
"table1",
"table2",
"table3"
]
},
"valueItems": [
{
"type": "input-kvs",
"addButtonText": "新增字段",
"name": "_value",
"keyItem": {
"label": "字段名",
"mode": "horizontal",
"type": "select",
"options": [
"id",
"title",
"content"
]
},
"valueItems": [
{
"type": "switch",
"name": "primary",
"mode": "horizontal",
"label": "是否是主键"
},
{
"type": "select",
"name": "type",
"label": "字段类型",
"mode": "horizontal",
"options": [
"text",
"int",
"float"
]
}
]
}
]
}
]
}
```
除了前面的对象,值也可以是数组,需要配置一下 `valueIsArray`
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-kvs",
"name": "dataModel",
"addButtonText": "新增表",
"valueIsArray": true,
"keyItem": {
"label": "表名",
"mode": "horizontal",
"type": "select",
"options": [
"table1",
"table2",
"table3"
]
},
"valueItems": [
{
type: 'checkboxes',
name: '_value',
joinValues: false,
extractValue: true,
options: [
{
label: '查询',
value: 'select'
},
{
label: '写入',
value: 'insert'
},
{
label: '更新',
value: 'update'
},
{
label: '删除',
value: 'delete'
}
]
}
]
}
]
}
```

View File

@@ -0,0 +1,106 @@
---
title: InputMonthRange 月份范围
description:
type: 0
group: null
menuName: InputMonthRange
icon:
order: 15
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-month-range",
"name": "a",
"label": "月份范围"
}
]
}
```
## 内嵌模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-month-range",
"name": "a",
"label": "月份范围",
"embed": true
}
]
}
```
## 存成两个字段
默认月份范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-month-range",
"name": "begin",
"extraName": "end",
"label": "月份范围"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | --------- | ------------------ | ---------------------------------------------------------------------------------- | ------- |
| format | `string` | `X` | [日期选择器值格式](./input-date#%E5%80%BC%E6%A0%BC%E5%BC%8F) |
| inputFormat | `string` | `YYYY-DD` | [日期选择器显示格式](./input-date#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) |
| placeholder | `string` | `"请选择月份范围"` | 占位文本 |
| minDate | `string` | | 限制最小日期,用法同 [限制范围](./input-date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| maxDate | `string` | | 限制最大日期,用法同 [限制范围](./input-date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| minDuration | `string` | | 限制最小跨度,如: 2days |
| maxDuration | `string` | | 限制最大跨度,如:1year |
| utc | `boolean` | `false` | [保存 UTC 值](./input-date#utc) |
| clearable | `boolean` | `true` | 是否可清除 |
| embed | `boolean` | `false` | 是否内联模式 |
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
| extraName | `string` | | 是否存成两个字段 | `3.3.0` |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------------- | -------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,依赖格式`format`,例如 '1646064000,1651334399' |

View File

@@ -0,0 +1,178 @@
---
title: InputMonth 月份
description:
type: 0
group: null
menuName: InputMonth 月份
icon:
order: 81
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-month",
"name": "month",
"label": "时间"
}
]
}
```
## 显示格式
选中月份,可以看到默认显示月份的格式是像`01`这样的格式,如果你想要自定义显示格式,那么可以配置`displayFormat`。
例如你想显示`01月`这样的格式,查找 moment 文档可知配置格式应为 `MM月`,即:
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-month",
"name": "month",
"label": "月份",
"displayFormat": "MM月"
}
]
}
```
调整月份,观察显示格式
## 值格式
选中任意月份,可以看到默认表单项的值格式是像`1582992000`这样的时间戳格式。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-month",
"name": "month",
"label": "月份"
}
]
}
```
如果你想要其他格式的月份值,那么可以配置`valueFormat`参数用于调整表单项的值格式。
例如你调整值为`01`这样的格式,查找 moment 文档可知配置格式应为 `MM`,即:
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-month",
"name": "month",
"label": "月份",
"valueFormat": "MM"
}
]
}
```
调整月份,观察数据域中表单项值的变化
## 默认值
可以设置`value`属性,设置月份选择器的默认值
### 基本配置
配置符合当前 [值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) 的默认值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-month",
"name": "month",
"label": "月份",
"value": "1582992000"
}
]
}
```
### 相对值
`value` 还支持类似像`"+1hours"`这样的相对值,更加便捷的配置默认值
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-month",
"name": "month",
"label": "月份",
"value": "+1month"
}
]
}
```
上例中配置了`"value": "+1month"`,默认就会选中一个月后。
支持的相对值关键字有:
- `now`: 当前时间
- `hour`或`hours`: 时
- `minute`或`minutes`: 分
- `second`或`seconds`: 秒
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | --------- | -------------- | ----------------------------------------------------------------------------------- | ------- |
| value | `string` | | [默认值](./date#%E9%BB%98%E8%AE%A4%E5%80%BC) |
| valueFormat | `string` | `X` | 月份选择器值格式,更多格式类型请参考 [moment](http://momentjs.com/) | `3.4.0` |
| displayFormat | `string` | `YYYY-MM` | 月份选择器显示格式,即时间戳格式,更多格式类型请参考 [moment](http://momentjs.com/) | `3.4.0` |
| placeholder | `string` | `"请选择月份"` | 占位文本 |
| clearable | `boolean` | `true` | 是否可清除 |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------- | --------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`valueFormat`,例如:'1646064000' |

View File

@@ -0,0 +1,417 @@
---
title: InputNumber 数字输入框
description:
type: 0
group: null
menuName: InputNumber
icon:
order: 32
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-number",
"name": "number",
"label": "数字"
}
]
}
```
## 设置精度
`precision` 设置数字的显示精度,一般需要配合 `step` 属性使用,以实现细粒度调整。注意带有单位的输入不支持配置精度属性。若设置了 `step` 值,则会基于 `step` 和 `precision` 的值,选择更高的精度。若输入的内容不满足精度要求,组件会按照精度自动处理,遵循四舍五入规则。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"data": {
"number2": 3.1234
},
"body": [
{
"type": "input-number",
"name": "number1",
"label": "数字",
"precision": 2,
"step": 0.01,
"value": 2.98786
},
{
"type": "input-number",
"name": "number2",
"label": "数字2",
"precision": 3,
"step": 0.001
},
{
"type": "input-number",
"name": "number3",
"label": "数字3",
"step": 0.001,
"description": "不设置precision,仅设置step, 实际精度为3"
}
]
}
```
## 重置值
清空/重置组件输入后,组件绑定的值将被设置为 `resetValue`,默认为 `""`。若 `resetValue` 为合法数字时,会根据 `min`、`max` 和 `precision` 属性,将组件值设置为满足条件的值。若 `resetValue` 为非数字,则组件清空/重置后设置为该值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-number",
"name": "number1",
"label": "数字resetValue为0",
"resetValue": 0,
"value": 1234
},
{
"type": "input-number",
"name": "number2",
"label": "数字带有min",
"min": 100,
"resetValue": 0,
"value": 1234,
"description": "清空输入后组件值变为100,因为设置了最小值min为100"
},
{
"type": "input-number",
"name": "number3",
"label": "数字带有max和precision",
"max": 100.5,
"precision": 2,
"resetValue": 1000,
"value": 1234,
"description": "清空输入后组件值变为100.5,因为设置了最大值max为100.5"
},
{
"type": "input-number",
"name": "number4",
"label": "数字未设置resetValue",
"resetValue": "string",
"value": 1234,
"description": "清空输入后组件值变为\"string\",因为resetValue不是一个合法的数字"
}
]
}
```
## 前后缀、千分分隔
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-number",
"name": "number",
"label": "数字",
"value": 111111,
"prefix": "$",
"suffix": "%",
"kilobitSeparator": true
}
]
}
```
## 带单位数字
> 1.4.0 及以上版本
可以通过 `unitOptions` 设置数字的单位选项,和前面的前后缀不同,它的输出结果也将会是字符串,包含单位,默认取选项的第一个。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-number",
"name": "number",
"label": "数字",
"unitOptions": ["px", "%", "em"]
}
]
}
```
## 加强版输入框
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-number",
"name": "number",
"label": "数字",
"displayMode": "enhance"
}
]
}
```
## 是否是大数
> 2.3.0 及以上版本
默认情况下使用 JavaScript 原生数字类型,但如果要支持输入超过 JavaScript 支持范围的整数或浮点数,可以通过 `"big": true` 开启大数支持,开启之后输入输出都将是字符串。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-number",
"name": "number",
"label": "数字",
"big": true
}
]
}
```
## 内容清空时删除字段
> 2.8.0 及以上版本
如果设置了 `"clearValueOnEmpty": true`,当输入框的值清空时,会从数据域中删除该表单项对应的值。比较常见的用法是在 `combo`、`input-array` 等组件中避免 `input-number` 清空后提交空字符串。
```schema: scope="body"
{
"type": "form",
"debug": true,
"debugConfig": {
"levelExpand": 2
},
"body": [
{
"type": "group",
"body": [
{
"name": "numberClear",
"type": "input-number",
"label": "清空",
"value": 123,
"clearValueOnEmpty": true
},
{
"name": "numberNotClear",
"type": "input-number",
"label": "不清空",
"value": 456
}
]
},
{
"type": "combo",
"name": "user",
"label": "用户",
"items": [
{
"name": "text",
"label": "名字",
"type": "input-text"
},
{
"name": "gender",
"label": "性别",
"type": "select",
"options": ["男", "女"]
},
{
"name": "age",
"label": "年龄",
"type": "input-number",
"clearValueOnEmpty": true
}
]
}
]
}
```
## 原生数字组件
原生数字组件将直接使用浏览器的实现,最终展现效果和浏览器有关,并且只支持 `min`、`max` 和 `step` 这几个属性设置,这个功能主要是给移动端浏览器使用的,PC 下不建议使用。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "native-number",
"name": "number",
"label": "数字"
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ----------------- | --------------------------------------- | -------- | ------------------------------------------- | ------- |
| min | [模板](../../../docs/concepts/template) | | 最小值 |
| max | [模板](../../../docs/concepts/template) | | 最大值 |
| step | `number` | | 步长 |
| precision | `number` | | 精度,即小数点后几位,支持 0 和正整数 |
| showSteps | `boolean` | `true` | 是否显示上下点击按钮 |
| readOnly | `boolean` | `false` | 只读 |
| prefix | `string` | | 前缀 |
| suffix | `string` | | 后缀 |
| unitOptions | `string[]` | | 单位选项 | `1.4.0` |
| kilobitSeparator | `boolean` | `false` | 千分分隔 |
| keyboard | `boolean` | `true` | 键盘事件(方向上下) |
| big | `boolean` | `false` | 是否使用大数 | `2.3.0` |
| displayMode | `"base" \| "enhance"` | `"base"` | 样式类型 |
| borderMode | `"full" \| "half" \| "none"` | `"full"` | 边框模式,全边框,还是半边框,或者没边框 |
| resetValue | `number \| string` | `""` | 清空输入内容时,组件值将设置为 `resetValue` |
| clearValueOnEmpty | `boolean` | `false` | 内容为空时从数据域中删除该表单项对应的值 | `2.8.0` |
## 事件表
当前组件会对外派发以下事件,可以通过 `onEvent` 来监听这些事件,并通过 `actions` 来配置执行的动作,在 `actions` 中可以通过 `${事件参数名}` 或 `${event.data.[事件参数名]}` 来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]` 表示当前组件绑定的名称,即 `name` 属性,如果没有配置 `name` 属性,则通过 `value` 取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | ---------------- |
| change | `[name]: number` 组件的值 | 输入值变化时触发 |
| blur | `[name]: number` 组件的值 | - |
| focus | `[name]: number` 组件的值 | - |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定 `actionType: 动作名称`、`componentId: 该组件id` 来触发这些动作,动作配置可以通过 `args: {动作配置项名称: xxx}` 来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | -------------------------- | -------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为 `resetValue`,若没有配置 `resetValue`,则清空 |
| setValue | `value: number` 更新的数值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-number",
"name": "number",
"label": "数字",
"id": "clear_text",
"value": 1
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-number",
"name": "number",
"label": "数字",
"id": "reset_text",
"value": 1
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-number",
"name": "number",
"label": "数字",
"id": "setvalue_text",
"value": 1
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": 2
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,60 @@
---
title: InputPassword 密码输入框
description:
type: 0
group: null
menuName: InputPassword
icon:
order: 35
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-password",
"name": "password",
"label": "密码"
}
]
}
```
## 配置密码显/隐藏
`revealPassword`属性可以设置是否展示密码显/隐按钮,默认为`true`。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-password",
"name": "password",
"label": "密码",
"revealPassword": false
}
]
}
```
## 属性表
请参考[输入框](./input-text)
| 属性名 | 类型 | 默认值 | 说明 |
| -------------- | --------- | ------ | --------------------- |
| revealPassword | `boolean` | `true` | 是否展示密码显/隐按钮 |
## 事件表
请参考[输入框](./input-text)
## 动作表
请参考[输入框](./input-text)

View File

@@ -0,0 +1,105 @@
---
title: InputQuarterRange 季度范围
description:
type: 0
group: null
menuName: InputQuarterRange
icon:
order: 15
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-quarter-range",
"name": "quarter-range",
"label": "季度范围"
}
]
}
```
## 内嵌模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-quarter-range",
"name": "quarter-range",
"label": "季度范围",
"embed": true
}
]
}
```
## 存成两个字段
默认季度范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-quarter-range",
"name": "begin",
"extraName": "end",
"label": "季度范围"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | --------- | ------------------ | ---------------------------------------------------------------------------------- | ------- |
| valueFormat | `string` | `X` | [日期选择器值格式](./input-date#%E5%80%BC%E6%A0%BC%E5%BC%8F) | `3.4.0` |
| displayFormat | `string` | `YYYY-DD` | [日期选择器显示格式](./input-date#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) | `3.4.0` |
| placeholder | `string` | `"请选择季度范围"` | 占位文本 |
| minDate | `string` | | 限制最小日期,用法同 [限制范围](./input-date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| maxDate | `string` | | 限制最大日期,用法同 [限制范围](./input-date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| minDuration | `string` | | 限制最小跨度,如: 2quarter |
| maxDuration | `string` | | 限制最大跨度,如:4quarter |
| utc | `boolean` | `false` | [保存 UTC 值](./input-date#utc) |
| clearable | `boolean` | `true` | 是否可清除 |
| embed | `boolean` | `false` | 是否内联模式 |
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
| extraName | `string` | | 是否存成两个字段 | `3.3.0` |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------------- | -------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,依赖格式`format`,例如 '1640966400,1664553600' |

View File

@@ -0,0 +1,49 @@
---
title: InputQuarter 季度
description:
type: 0
group: null
menuName: InputQuarter 季度
icon:
order: 62
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-quarter",
"name": "quarter",
"label": "季度"
}
]
}
```
更多用法和配置可以参考 [InputDate 日期](input-date),quarter 就是 date 的特定配置,所以 date 的所有配置都能使用。
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`format`,例如:'1640966400' |

View File

@@ -0,0 +1,541 @@
---
title: InputRange 滑块
description:
type: 0
group: null
menuName: InputRange 范围
icon:
order: 38
---
可以用于选择单个数值或数值范围。
## 基本用法
默认是单个数值,结果是个整数。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"label": '滑块',
"name": 'range',
"value": 20
}
]
}
```
## 选择范围
对于范围的渲染,结果将是个字符串,两个数值通过分隔符来隔开。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"name": "range",
"label": "range",
"multiple": true,
"joinValues": false,
"value": {
"min": 10,
"max": 50
}
}
]
}
```
## 控制调整的粒度
使用 `step` 可以控制调整粒度,默认是 1。`3.3.0`版本后支持使用变量。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"name": "range",
"min": 0,
"max": 1,
"step": 0.01,
"label": "range"
}
]
}
```
## 禁用
使用`disabled`禁用滑块。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"label": '滑块',
"name": 'range',
"value": 10,
"disabled": true,
"showInput": true,
"clearable": true
}
]
}
```
## 显示步长
开启`showSteps`可显示每个`step`长度
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"label": '滑块',
"name": 'range',
"max": 10,
"showSteps": true
}
]
}
```
## 分割块数
通过`parts`可对整个滑动条平均分为`parts`块。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"label": '滑块',
"name": 'range',
"showSteps": true,
"parts": 20
}
]
}
```
## 刻度标记
通过`marks`可对刻度进行自定义。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"label": '滑块',
"name": 'range',
"parts": 5,
"marks": {
'0': '0',
'20%': '20Mbps',
'40%': '40Mbps',
'60%': '60Mbps',
'80%': '80Mbps',
'100': '100'
}
}
]
}
```
## 输入框
通过开启`showInput`会展示输入框,输入框数据于滑块数据同步。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"name": "range",
"label": "range",
"value": 20,
"showInput": true
}
]
}
```
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"name": "range",
"label": "range",
"multiple": true,
"value": [10, 20],
"showInput": true
}
]
}
```
## 清除输入
在打开`showInput`输入框的前提下,开启`clearable`可对数据进行清除。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"name": "range",
"label": "range",
"value": 20,
"showInput": true,
"clearable": true
}
]
}
```
## 显示单位
在打开`showInput`输入框且设置了`unit`单位的前提下,开启`showInputUnit`可在 input 框中显示已配置的单位。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"name": "range",
"label": "range",
"value": 20,
"unit": "个",
"showInput": true,
"showInputUnit": true
}
]
}
```
## 显示标签
标签默认在 hover 和拖拽过程中展示,通过`tooltipVisible`或者`tipFormatter`可指定标签是否展示。标签默认展示在滑块上方,通过`tooltipPlacement`可指定标签展示的位置。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"name": "range",
"label": "range",
"value": 20,
"tooltipVisible": true,
"tooltipPlacement": "right"
}
]
}
```
## 存成两个字段
默认滑块多选存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-range",
"multiple": true,
"name": "begin",
"extraName": "end",
"label": "range"
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| className | `string` | | css 类名 |
| value | `number` or `string` or `{min: number, max: number}` or `[number, number]` | | |
| min | `number \| string` | `0` | 最小值,支持变量 | `3.3.0`后支持变量 |
| max | `number \| string` | `100` | 最大, 支持变量值 | `3.3.0`后支持变量 |
| disabled | `boolean` | `false` | 是否禁用 |
| step | `number \| string` | `1` | 步长,支持变量 | `3.3.0`后支持变量 |
| showSteps | `boolean` | `false` | 是否显示步长 |
| parts | `number` or `number[]` | `1` | 分割的块数<br/>主持数组传入分块的节点 |
| marks | <code>{ [number &#124; string]: string &#124; number &#124; SchemaObject }</code> or <code>{ [number &#124; string]: { style: CSSProperties, label: string } }</code> | | 刻度标记<br/>- 支持自定义样式<br/>- 设置百分比 |
| tooltipVisible | `boolean` | `false` | 是否显示滑块标签 |
| tooltipPlacement | `auto` or `bottom` or `left` or `right` | `top` | 滑块标签的位置,默认`auto`,方向自适应<br/>前置条件:tooltipVisible 不为 false 时有效 |
| tipFormatter | `function` | | 控制滑块标签显隐函数<br/>前置条件:tooltipVisible 不为 false 时有效 |
| multiple | `boolean` | `false` | 支持选择范围 |
| joinValues | `boolean` | `true` | 默认为 `true`,选择的 `value` 会通过 `delimiter` 连接起来,否则直接将以`{min: 1, max: 100}`的形式提交<br/>前置条件:开启`multiple`时有效 |
| delimiter | `string` | `,` | 分隔符 |
| unit | `string` | | 单位 |
| clearable | `boolean` | `false` | 是否可清除<br/>前置条件:开启`showInput`时有效 |
| showInput | `boolean` | `false` | 是否显示输入框 |
| showInputUnit | `boolean` | `false` | 是否显示输入框单位<br/>前置条件:开启`showInput`且配置了`unit`单位时有效 | `6.0.0`后支持变量 |
| onChange | `function` | | 当 组件 的值发生改变时,会触发 onChange 事件,并把改变后的值作为参数传入 |
| onAfterChange | `function` | | 与 `onmouseup` 触发时机一致,把当前值作为参数传入 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ---------------------------------------------------------------- | ------------------------------------------------- |
| change | `[name]: number \| string \|{min: number, max: number}` 组件的值 | 当值变化时触发的事件 |
| blur | `[name]: number \| string \|{min: number, max: number}` 组件的值 | 当设置 showInput 为 true 时,输入框失去焦点时触发 |
| focus | `[name]: number \| string \|{min: number, max: number}` 组件的值 | 当设置 showInput 为 true 时,输入框获取焦点时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-range",
"label": "滑块",
"name": "range",
"value": 20,
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
### blur
当设置 `showInput` 为 true 时,输入框失去焦点时触发。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-range",
"label": "滑块",
"name": "range",
"value": 20,
"showInput": true,
"onEvent": {
"blur": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
### focus
当设置 `showInput` 为 true 时,输入框获取焦点时触发。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-range",
"label": "滑块",
"name": "range",
"value": 20,
"showInput": true,
"onEvent": {
"focus": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------------------------------------------- | ------------------------------------------------ |
| clear | - | 清除输入框 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: number \| string \| {min: number, max: number}` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-range",
"label": "滑块",
"name": "range",
"value": 20,
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-range",
"label": "滑块",
"name": "range",
"value": 20,
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-range",
"label": "滑块",
"name": "range",
"value": 20,
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": 30
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,288 @@
---
title: InputRating 评分
description:
type: 0
group: null
menuName: InputRating 评分
icon:
order: 37
---
## 基本用法
默认颜色
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3
}
]
}
```
自定义颜色。支持各种颜色形式,如 CSS 预定义颜色,十六进制颜色,RGB 颜色,HSL 颜色。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3,
"colors": {
"1": "gray",
"2": "#678f8d",
"3": "rgb(119, 168, 141)",
"4": "hsl(147, 22%, 56%)",
"5": "#ff6670"
}
}
]
}
```
## 半星
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3.5,
"half": true
}
]
}
```
## 带有文字
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3,
"texts": {
"1": "很差",
"2": "较差",
"3": "一般",
"4": "较好",
"5": "很好"
},
"textClassName": "okde"
}
]
}
```
## 自定义字符
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3,
"char": "好"
}
]
}
```
## 只读
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3.6,
"half": true,
"readOnly": true,
"texts": {
"5": "3.6"
}
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------- | ------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| value | `number` | - | 当前值 |
| half | `boolean` | `false` | 是否使用半星选择 |
| count | `number` | `5` | 总星数 |
| readOnly | `boolean` | `false` | 只读 |
| allowClear | `boolean` | `true` | 是否允许再次点击后清除 |
| colors | `string` / `object` | `{'2': '#abadb1', '3': '#787b81', '5': '#ffa900' }` | 星星被选中的颜色。 若传入字符串,则只有一种颜色。若传入对象,可自定义分段,键名为分段的界限值,键值为对应的类名 |
| inactiveColor | `string` | `#e7e7e8` | 未被选中的星星的颜色 |
| texts | `object` | - | 星星被选中时的提示文字。可自定义分段,键名为分段的界限值,键值为对应的类名 |
| textPosition | `right` / `left` | `right` | 文字的位置 |
| char | `string` | `★` | 自定义字符 |
| className | `string` | - | 自定义样式类名 |
| charClassName | `string` | - | 自定义字符类名 |
| textClassName | `string` | - | 自定义文字类名 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------- |
| change | `[name]: number` 组件的值 | 分值变化时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: number` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3.5,
"half": true,
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3.5,
"half": true,
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-rating",
"name": "rating",
"label": "评分",
"count": 5,
"value": 3.5,
"half": true,
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": 4
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,34 @@
---
title: InputRepeat 重复频率选择器
description:
type: 0
group: null
menuName: InputRepeat 重复频率
icon:
order: 39
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-repeat",
"name": "repeat",
"label": "重复频率"
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ----------- | -------- | ----------------------------- | ------------------------------------------------------------------------ |
| options | `string` | `hourly,daily,weekly,monthly` | 可用配置 `secondly,minutely,hourly,daily,weekdays,weekly,monthly,yearly` |
| placeholder | `string` | `不重复` | 当不指定值时的说明。 |

View File

@@ -0,0 +1,260 @@
---
title: InputRichText 富文本编辑器
description:
type: 0
group: null
menuName: InputRichText
icon:
order: 47
---
目前富文本编辑器基于两个库:[froala](https://froala.com/) 和 [tinymce](https://github.com/tinymce/tinymce),默认使用 tinymce。
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rich-text",
"name": "rich",
"label": "Rich Text"
}
]
}
```
## 图片上传
通过设置 `receiver` 来支持文件上传,如果是 tinymce,它会将图片放在 `file` 字段中
> 1.6.1 及以上版本可以通过 fileField 字段修改
它的返回值类似如下:
```json
{
"link": "https://xxx.png"
}
```
也可以是
```json
{
"status": 0,
"data": {
"link": "https://xxx.png"
}
}
```
下面是个示例,但不会真正上传,每次都返回同一张图片
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-rich-text",
"receiver": "/api/mock2/sample/mirror?json={%22link%22:%22/amis/static/logo_c812f54.png%22}",
"name": "rich",
"label": "Rich Text"
}
]
}
```
## tinymce 自定义配置
可以设置 options 属性来自定义编辑器的展现,详细配置项请参考[官方文档](https://www.tiny.cloud/docs/tinymce/6/basic-setup/)。
> amis 2.1.0 版本升级到了 tinymce 6,导致 plugins 的写法有变化
注意在下面的编辑器里修改 JSON 配置后不会实时生效。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rich-text",
"name": "rich",
"options": {
"menubar": false,
"height": 200,
"plugins": [
"advlist", "autolink", "link", "image", "lists", "charmap", "preview", "anchor", "pagebreak", "searchreplace", "wordcount", "visualblocks", "visualchars", "code", "fullscreen", "insertdatetime", "media", "nonbreaking", "table", "emoticons", "template", "help"
],
"toolbar": "undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help"
}
}
]
}
```
## 关于 tinymce 粘贴 word 的问题
因为 amis 中使用的是开源版本 tinymce,没有商业版本功能,导致比如从 Word 中粘贴表格会看不到边框,解决方法是自己
```json
{
"type": "input-rich-text",
"name": "rich",
"options": {
"content_css": "/xxx.css"
}
}
```
比如下面的示例
```css
.mce-item-table th {
font-weight: bold;
}
.mce-item-table th,
.mce-item-table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
.mce-item-table tr {
border-top: 1px solid #ccc;
}
```
但最终页面渲染的时候,这个 class 没有了,得改成 table
```css
table th {
font-weight: bold;
}
table th,
table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table tr {
border-top: 1px solid #ccc;
}
```
## 图片保存为 base64
当使用 tinymce 编辑器的时候,如果配置文件接收器为空,当选择图片的时候,会自动转成 base64 格式存储
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rich-text",
"name": "rich",
"label": "Rich Text",
"receiver": ""
}
]
}
```
## 扩充 tinymce 插件
需要在调用 amis 的时候,通过 `env.loadTinymcePlugin` 来加载自定义插件,可以查考: [examples/components/SchemaRender.jsx](https://github.com/baidu/amis/blob/master/examples/components/SchemaRender.jsx) 文件中的示例。
```schema
{
"type": "page",
"body": {
"type": "form",
"debug": true,
"body": [
{
"type": "input-rich-text",
"name": "rich",
"label": "Rich Text",
"options": {
"menubar": false,
"height": 200,
"plugins": [
"example"
],
"toolbar": "undo redo | example"
}
}
]
}
}
```
## 使用 froala 编辑器
只需要加一行 `"vendor": "froala"` 配置就行,froala 是付费产品,需要设置 [richTextToken](../../start/getting-started#richtexttoken-string) 才能去掉水印。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-rich-text",
"vendor": "froala",
"name": "rich",
"label": "Rich Text"
}
]
}
```
### froala buttons 配置项
froala 可以通过设置 buttons 参数来控制显示哪些按钮,默认是这些:
```json
[
"undo",
"redo",
"paragraphFormat",
"textColor",
"backgroundColor",
"bold",
"underline",
"strikeThrough",
"formatOL",
"formatUL",
"align",
"quote",
"insertLink",
"insertImage",
"insertEmotion",
"insertTable",
"html"
]
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------- | ------------------------------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| saveAsUbb | `boolean` | | 是否保存为 ubb 格式 |
| receiver | [API](../../../docs/types/api) | | 默认的图片保存 API |
| videoReceiver | [API](../../../docs/types/api) | | 默认的视频保存 API `仅支持 froala 编辑器` |
| fileField | string | | 上传文件时的字段名 |
| size | `string` | | 框的大小,可设置为 `md` 或者 `lg` |
| options | `object` | | 需要参考 [tinymce](https://www.tiny.cloud/docs/configure/integration-and-setup/) 或 [froala](https://www.froala.com/wysiwyg-editor/docs/options) 的文档 |
| buttons | `Array<string>` | | froala 专用,配置显示的按钮,tinymce 可以通过前面的 options 设置 [toolbar](https://www.tiny.cloud/docs/demo/custom-toolbar-button/) 字符串 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
> | 事件名称 | 事件参数 | 说明 |
> | -------- | ------------------------------------- | ------------------------------------------- |
> | change | `[value]: object` 富文本组件的值<br/> | 富文本值改变时触发 |

View File

@@ -0,0 +1,122 @@
---
title: inputSignature 签名面板
description:
type: 0
group: null
menuName: inputSignature
icon:
order: 62
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "signature",
"type": "input-signature",
"label": "手写签名",
"height": 200
}
]
}
```
## 自定义按钮名称
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "signature",
"type": "input-signature",
"height": 160,
"confirmBtnLabel": "确定",
"undoBtnLabel": "上一步",
"clearBtnLabel": "重置"
}
]
}
```
## 自定义颜色
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "signature",
"type": "input-signature",
"label": "手写签名",
"height": 200,
"color": "#ff0000",
"bgColor": "#fff"
}
]
}
```
## 配合图片组件实现实时预览
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "signature",
"type": "input-signature",
"label": "手写签名",
"height": 200
},
{
"type": "image",
"name": "signature"
}
]
}
```
## 内嵌模式
在内嵌模式下,组件会以按钮的形式展示,点击按钮后弹出一个容器,用户可以在容器中完成签名。更适合在移动端使用。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "signature",
"type": "input-signature",
"label": "手写签名",
"embed": true
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
| ----------------- | ------------------------------ | ---------- | ------------------------------------ |
| width | `number` | | 组件宽度,最小 300 |
| height | `number` | | 组件高度,最小 160 |
| color | `string` | `#000` | 手写字体颜色 |
| bgColor | `string` | `#EFEFEF` | 面板背景颜色 |
| clearBtnLabel | `string` | `清空` | 清空按钮名称 |
| undoBtnLabel | `string` | `撤销` | 撤销按钮名称 |
| confirmBtnLabel | `string` | `确认` | 确认按钮名称 |
| embed | `boolean` | | 是否内嵌 |
| embedConfirmLabel | `string` | `确认` | 内嵌容器确认按钮名称 |
| ebmedCancelLabel | `string` | `取消` | 内嵌容器取消按钮名称 |
| embedBtnIcon | `string` | | 内嵌按钮图标 |
| embedBtnLabel | `string` | `点击签名` | 内嵌按钮文案 |
| uploadApi | [API](../../../docs/types/api) | | 上传签名图片接口,仅在内嵌模式下生效 |

View File

@@ -0,0 +1,183 @@
---
title: InputSubForm 子表单
description:
type: 0
group: null
menuName: InputSubForm 子表单
icon:
order: 50
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-sub-form",
"name": "form",
"label": "子Form",
"btnLabel": "设置子表单",
"form": {
"title": "配置子表单",
"body": [
{
"name": "a",
"label": "A",
"type": "input-text"
},
{
"name": "b",
"label": "B",
"type": "input-text"
}
]
}
}
]
}
```
## 多选模式
可以配置`"multiple": true`,实现多选模式
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-sub-form",
"name": "form2",
"label": "多选",
"multiple": true,
"maxLength": 3,
"form": {
"title": "配置子表单",
"body": [
{
"name": "a",
"label": "A",
"type": "input-text"
},
{
"name": "b",
"label": "B",
"type": "input-text"
}
]
}
}
]
}
```
## 设置按钮名称
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-sub-form",
"name": "form2",
"label": "多选",
"multiple": true,
"btnLabel": "设置${title}",
"form": {
"title": "配置子表单",
"body": [
{
"name": "title",
"label": "标题",
"required": true,
"type": "input-text"
},
{
"name": "b",
"label": "其他",
"type": "input-text"
}
]
}
}
]
}
```
## 支持拖拽
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-sub-form",
"name": "form2",
"label": "多选",
"multiple": true,
"btnLabel": "设置${title}",
"draggable": true,
"addable": false,
"removable": false,
"value": [
{
"title": "a"
},
{
"title": "b"
},
{
"title": "c"
},
{
"title": "d"
}
],
"form": {
"title": "配置子表单",
"body": [
{
"name": "title",
"label": "标题",
"required": true,
"type": "input-text"
},
{
"name": "b",
"label": "其他",
"type": "input-text"
}
]
}
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------------ | --------------- | -------- | ------------------------------------------------------ |
| multiple | `boolean` | `false` | 是否为多选模式 |
| labelField | `string` | | 当值中存在这个字段,则按钮名称将使用此字段的值来展示。 |
| btnLabel | `string` | `"设置"` | 按钮默认名称 |
| minLength | `number` | `0` | 限制最小个数。 |
| maxLength | `number` | `0` | 限制最大个数。 |
| draggable | `boolean` | | 是否可拖拽排序 |
| addable | `boolean` | | 是否可新增 |
| removable | `boolean` | | 是否可删除 |
| addButtonClassName | `string` | `` | 新增按钮 CSS 类名 |
| itemClassName | `string` | `` | 值元素 CSS 类名 |
| itemsClassName | `string` | `` | 值包裹元素 CSS 类名 |
| form | [Form](./index) | | 子表单配置,同 [Form](./index) |
| addButtonText | `string` | `` | 自定义新增一项的文本 |
| showErrorMsg | `boolean` | `true` | 是否在左下角显示报错信息 |

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,441 @@
---
title: InputTag 标签选择器
description:
type: 0
group: null
menuName: InputTag 标签选择器
icon:
order: 55
---
## 基本使用
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"placeholder": "请选择标签",
"options": [
"Aaron Rodgers",
"Tom Brady",
"Charlse Woodson",
"Aaron Jones"
]
}
]
}
```
## 限制标签最大展示数量
> 1.10.0 及以上版本
`maxTagCount`可以限制标签的最大展示数量,超出数量的部分会收纳到 Popover 中,可以通过`overflowTagPopover`配置 Popover 相关的[属性](../tooltip#属性表),注意该属性仅在多选模式开启后生效。
> 6.13.0 版本开始,可摆放个数会根据所剩空间尽可能多的摆放,但是摆放个数不会超出设定的值,所以可以将这个值稍微设置大点。
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"maxTagCount": 100,
"overflowTagPopover": {
"title": "水果"
},
"value": "Pineapple,Kiwifruit,Banana,Blueberry,Carambola,Coconut,Lemon,Grape,Pomegranate,Mango,Papaya,Mangosteen,Durian,Longan,Litchi,Loquat,Persimmon,Pomelo,Orange,Tangerine,Kumquat,Plum,Apricot,Peach,Pear,Apple,Strawberry",
"options": [
{"label": "苹果", "value": "Apple"},
{"label": "香蕉", "value": "Banana"},
{"label": "黑莓", "value": "Blackberry"},
{"label": "蓝莓", "value": "Blueberry"},
{"label": "樱桃", "value": "Cherry"},
{"label": "杨桃", "value": "Carambola"},
{"label": "椰子", "value": "Coconut"},
{"label": "猕猴桃", "value": "Kiwifruit"},
{"label": "柠檬", "value": "Lemon"},
{"label": "菠萝", "value": "Pineapple"},
{"label": "葡萄", "value": "Grape"},
{"label": "石榴", "value": "Pomegranate"},
{"label": "芒果", "value": "Mango"},
{"label": "木瓜", "value": "Papaya"},
{"label": "山竹", "value": "Mangosteen"},
{"label": "榴莲", "value": "Durian"},
{"label": "龙眼", "value": "Longan"},
{"label": "荔枝", "value": "Litchi"},
{"label": "枇杷", "value": "Loquat"},
{"label": "柿子", "value": "Persimmon"},
{"label": "柚子", "value": "Pomelo"},
{"label": "橙子", "value": "Orange"},
{"label": "橘子", "value": "Tangerine"},
{"label": "金桔", "value": "Kumquat"},
{"label": "李子", "value": "Plum"},
{"label": "杏子", "value": "Apricot"},
{"label": "桃子", "value": "Peach"},
{"label": "梨子", "value": "Pear"},
{"label": "草莓", "value": "Strawberry"}
]
}
]
}
```
## 批量输入
> 2.0.0 及以上版本
可以设置`"enableBatchAdd": true`开启批量输入模式,默认的分隔符为`"-"`,可以使用`"separator"`属性自定义分隔符,注意避免和`"delimiter"`属性冲突。
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"enableBatchAdd": true
}
]
}
```
## 数量&文本长度限制
> 2.0.0 及以上版本
可以设置`max`限制输入的标签数量,设置`maxTagLength`限制单个标签的最大文本长度。
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"options": ["abc", "def", "xyz"],
"enableBatchAdd": true,
"max": 5,
"maxTagLength": 3
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------------ | ----------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
| optionsTip | `Array<object>`或`Array<string>` | `"最近您使用的标签"` | 选项提示 |
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
| delimiter | `string` | `false` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
| labelField | `string` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
| valueField | `string` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
| clearable | `boolean` | `false` | 在有值的时候是否显示一个删除图标在右侧。 |
| resetValue | `string` | `""` | 删除后设置此配置项给定的值。 |
| max | `number` | | 允许添加的标签的最大数量 |
| maxTagLength | `number` | | 单个标签的最大文本长度 |
| maxTagCount | `number` | | 标签的最大展示数量,超出数量后以收纳浮层的方式展示,仅在多选模式开启后生效 |
| overflowTagPopover | `TooltipObject` | `{"placement": "top", "trigger": "hover", "showArrow": false, "offset": [0, -10]}` | 收纳浮层的配置属性,详细配置参考[Tooltip](../tooltip#属性表) |
| enableBatchAdd | `boolean` | `false` | 是否开启批量添加模式 |
| separator | `string` | `"-"` | 开启批量添加后,输入多个标签的分隔符,支持传入多个符号,默认为"-" |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ----------------------------------------------------------------------------------------------------------------- | -------------------- |
| change | `[name]: string` 组件的值(多个以逗号分割)<br/>`selectedItems: Option[]` 选中的项<br/>`items: Option[]` 所有选项 | 选中值变化时触发 |
| blur | `[name]: string` 组件的值<br/>`selectedItems: Option[]` 选中的项<br/>`items: Option[]` 所有选项 | 输入框失去焦点时触发 |
| focus | `[name]: string` 组件的值<br/>`selectedItems: Option[]` 选中的项<br/>`items: Option[]` 所有选项 | 输入框获取焦点时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"placeholder": "请选择标签",
"options": [
"Aaron Rodgers",
"Tom Brady",
"Charlse Woodson",
"Aaron Jones"
],
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
### blur
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"placeholder": "请选择标签",
"options": [
"Aaron Rodgers",
"Tom Brady",
"Charlse Woodson",
"Aaron Jones"
],
"onEvent": {
"blur": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
### focus
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"placeholder": "请选择标签",
"options": [
"Aaron Rodgers",
"Tom Brady",
"Charlse Woodson",
"Aaron Jones"
],
"onEvent": {
"focus": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
| setValue | `value: string` 更新的值 | 更新数据,多个值用`,`分隔 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"placeholder": "请选择标签",
"options": [
"Aaron Rodgers",
"Tom Brady",
"Charlse Woodson",
"Aaron Jones"
],
"value": "Charlse Woodson",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"placeholder": "请选择标签",
"options": [
"Aaron Rodgers",
"Tom Brady",
"Charlse Woodson",
"Aaron Jones"
],
"value": "Charlse Woodson",
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### reload
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"placeholder": "请选择标签",
"id": "reload_type",
"source": "/api/mock2/form/getOptions?waitSeconds=1",
"value": "a"
},
{
"type": "button",
"label": "重新加载",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reload",
"componentId": "reload_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "input-tag",
"name": "tag",
"label": "标签",
"placeholder": "请选择标签",
"options": [
"Aaron Rodgers",
"Tom Brady",
"Charlse Woodson",
"Aaron Jones"
],
"value": "Charlse Woodson",
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "Tom Brady"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,798 @@
---
title: InputText 输入框
description:
type: 0
group: null
menuName: InputText 输入框
icon:
order: 56
---
## 基本使用
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "text",
"type": "input-text",
"label": "text"
}
]
}
```
## 不同边框风格
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "text-half-border",
"type": "input-text",
"label": "半边框",
"borderMode": "half",
"inputControlClassName": "bg-gray-100"
},
{
"name": "text-no-border",
"type": "input-text",
"label": "无边框",
"borderMode": "none",
"nativeInputClassName": "focus:text-indigo-700"
}
]
}
```
## 不同类型
配置`type`可以支持不同格式的文本输入框
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "text",
"type": "input-text",
"label": "text"
},
{
"type": "divider"
},
{
"type": "input-url",
"name": "url",
"label": "链接"
},
{
"type": "divider"
},
{
"type": "input-email",
"name": "email",
"label": "邮箱"
},
{
"type": "divider"
},
{
"type": "input-password",
"name": "password",
"label": "密码"
}
]
}
```
## 附加组件
可以配置`addOn`,附带附加组件,比如 button,还能设置 icon。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"addOn": {
"type": "button",
"icon": "https://suda.cdn.bcebos.com/images%2F2021-01%2Fsearch.svg",
"label": "搜索"
}
}
]
}
```
## 可清除
通过 `"clearable": true` 可以设置文本可清除
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"clearable": true
}
]
}
```
## 选择器模式
配置`options`即可支持选择器模式。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"options": [
{
"label": "aa",
"value": "aa"
},
{
"label": "bb",
"value": "bb"
},
{
"label": "cc",
"value": "cc"
},
{
"label": "dd",
"value": "dd"
}
]
}
]
}
```
选择器模式下,支持部分选择器组件支持的配置项,具体请查看下面的属性表。如:source 和 autoComplete 都支持
## 限制只能选择预设
配置 options 并且配置 creatable: false
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"creatable": false,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 多选模式
配置 multiple: true
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"multiple": true,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB (with long suffix for testing ellipsis)",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 前缀和后缀
`prefix` 和 `suffix` 属性支持数据映射。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"data": {
"unit": "MB"
},
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"prefix": "¥",
"suffix": "RMB"
},
{
"name": "prefix",
"type": "input-text",
"label": "text",
"prefix": "¥"
},
{
"name": "suffix",
"type": "input-text",
"label": "text",
"suffix": "${unit}"
}
]
}
```
## 显示计数器
配置`"showCounter": true`后输入框将显示计数器,一般会配合`maxLength`属性以限制输入长度,如果不设置`maxLength`,则仅展示计数器,并不会限制用户的输入长度。
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "a",
"type": "input-text",
"label": "A",
"showCounter": true,
"placeholder": "请输入",
"showCounter": true,
"options": [
{
"label": "aa",
"value": "aa"
},
{
"label": "bb",
"value": "bb"
},
{
"label": "cc",
"value": "cc"
},
{
"label": "dd",
"value": "dd"
}
]
},
{
"name": "b",
"type": "input-text",
"label": "B",
"showCounter": true,
"maxLength": 20,
"placeholder": "请输入"
}
]
}
```
## 自动转换值
可以配置 transform,来自动转换值,支持转小写或大写。
> 注意下面第一个示例,只有输入的内容才会触发 transform,下拉框选中的值是不会处理的。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "lower",
"type": "input-text",
"label": "转换小写",
"placeholder": "输入的英文自动转为小写",
"transform": {
"lowerCase": true
},
"multiple": true,
"options": ["APPLE", "ORANGE", "WATERMELON"],
},
{
"name": "upper",
"type": "input-text",
"label": "转换大写",
"placeholder": "输入的英文自动转为大写",
"transform": {
"upperCase": true
}
}
]
}
```
## 文本内容为空时去掉这个值
> 2.4.0 及以上版本
如果设置了 `"clearValueOnEmpty": true`,当输入框的值清空时,提交的表单项里就不会有这个值
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"type": "input-text",
"label": "内容为空时清理这个表单项",
"value": "v",
"clearValueOnEmpty": true
}
]
}
```
## 自动补全
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "name",
"type": "input-text",
"label": "自动补全",
"autoComplete": "/api/mock2/options/autoComplete?term=$term",
"placeholder": "请输入",
"multiple": true
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| --------------------- | ----------------------------------------- | --------- | ------------------------------------------------------------------------------------------- |
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
| autoComplete | `string`或 [API](../../../docs/types/api) | | [自动补全](./options#%E8%87%AA%E5%8A%A8%E8%A1%A5%E5%85%A8-autocomplete) |
| multiple | `boolean` | | [是否多选](./options#%E5%A4%9A%E9%80%89-multiple) |
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
| labelField | `string` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
| valueField | `string` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
| addOn | `addOn` | | 输入框附加组件,比如附带一个提示文字,或者附带一个提交按钮。 |
| addOn.type | `string` | | 请选择 `text` 、`button` 或者 `submit`。 |
| addOn.label | `string` | | 文字说明 |
| addOn.position | `'left' \| 'right'` | `'right'` | addOn 位置 |
| addOn.xxx | `string` | | 其他参数请参考按钮文档 |
| trimContents | `boolean` | | 是否去除首尾空白文本。 |
| clearValueOnEmpty | `boolean` | | 文本内容为空时去掉这个值 |
| creatable | `boolean` | | 是否可以创建,默认为可以,除非设置为 false 即只能选择选项中的值 |
| clearable | `boolean` | | 是否可清除 |
| resetValue | `string` | `""` | 清除后设置此配置项给定的值。 |
| prefix | `string` | `""` | 前缀 |
| suffix | `string` | `""` | 后缀 |
| showCounter | `boolean` | | 是否显示计数器 |
| minLength | `number` | | 限制最小字数 |
| maxLength | `number` | | 限制最大字数 |
| transform | `object` | | 自动转换值,可选 `transform: { lowerCase: true, upperCase: true }` |
| borderMode | `"full"\| "half" \| "none"` | `"full"` | 输入框边框模式,全边框,还是半边框,或者没边框。 |
| inputControlClassName | `string` | | control 节点的 CSS 类名 |
| nativeInputClassName | `string` | | 原生 input 标签的 CSS 类名 |
| nativeAutoComplete | `string` | `off` | 原生 input 标签的 `autoComplete` 属性,比如配置集成 `new-password` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | ---------------------------------------------- |
| click | `[name]: string` 组件的值 | 点击输入框时触发,只针对选择器模式的输入框有效 |
| enter | `[name]: string` 组件的值 | 回车时触发,只针对选择器模式的输入框有效 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点时触发 |
| change | `[name]: string` 组件的值 | 值变化时触发 |
| clear | `[name]: string` 组件的值 | 点击清除按钮时触发 |
### enter
选择器模式下,回车时触发。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"options": [
{
"label": "aa",
"value": "aa"
},
{
"label": "bb",
"value": "bb"
}
],
"onEvent": {
"enter": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
### focus
当设置 `showInput` 为 true 时,输入框获取焦点时触发。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"onEvent": {
"focus": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
### blur
当设置 `showInput` 为 true 时,输入框失去焦点时触发。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"onEvent": {
"blur": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
### clear
配置`clearable`为 true,点击清除按钮时触发。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"type": "input-text",
"label": "text",
"clearable": true,
"onEvent": {
"clear": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | -------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 重置 |
| focus | - | 获取焦点 |
| reload | - | 刷新(重新加载),只针对配置了`source`的输入框有效 |
| setValue | `value: string` 更新的值 | 更新数据,开启`multiple`多选时用`,`分隔 |
### clear
如果配置了`clearValueOnEmpty: true`,则清空时将置为`undefined`,否则置为空字符串。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "clear_text",
"type": "input-text",
"label": "text",
"value": "清空我"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "reset_text",
"type": "input-text",
"label": "text",
"value": "重置我"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### focus
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "focus_text",
"type": "input-text",
"label": "text",
"value": "聚焦我"
},
{
"type": "button",
"label": "聚焦",
"onEvent": {
"click": {
"actions": [
{
"actionType": "focus",
"componentId": "focus_text"
}
]
}
}
}
]
}
```
### reload
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "reload_text",
"type": "input-text",
"label": "text",
"value": "a",
"source": "/api/mock2/form/getOptions?waitSeconds=1"
},
{
"type": "button",
"label": "重新加载",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reload",
"componentId": "reload_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "setvalue_text",
"type": "input-text",
"label": "text",
"value": "amis"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "amis go go go!"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,122 @@
---
title: InputTimeRange 时间范围
description:
type: 0
group: null
menuName: InputTimeRange
icon:
order: 15
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time-range",
"name": "times",
"label": "时间范围"
}
]
}
```
## 内嵌模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-time-range",
"name": "times",
"label": "时间范围",
"embed": true
}
]
}
```
## 显示秒
默认显示的是时和分,请参考以下配置,其中若`valueFormat`非时间戳格式时需与`displayFormat`精确度相同
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-time-range",
"name": "times",
"label": "时间范围",
"valueFormat": "HH:mm:ss",
"displayFormat": "HH:mm:ss"
}
]
}
```
## 存成两个字段
默认季度范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time-range",
"name": "begin",
"extraName": "end",
"label": "时间范围"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | --------- | ------------------ | --------------------------------------------------------------------- | ------- |
| valueFormat | `string` | `HH:mm` | [时间范围选择器值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) | `3.4.0` |
| displayFormat | `string` | `HH:mm` | [时间范围选择器显示格式](./date#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) | `3.4.0` |
| placeholder | `string` | `"请选择时间范围"` | 占位文本 |
| clearable | `boolean` | `true` | 是否可清除 |
| embed | `boolean` | `false` | 是否内联模式 |
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
| extraName | `string` | | 是否存成两个字段 | `3.3.0` |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------------- | -------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,依赖格式`format`,例如 '1617206400,1743436800' |

View File

@@ -0,0 +1,283 @@
---
title: InputTime 时间
description:
type: 0
group: null
menuName: InputTime 时间
icon:
order: 58
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time",
"name": "time",
"label": "时间"
}
]
}
```
## 显示格式
选中任意时间,可以看到默认显示时间的格式是像`01:01`这样的格式,如果你想要自定义显示格式,那么可以配置`displayFormat`。
例如你想显示`01时01分`这样的格式,查找 moment 文档可知配置格式应为 `HH时mm分`,即:
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time",
"name": "time",
"label": "时间",
"displayFormat": "HH时mm分"
}
]
}
```
调整时间,观察显示格式
## 值格式
选中任意时间,可以看到默认表单项的值格式是像`1591862818`这样的时间戳格式。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time",
"name": "time",
"label": "时间"
}
]
}
```
如果你想要其他格式的日期值,那么可以配置`valueFormat`参数用于调整表单项的值格式。
例如你调整值为`01:11`这样的格式,查找 moment 文档可知配置格式应为 `HH:mm`,即:
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time",
"name": "time",
"label": "时间",
"valueFormat": "HH:mm"
}
]
}
```
调整时间,观察数据域中表单项值的变化
## 显示秒
默认显示的是时和分,要显示秒可通过配置`displayFormat`实现,请参考以下配置,若配置`valueFormat`需与`displayFormat`精确度相同
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time",
"name": "time",
"label": "时间",
"valueFormat": "HH:mm:ss",
"displayFormat": "HH:mm:ss"
},
{
"type": "input-time",
"name": "time2",
"label": "时间2",
"displayFormat": "HH:mm:ss"
}
]
}
```
## 默认值
可以设置`value`属性,设置日期选择器的默认值
### 基本配置
配置符合当前 [值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) 的默认值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time",
"name": "time",
"label": "时间",
"value": "1591862818"
}
]
}
```
### 相对值
`value` 还支持类似像`"+1hours"`这样的相对值,更加便捷的配置默认值
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time",
"name": "time",
"label": "时间",
"value": "+1hours"
}
]
}
```
上例中配置了`"value": "+1hours"`,默认就会选中一小时后。
支持的相对值关键字有:
- `now`: 当前时间
- `hour`或`hours`: 时
- `minute`或`minutes`: 分
- `second`或`seconds`: 秒
## 控制输入范围
通过 `timeConstraints` 属性可以控制输入范围
默认值是
```json
{
"hours": {
"min": 0,
"max": 23,
"step": 1
},
"minutes": {
"min": 0,
"max": 59,
"step": 1
},
"seconds": {
"min": 0,
"max": 59,
"step": 1
},
"milliseconds": {
"min": 0,
"max": 999,
"step": 1
}
}
```
可以只修改其中的部分值,比如下面的示例将分钟每次加减改成了 15,小时的范围限制在 9 到 17
> 设置了`timeConstraints`后,点击「此刻」会选择最接近当前时间的有效值
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-time",
"name": "time",
"label": "时间",
"timeConstraints": {
"hours": {
"min": 9,
"max": 17
},
"minutes": {
"step": 15
}
}
}
]
}
```
## 原生时间组件
原生时间组件将直接使用浏览器的实现,最终展现效果和浏览器有关,而且只支持 `min`、`max`、`step` 这几个属性设置。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "native-time",
"name": "time",
"label": "时间"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | --------- | -------------- | ----------------------------------------------------------------------------------- | ---------------- |
| value | `string` | | [默认值](./date#%E9%BB%98%E8%AE%A4%E5%80%BC) |
| valueFormat | `string` | `X` | 时间选择器值格式,更多格式类型请参考 [moment](http://momentjs.com/) | 3.4.0 版本后支持 |
| displayFormat | `string` | `HH:mm` | 时间选择器显示格式,即时间戳格式,更多格式类型请参考 [moment](http://momentjs.com/) | 3.4.0 版本后支持 |
| placeholder | `string` | `"请选择时间"` | 占位文本 |
| clearable | `boolean` | `true` | 是否可清除 |
| timeConstraints | `object` | `true` | |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`format`,例如:'1648746120' |

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,160 @@
---
title: 验证码输入 InputVerificationCode
description:
type: 0
group: null
menuName: InputVerificationCode 验证码
icon:
order: 63
---
注意 InputVerificationCode, 可通过<b>粘贴</b>完成填充数据。
## 基本用法
基本用法。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-verification-code",
"name": "verificationCode"
},
]
}
```
## 密码模式
指定 masked = true,可开启密码模式。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-verification-code",
"name": "verificationCode",
"masked": true,
}
]
}
```
## 自定义分隔符
指定 separator 可以自定义渲染分隔符。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-verification-code",
"name": "verificationCode",
"length": 9,
"separator": "${((index + 1) % 3 || index > 7 ) ? null : '-'}",
}
]
}
```
## 状态
<p>指定 disabled = true,可开启禁用模式。</p>
指定 readOnly = true,可开启只读模式。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-verification-code",
"name": "verificationCodeDisabled",
"value": "123456",
"disabled": true,
},
{
"type": "input-verification-code",
"name": "verificationCodeReadOnly",
"value": "987654",
"readOnly": true,
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| --------- | --------- | ------ | ------------------------------------------------------------------------------ |
| length | `number` | 6 | 验证码的长度,根据长度渲染对应个数的输入框 |
| masked | `boolean` | false | 是否是密码模式 |
| separator | `string` | | 分隔符,支持表达式, 表达式`只`可以访问 index、character 变量, 参考自定义分隔符 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件。
| 事件名称 | 事件参数 | 说明 |
| -------- | -------- | -------------------------- |
| finish | - | 输入框都被填充后触发的回调 |
| change | - | 输入值改变时触发的回调 |
### 事件
finish 输入框都被填充。可以尝试通过`${event.data.value}`获取填写的数据。
```schema: scope="body"
{
"type": "input-verification-code",
"onEvent": {
"finish": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "info",
"msg": "${event.data.value}"
}
}
]
}
}
}
```
change 输入值改变。可以尝试通过`${event.data.value}`获取填写的数据。
```schema: scope="body"
{
"type": "input-verification-code",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "info",
"msg": "${event.data.value}"
}
}
]
}
}
}
```

View File

@@ -0,0 +1,105 @@
---
title: InputYearRange 年份范围
description:
type: 0
group: null
menuName: InputYearRange
icon:
order: 15
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-year-range",
"name": "year-range",
"label": "年份范围"
}
]
}
```
## 内嵌模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "input-year-range",
"name": "year-range",
"label": "年份范围",
"embed": true
}
]
}
```
## 存成两个字段
默认年份范围存储一个字段,用 `delimiter` 分割,如果配置 `extraName` 则会存两个字段。
```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-year-range",
"name": "begin",
"extraName": "end",
"label": "年份范围"
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ------------------------ | --------- | ------------------ | ---------------------------------------------------------------------------------- | ------- |
| valueFormat | `string` | `X` | [年份选择器值格式](./input-date#%E5%80%BC%E6%A0%BC%E5%BC%8F) | `3.4.0` |
| displayFormat | `string` | `YYYY` | [年份选择器显示格式](./input-date#%E6%98%BE%E7%A4%BA%E6%A0%BC%E5%BC%8F) | `3.4.0` |
| placeholder | `string` | `"请选择年份范围"` | 占位文本 |
| minDate | `string` | | 限制最小日期,用法同 [限制范围](./input-date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| maxDate | `string` | | 限制最大日期,用法同 [限制范围](./input-date#%E9%99%90%E5%88%B6%E8%8C%83%E5%9B%B4) |
| minDuration | `string` | | 限制最小跨度,如: 2year |
| maxDuration | `string` | | 限制最大跨度,如:4year |
| utc | `boolean` | `false` | [保存 UTC 值](./input-date#utc) |
| clearable | `boolean` | `true` | 是否可清除 |
| embed | `boolean` | `false` | 是否内联模式 |
| animation | `boolean` | `true` | 是否启用游标动画 | `2.2.0` |
| popOverContainerSelector | `string` | | 弹层挂载位置选择器,会通过`querySelector`获取 | `6.4.0` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------------- | -------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间区间值,用`,`隔开 | 更新数据,依赖格式`format`,例如 '1648746120,1648760760' |

View File

@@ -0,0 +1,49 @@
---
title: Year 年份选择
description:
type: 0
group: null
menuName: Year 年份选择
icon:
order: 61
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-year",
"name": "year",
"label": "年份选择"
}
]
}
```
更多用法和配置可以参考 [InputDate 日期](input-date),year 就是 data 的特定配置,所以 data 的所有配置都能使用。
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值 | 时间值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ---------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`format`,例如:'1617206400' |

View File

@@ -0,0 +1,220 @@
---
title: JSONSchema Editor
description:
type: 0
group: null
menuName: JSONSchema Editor
icon:
order: 61
---
## 基本用法
> 1.9.0 及以上版本
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
debug: true,
"body": [
{
"type": "json-schema-editor",
"name": "schema",
"label": "字段类型"
}
]
}
```
## 顶级类型可配置
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "json-schema-editor",
"name": "schema",
"label": "字段类型",
"rootTypeMutable": true,
"showRootInfo": true
}
]
}
```
## 预设类型
通过设置 definitions 属性可以提供一些默认类型,可以减少类型的定义成本。
```schema: scope="form-item"
{
label: 'JSON Schema Editor',
name: 'schema',
// showRootInfo: true,
// rootTypeMutable: true,
type: 'json-schema-editor',
disabledTypes: ['null', 'interger', 'boolean'],
definitions: {
user: {
type: 'object',
title: '用户',
properties: {
name: {
type: 'string',
title: '用户名',
description: '用户名信息'
},
id: {
type: 'interger',
title: '用户ID'
},
email: {
type: 'string',
title: '用户邮箱'
},
displayName: {
type: 'string',
title: '用户昵称'
}
}
}
}
}
```
## 开启高级配置
通过 `enableAdvancedSetting` 可以开启高级配置,同时通过 `advancedSettings` 可以定制弹窗中的配置面板。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "json-schema-editor",
"name": "schema",
"label": "字段类型",
"enableAdvancedSetting": true,
"advancedSettings": {
"string": [
{
"type": "input-text",
"name": "maxLength",
"label": "Max Length"
}
],
"number": [
{
"type": "input-number",
"name": "max",
"label": "Max"
}
]
}
}
]
}
```
## Mini 版本
通过设置 `mini` 属性可以开启 mini 版本,适用于宽度窄的情况。同时通过 `advancedSettings` 可以定制弹窗中的配置面板。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "json-schema-editor",
"name": "schema",
"label": "字段类型",
"mini": true,
"style": {
"width": 300
},
"advancedSettings": {
"string": [
{
"type": "input-text",
"name": "maxLength",
"label": "Max Length"
}
],
"number": [
{
"type": "input-number",
"name": "max",
"label": "Max"
}
]
}
}
]
}
```
## 占位提示
> 2.8.0 及以上版本
设置`placeholder`属性,可以修改属性控件的默认占位提示文本,当前属性值会和默认值做合并
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "json-schema-editor",
"name": "schema",
"label": "字段类型",
"enableAdvancedSetting": true,
"placeholder": {
"key": "请输入字段名称",
"title": "请输入名称",
"description": "请输入描述信息",
"default": "",
"empty": "暂无字段"
}
}
]
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| --------------- | ----------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ------- |
| rootTypeMutable | `boolean` | false | 顶级类型是否可配置 |
| showRootInfo | `boolean` | false | 是否显示顶级类型信息 |
| disabledTypes | `Array<string>` | | 用来禁用默认数据类型,默认类型有:string、number、interger、object、number、array、boolean、null |
| definitions | `object` | | 用来配置预设类型 |
| mini | `boolean` | | 用来开启迷你模式,适应于边栏面板,宽度较低的情况 |
| placeholder | `SchemaEditorItemPlaceholder` | `{key: "字段名", title: "名称", description: "描述", default: "默认值", empty: "<空>",}` | 属性输入控件的占位提示文本 | `2.8.0` |
### SchemaEditorItemPlaceholder
```typescript
interface SchemaEditorItemPlaceholder {
/* 字段名称输入框占位文本 */
key?: string;
/* 名称输入框占位文本 */
title?: string;
/* 描述信息输入框占位文本 */
description?: string;
/* 默认值输入框占位文本 */
default?: string;
/* 默认值输入框占位文本 */
empty?: string;
}
```

View File

@@ -0,0 +1,272 @@
---
title: JSONSchema
description:
type: 0
group: null
menuName: JSONSchema
icon:
order: 61
---
## 基本用法
> 1.10.0 及以上版本
这个组件可以基于 JSON Schema 生成表单项,方便对接类似 OpenAPI/Swagger Specification 的接口规范,可基于接口定义自动生成 amis 表单项。
> 此组件还在实验阶段,很多 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
}
}
}
}
]
}
```
## 搭配公式使用
> 6.4.0 及以上版本
通过配置 `formula` 属性,可以配合公式使用。
```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
}
}
},
"formula": {
"mode":"input-group",
"mixedMode": true,
"variables": [
{
"label": "表单字段",
"children": [
{
"label": "文章名",
"value": "name",
"tag": "文本"
},
{
"label": "作者",
"value": "author",
"tag": "文本"
},
{
"label": "售价",
"value": "price",
"tag": "数字"
},
{
"label": "出版时间",
"value": "time",
"tag": "时间"
},
{
"label": "版本号",
"value": "version",
"tag": "数字"
},
{
"label": "出版社",
"value": "publisher",
"tag": "文本"
}
]
},
{
"label": "流程字段",
"children": [
{
"label": "联系电话",
"value": "telphone"
},
{
"label": "地址",
"value": "addr"
}
]
},
{
"label": "长文本测试分类长文本测试分类长文本测试分类长文本测试分类",
"children": [
{
"label": "这是一段测试长文本这是一段测试长文本这是一段测试长文本",
"value": "longtext",
"tag": "文本"
}
]
}
]
}
}
]
}
```
## 远程获取 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 |

View File

@@ -0,0 +1,322 @@
---
title: ListSelect 列表
description:
type: 0
group: null
menuName: ListSelect
icon:
order: 29
---
ListSelect 一般用来实现选择,可以单选也可以多选,和 Radio/Checkboxs 最大的不同是在展现方面支持带图片。
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "list-select",
"name": "select",
"label": "单选",
"clearable": true,
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
}
]
}
]
}
```
## 选项带图片
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "list-select",
"name": "select",
"label": "图片",
"options": [
{
"label": "OptionA",
"value": "a",
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
},
{
"label": "OptionB",
"value": "b",
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
},
{
"label": "OptionC",
"value": "c",
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
},
{
"label": "OptionD",
"value": "d",
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg"
}
]
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------- | ----------------------------------------- | --------- | ------------------------------------------------------------------------------------------- |
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
| multiple | `boolean` | `false` | [多选](./options#%E5%A4%9A%E9%80%89-multiple) |
| labelField | `string` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
| valueField | `string` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
| autoFill | `object` | | [自动填充](./options#%E8%87%AA%E5%8A%A8%E5%A1%AB%E5%85%85-autofill) |
| listClassName | `string` | | 支持配置 list div 的 css 类名。比如: `flex justify-between` |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------- | ---------------- |
| change | `[name]: string` 组件的值 | 选中值变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "list-select",
"name": "select",
"label": "单选",
"clearable": true,
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
}
],
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | -------------------------------------- | --------------------------------------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
| setValue | `value: string` \| `string[]` 更新的值 | 更新数据,开启`multiple`支持设置多项,开启`joinValues`时,多值用`,`分隔,否则多值用数组 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "list-select",
"name": "select",
"label": "单选",
"clearable": true,
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
}
],
"value": "a",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "list-select",
"name": "select",
"label": "单选",
"clearable": true,
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
}
],
"value": "a",
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### reload
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "list-select",
"name": "select",
"label": "单选",
"clearable": true,
"id": "reload_type",
"source": "/api/mock2/form/getOptions?waitSeconds=1",
"value": "a"
},
{
"type": "button",
"label": "重新加载",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reload",
"componentId": "reload_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "list-select",
"name": "select",
"label": "单选",
"clearable": true,
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
}
],
"value": "a",
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "b"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,297 @@
---
title: LocationPicker 地理位置
description:
type: 0
group: null
menuName: LocationPicker
icon:
order: 30
---
用于选择地理位置
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "location-picker",
"name": "location",
"ak": "LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7",
"label": "地址"
}
]
}
```
注意其中的 `ak` 参数只能在 amis 官网示例中使用,请前往[百度地图开放平台](http://lbsyun.baidu.com/)申请自己的 `ak`。
## 静态展示
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "location-picker",
"name": "location",
"ak": "LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7",
"label": "默认展示方式",
"value": {
"address": "北京市西城区复兴门内大街97号",
"lat": 39.91404014231763,
"lng": 116.36857981150743,
"zoom": 12
},
"static": true
},
{
"type": "location-picker",
"name": "location",
"ak": "LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7",
"label": "内嵌地图展示",
"value": {
"address": "北京市西城区复兴门内大街97号",
"lat": 39.91404014231763,
"lng": 116.36857981150743,
"zoom": 12
},
"static": true,
"staticSchema": {
"embed": true,
"showAddress": true
}
}
]
}
```
## 高德地图(暂不支持)
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "location-picker",
"name": "location",
"vendor": "gaode",
"ak": "8ae6a7549ce3f37f8e5aab9d445df8ad",
"label": "地址"
},
]
}
```
高德地图需要设置 `vendor` 为 `gaode`,并且需要设置 `ak`。其中的 ak 参数为随机值, 请替换为自己申请的 `ak` , 高德地图的 `ak` 申请地址:[高德地图开放平台](https://lbs.amap.com/)
请注意: **_高德地图不支持坐标转换_**
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------------------ | ------------------ | ------------------------------------ | -------------------------------------------------------------------------------- |
| value | `LocationData` | 参考 [`LocationData`](#LocationData) | |
| vendor | 'baidu' \| 'gaode' | 'baidu' | 地图厂商,目前只实现了百度地图和高德地图 |
| ak | `string` | 无 | 百度/高德地图的 ak |
| clearable | `boolean` | false | 输入框是否可清空 |
| placeholder | `string` | '请选择位置' | 默认提示 |
| autoSelectCurrentLoc | `boolean` | false | 是否自动选中当前地理位置 |
| onlySelectCurrentLoc | `boolean` | false | 是否限制只能选中当前地理位置,设置为 true 后,可用于充当定位组件 |
| coordinatesType | 'bd09' \| 'gcj02' | 'bd09' | 坐标系类型,默认百度坐标,使用高德地图时应设置为'gcj02', 高德地图不支持坐标转换 |
| staticSchema | `object` | | 静态展示,内嵌模式`{static: true: embed: true}`时的额外配置 |
| staticSchema.embed | `boolean` | false | 是否内嵌地图展示地理位置 |
| staticSchema.showAddress | `boolean` | true | 内嵌模式是否展示文字地址 |
| staticSchema.showGeoLoc | `boolean` | false | 内嵌模式是否展示定位当当前控件 |
| staticSchema.mapStyle | `object` | | 内嵌模式地图的样式,可以传宽高控制大小 |
### 坐标系说明
- bd09:百度坐标系,在 GCJ02 坐标系基础上再次加密。
- gcj02:火星坐标系,是由中国国家测绘局制定的地理坐标系统。
### LocationData
| 属性值 | 类型 | 是否必填 | 说明 |
| ------- | ------------------ | -------- | ----------------------- |
| address | `string` | 是 | 地址信息 |
| lng | `number` | 是 | 经度,范围:[-180, 180] |
| lat | `number` | 是 | 维度,范围:[-90, 90] |
| vendor | 'baidu' \| 'gaode' | 否 | 地图厂商类型 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------------- | ---------------- |
| change | `[name]: LocationData` 组件的值 | 选中值变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "location-picker",
"name": "location",
"ak": "LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7",
"label": "地址",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | -------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value` | 参考 [`LocationData`](#LocationData) |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "location-picker",
"name": "location",
"ak": "LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7",
"label": "地址",
"value": {
"address":"北京市西城区府右街131号",
"lat":39.916383659908185,
"lng":116.38854914523102,
"city":"北京市",
"vendor":"baidu"
},
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "location-picker",
"name": "location",
"ak": "LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7",
"label": "地址",
"value": {
"address":"北京市西城区府右街131号",
"lat":39.916383659908185,
"lng":116.38854914523102,
"city":"北京市",
"vendor":"baidu"
},
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "location-picker",
"name": "location",
"ak": "LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7",
"label": "地址",
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": {
"address":"北京市西城区府右街131号",
"lat":39.916383659908185,
"lng":116.38854914523102,
"city":"北京市",
"vendor":"baidu"
}
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,639 @@
---
title: MatrixCheckboxes 矩阵
description:
type: 0
group: null
menuName: MatrixCheckboxes
icon:
order: 30
---
矩阵类型的输入框。
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
]
}
]
}
```
## 全选
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"xCheckAll": true,
"yCheckAll": true,
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
]
}
]
}
```
## 单选模式
配置`"multiple": false`可以设置单选,配置`singleSelectMode`可以设置单选模式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"multiple": false,
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
]
}
]
}
```
## 动态选项
可以配置 source 渲染动态选项
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "matrix",
"type": "matrix-checkboxes",
"label": "动态矩阵组件",
"source": "/api/mock2/options/matrix?waitSeconds=1"
}
]
}
```
以上面为例,source 接口返回格式如下:
```json
{
"status": 0,
"msg": "ok",
"data": {
"columns": [
{
"label": "Col A",
"col": "a"
},
{
"label": "Col B",
"col": "b"
},
{
"label": "Col C",
"col": "c"
},
{
"label": "Col D",
"col": "d"
},
{
"label": "Col E",
"col": "e"
}
],
"rows": [
{
"label": "Row 1",
"rol": 1
},
{
"label": "Row 2",
"rol": 2
},
{
"label": "Row 3",
"rol": 3
},
{
"label": "Row 4",
"rol": 4
},
{
"label": "Row 5",
"rol": 5
},
{
"label": "Row 6",
"rol": 6
}
]
}
}
```
### column 模式
默认为 column 模式,即每列只能单选某个单元格
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"multiple": false,
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
]
}
]
}
```
### cell 模式
cell 模式,指全部选项中只能单选某个单元格
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"multiple": false,
"singleSelectMode": "cell",
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
]
}
]
}
```
### row 模式
row 模式,每行只能单选某个单元格
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"multiple": false,
"singleSelectMode": "row",
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
]
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ---------------- | ------------------------------ | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| columns | `Array<column>` | | 列信息,数组中 `label` 字段是必须给出的 |
| rows | `Array<row>` | | 行信息, 数组中 `label` 字段是必须给出的 |
| rowLabel | `string` | | 行标题说明 |
| source | [API](../../../docs/types/api) | | Api 地址,如果选项组不固定,可以通过配置 `source` 动态拉取。 |
| multiple | `boolean` | `true` | 是否多选 |
| singleSelectMode | `string` | `"column"` | 设置单选模式,`multiple`为`false`时有效,可设置为`cell`, `row`, `column` 分别为全部选项中只能单选某个单元格、每行只能单选某个单元格,每列只能单选某个单元格 |
| textAlign | `string` | `"center"` | 当开启多选+全选时,默认为'left' |
| yCheckAll | `boolean` | `false` | 列上的全选 |
| xCheckAll | `boolean` | `false` | 行上的全选 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------ | ---------------- |
| change | `[name]: Array` 组件的值 | 选中值变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
],
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ----------------------- | ------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
| setValue | `value: Array` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
],
"value": [
[
{
"label": "列1",
"checked": true
},
{
"label": "列1",
"checked": false
}
],
[
{
"label": "列2",
"checked": false
},
{
"label": "列2",
"checked": true
}
]
],
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
],
"value": [
[
{
"label": "列1",
"checked": true
},
{
"label": "列1",
"checked": false
}
],
[
{
"label": "列2",
"checked": false
},
{
"label": "列2",
"checked": true
}
]
],
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### reload
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "list-select",
"name": "select",
"label": "单选",
"clearable": true,
"id": "reload_type",
"source": "/api/mock2/form/getOptions?waitSeconds=1",
"value": "a"
},
{
"type": "button",
"label": "重新加载",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reload",
"componentId": "reload_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "matrix-checkboxes",
"name": "matrix",
"label": "Matrix",
"rowLabel": "行标题说明",
"columns": [
{
"label": "列1"
},
{
"label": "列2"
}
],
"rows": [
{
"label": "行1"
},
{
"label": "行2"
}
],
"value": "a",
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": [
[
{
"label": "列1",
"checked": true
},
{
"label": "列1",
"checked": true
}
],
[
{
"label": "列2",
"checked": false
},
{
"label": "列2",
"checked": true
}
]
]
}
}
]
}
}
}
]
}
```

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,321 @@
---
title: Radio 单选框
description:
type: 0
group: null
menuName: Radio
icon:
order: 8
---
实现组合中的单选功能,此组件只有在 `combo` 和 `input-table` 中有意义。
## combo 中使用
```schema: scope="body"
{
"type": "form",
"debug": true,
data: {
answers: [
{
isAnswer: false,
answer: '选项 1'
},
{
isAnswer: false,
answer: '选项 2',
}
]
},
"body": [
{
type: 'combo',
label: '可选答案',
name: 'answers',
multiple: true,
addable: true,
strictMode: false,
items: [
{
type: 'radio',
name: 'isAnswer',
columnClassName: 'no-grow'
},
{
type: 'input-text',
name: 'answer',
placeholder: '答案文案'
}
]
},
]
}
```
## input-table 中使用
```schema: scope="body"
{
"type": "form",
"debug": true,
data: {
answers: [
{
isAnswer: false,
answer: '选项 1'
},
{
isAnswer: false,
answer: '选项 2',
children: [
{
isAnswer: false,
answer: '选项 1'
},
{
isAnswer: false,
answer: '选项 2'
}
]
}
]
},
"body": [
{
type: 'input-table',
label: '可选答案',
name: 'answers',
multiple: true,
addable: true,
strictMode: false,
columns: [
{
label: '',
type: 'radio',
name: 'isAnswer',
},
{
label: '答案文案',
type: 'input-text',
name: 'answer',
placeholder: '答案文案'
}
]
}
]
}
```
## 配置真假值
默认情况:
- 单选框勾选时,表单项值为:true
- 单选框取消勾选时,表单项值为:false
如果你想调整这个值,可以配置`trueValue`和`falseValue`
```schema: scope="body"
{
"type": "form",
"debug": true,
data: {
answers: [
{
isAnswer: false,
answer: '选项 1'
},
{
isAnswer: false,
answer: '选项 2',
}
]
},
"body": [
{
type: 'combo',
label: '可选答案',
name: 'answers',
multiple: true,
addable: true,
strictMode: false,
items: [
{
type: 'radio',
name: 'isAnswer',
columnClassName: 'no-grow',
trueValue: 1,
falseValue: 0
},
{
type: 'input-text',
name: 'answer',
placeholder: '答案文案'
}
]
},
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ---------- | ------------------------- | ------- | -------- |
| option | `string` | | 选项说明 |
| trueValue | `string|number|boolean` | `true` | 标识真值 |
| falseValue | `string|number|boolean` | `false` | 标识假值 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`来获取事件产生的数据(`< 2.3.2 及以下版本 为 ${event.data.[事件参数名]}`),详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | -------------------------- | ------------------ |
| change | `[name]: boolean` 组件的值 | 选中状态变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "radio",
"name": "radio",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------------- | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string \|number \|boolean` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "radio",
"label": "选项",
"name": "type",
"id": "clear_type",
"option": "选项说明",
"value": true
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_type"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "radio",
"label": "选项",
"name": "type",
"id": "reset_type",
"option": "选项说明",
"value": false
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"type": "radio",
"label": "选项",
"name": "type",
"id": "setvalue_type",
"option": "选项说明",
"value": true
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_type",
"args": {
"value": false
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,508 @@
---
title: Radios 单选框
description:
type: 0
group: null
menuName: Radios 单选框
icon:
order: 36
---
用于实现单选。
## 基本用法
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 列显示
设置 `inline` 可以纵向显示,用于显示列很多的情况
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"inline": false,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 控制列显示的分裂
通过 columnsCount 来设置列显示的列数,比如下面例子是两列。
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"inline": false,
"columnsCount": 2,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 默认选择第一个
通过 `selectFirst` 属性配置
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"selectFirst": true,
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
]
}
]
}
```
## 动态选项
可以配置 `source` 来从上下文或远程 api 拉取选项数据
```schema: scope="body"
{
"type": "page",
"body": {
"type": "form",
"data": {
"items": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b"
},
{
"label": "C",
"value": "c"
}
]
},
"body": [
{
"label": "选项",
"type": "radios",
"name": "radios",
"source": "${items}"
}
]
}
}
```
远程 api
```schema: scope="body"
{
"type": "page",
"body": {
"type": "form",
"body": [
{
"label": "选项",
"type": "radios",
"name": "radios",
"source": "/api/mock2/form/getOptions?waitSeconds=1"
}
]
}
}
```
api 返回内容需要包含 options 字段
```json
{
"status": 0,
"msg": "",
"data": {
"value": "b", // 可选,如果返回就会自动选中 b 选项
// 必须用 options 作为选项组的 key 值
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b"
},
{
"label": "C",
"value": "c"
}
]
}
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------ | ----------------------------------------- | --------- | ------------------------------------------------------------------------------------------- |
| options | `Array<object>`或`Array<string>` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) |
| source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) |
| labelField | `string` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) |
| valueField | `string` | `"value"` | [选项值字段](./options#%E9%80%89%E9%A1%B9%E5%80%BC%E5%AD%97%E6%AE%B5-valuefield) |
| columnsCount | `number` | `1` | 选项按几列显示,默认为一列 |
| inline | `boolean` | `true` | 是否显示为一行 |
| selectFirst | `boolean` | `false` | 是否默认选中第一个 |
| autoFill | `object` | | [自动填充](./options#%E8%87%AA%E5%8A%A8%E5%A1%AB%E5%85%85-autofill) |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | --------------------------------------------------------------------------------------------- | ---------------- |
| change | `[name]: string` 组件的值<br/>`selectedItems: Option` 选中的项<br/>`items: Option[]` 选项集合 | 选中值变化时触发 |
### change
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
],
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msg": "${event.data.value|json}"
}
}
]
}
}
}
]
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| reload | - | 重新加载,调用 `source`,刷新数据域数据刷新(重新加载) |
| setValue | `value: string` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
],
"value": "a",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
],
"value": "a",
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### reload
只有选择器模式支持,即配置`source`,用于重新加载选择器的数据源。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"id": "reload_type",
"source": "/api/mock2/form/getOptions",
"value": "a"
},
{
"type": "button",
"label": "重新加载",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reload",
"componentId": "reload_type"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "radios",
"type": "radios",
"label": "radios",
"options": [
{
"label": "OptionA",
"value": "a"
},
{
"label": "OptionB",
"value": "b"
},
{
"label": "OptionC",
"value": "c"
},
{
"label": "OptionD",
"value": "d"
}
],
"value": "a",
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "b"
}
}
]
}
}
}
]
}
```

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,303 @@
---
title: Static 静态展示
description:
type: 0
group: null
menuName: Static 静态展示
icon:
order: 52
---
> 推荐在`2.4.0`版本后使用[新版静态展示](./formitem#配置静态展示)来实现该功能
> 常用表单项已支持静态展示:[支持静态展示的表单项](./formitem#支持静态展示的表单项),展示效果请查看[示例页](../../../examples/form/switchDisplay)
> 新版静态展示还可以实现整个表单的静态展示及切换,具体用法请参考[表单静态展示](./index#表单静态展示)
用来在表单中,展示静态数据
## 基本用法
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "static",
"type": "static",
"label": "静态展示",
"value": "aaa"
}
]
}
```
## 数据域变量映射
除了显式配置`value`属性,来展示数据以外,支持通过配置`name`属性,来自动映射数据域中的相关变量
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "select",
"name": "select",
"label": "select",
"options": [
{
"label":"A",
"value":"a"
},
{
"label":"B",
"value":"b"
},
{
"label":"C",
"value":"c"
}
]
},
{
"type": "static",
"name": "select",
"label": "选中的值是"
}
]
}
```
## 展示其他组件
支持通过配置`type`为`static-xxx`的形式,展示其他 **非[表单项](./formitem)** 组件,例如:
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "static-json",
"name": "json",
"label": "静态展示JSON",
"value": {
"a": "aaa",
"b": "bbb"
}
}
]
}
```
理论上可以支持所有非表达项的所有组件,并且支持对应的配置项,下面是一些示例:
```schema: scope="body"
{
"type": "form",
"data": {
"id": 1,
"image": "https://suda.cdn.bcebos.com/amis/images/alice-macaw.jpg",
"images": [
{
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692722/4f3cb4202335.jpeg"
},
{
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395692942/d8e4992057f9.jpeg"
},
{
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693148/1314a2a3d3f6.jpeg"
},
{
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693379/8f2e79f82be0.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693379/8f2e79f82be0.jpeg"
},
{
"image": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693566/552b175ef11d.jpeg@s_0,w_216,l_1,f_jpg,q_80",
"src": "https://internal-amis-res.cdn.bcebos.com/images/2020-1/1578395693566/552b175ef11d.jpeg"
}
]
},
"api": "/api/mock2/saveForm?waitSeconds=2",
"title": "表单项静态展示",
"mode": "horizontal",
"body": [
{
"type": "static",
"label": "文本",
"value": "文本"
},
{
"type": "divider"
},
{
"type": "static-tpl",
"label": "模板",
"tpl": "自己拼接 HTML 取变量 \\${id}: ${id}"
},
{
"type": "divider"
},
{
"type": "static-date",
"label": "日期",
"value": 1593327764
},
{
"type": "divider"
},
{
"type": "static-datetime",
"label": "日期时间",
"value": 1593327764
},
{
"type": "divider"
},
{
"type": "static-mapping",
"label": "映射",
"value": 2,
"map": {
"0": "<span class='label label-info'>一</span>",
"1": "<span class='label label-success'>二</span>",
"2": "<span class='label label-danger'>三</span>",
"3": "<span class='label label-warning'>四</span>",
"4": "<span class='label label-primary'>五</span>",
"*": "<span class='label label-default'>-</span>"
}
},
{
"type": "divider"
},
{
"type": "static-progress",
"label": "进度",
"value": 66.66
},
{
"type": "divider"
},
{
"type": "static-image",
"label": "图片",
"name": "image",
"thumbMode": "cover",
"thumbRatio": "4:3",
"title": "233",
"imageCaption": "jfe fjkda fejfkda fejk fdajf dajfe jfkda",
"popOver": {
"title": "查看大图",
"body": "<div class=\"w-xxl\"><img class=\"w-full\" src=\"${image}\"/></div>"
}
},
{
"type": "divider"
},
{
"type": "static-image",
"label": "图片自带放大",
"name": "image",
"thumbMode": "cover",
"thumbRatio": "4:3",
"title": "233",
"imageCaption": "jfe fjkda fejfkda fejk fdajf dajfe jfkda",
"enlargeAble": true,
"originalSrc": "${image}"
},
{
"type": "static-images",
"label": "图片集",
"name": "images",
"thumbMode": "cover",
"thumbRatio": "4:3",
"enlargeAble": true,
"originalSrc": "${src}"
},
{
"type": "divider"
},
{
"type": "static-json",
"label": "JSON",
"value": {
"a": 1,
"b": 2,
"c": {
"d": 3
}
}
},
{
"type": "divider"
},
{
"type": "static",
"label": "可复制",
"value": "文本",
"copyable": {
"content": "内容,支持变量 ${id}"
}
},
{
"type": "divider"
},
{
"type": "static",
"name": "text",
"label": "可快速编辑",
"value": "文本",
"quickEdit": true
}
]
}
```
想要调整展示组件的配置,请查阅相应组件的文档。
## 快速编辑
通过 `quickEdit` 开启快速编辑功能,比如
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "static",
"type": "static",
"label": "静态展示",
"value": "aaa",
"quickEdit": {
"type": "number"
}
}
]
}
```
其他配置项参考 [快速编辑](../crud#快速编辑)
## 弹出框(popOver)
可以通过 `popOver` 属性配置弹出框
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "static",
"type": "static",
"label": "静态展示",
"value": "aaa",
"popOver": {
"body": {
"type": "tpl",
"tpl": "弹出内容"
}
}
}
]
}
```

View File

@@ -0,0 +1,540 @@
---
title: Switch 开关
description:
type: 0
group: null
menuName: Switch
icon:
order: 51
---
## 基本用法
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "switch",
"type": "switch",
"label": "开关",
"option": "开关说明"
}
]
}
```
## 禁用状态
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "switch",
"type": "switch",
"disabled": true,
"label": "开关",
"option": "开关说明"
}
]
}
```
## 配置真假值
默认情况:
- 开关打开时,表单项值为:true
- 开关关闭时,表单项值为:false
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "switch",
"type": "switch",
"label": "开关"
}
]
}
```
如果你想调整这个值,可以配置`trueValue`和`falseValue`
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "switch",
"type": "switch",
"label": "开关",
"trueValue": 1,
"falseValue": 0
}
]
}
```
调整开关,观察数据域变化,会发现打开后值为`1`,而关闭后为`0`
## 配置开启和关闭状态的文本
> `1.1.5` 版本之后支持
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "switch",
"type": "switch",
"onText": "已开启飞行模式",
"offText": "已关闭飞行模式"
}
]
}
```
### 使用 Schema 配置文本
> `3.6.0` 版本之后支持
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "switch",
"type": "switch",
"onText": [
{
"type": "icon",
"icon": "fa fa-plane",
"vendor": "",
"className": "mr-1"
},
{
"type": "tpl",
"tpl": "飞行模式"
}
],
"offText": [
{
"type": "icon",
"icon": "fa fa-plane",
"vendor": "",
"className": "mr-1"
},
{
"type": "tpl",
"tpl": "飞行模式"
}
]
}
]
}
```
## 默认值
和其它表单项一样,如果要设置默认值,可以使用 value 属性
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "switch",
"type": "switch",
"label": "开关",
"value": false
}
]
}
```
## 不同尺寸
> `2.0.0` 及以上版本
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "switch",
"type": "switch",
"label": ""
},
{
"name": "switch-sm",
"type": "switch",
"label": "",
"size": "sm"
}
]
}
```
## 加载状态
> `3.6.0` 及以上版本
设置`"loading": true`, 标识开关操作的异步任务仍在执行中。另外`loadingOn`支持表达式
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"data": {
"shouldLoading": true
},
"body": [
{
"type": "switch",
"name": "switch1",
"label": "",
"loading": true,
"value": true
},
{
"type": "switch",
"name": "switch2",
"label": "",
"size": "sm",
"disabled": true,
"loading": true
}
]
}
```
配合`ajax`动作,实现开关操作后台异步任务:
```schema: scope="body"
{
"type": "page",
"body": [
{
"type": "form",
"id": "demo-form",
"body": [
{
"type": "hidden",
"name": "isFetching",
"value": false
},
{
"type": "switch",
"name": "switch",
"label": "操作状态开关",
"mode": "horizontal",
"loadingOn": "${isFetching}",
"onEvent": {
"change": {
"actions": [
{
"actionType": "toast",
"args": {
"msgType": "warning",
"msg": "任务${switch === true ? '派发' : '取消'}成功,等待后台操作..."
}
},
{
"actionType": "setValue",
"componentId": "demo-form",
"args": {
"value": {
"isFetching": true
}
}
},
{
"actionType": "ajax",
"api": {
"url": "/api/mock2/form/saveForm?waitSeconds=3",
"method": "get",
"messages": {
"success": "操作成功",
"failed": "操作失败"
}
}
},
{
"actionType": "setValue",
"componentId": "demo-form",
"args": {
"value": {
"isFetching": false
}
}
}
]
}
}
}
]
}
]
}
```
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 | 版本 |
| ---------- | ------------------------------------------ | ------- | -------------------- | ------------------ |
| option | `string` | | 选项说明 |
| onText | `string \| IconSchema \| SchemaCollection` | | 开启时开关显示的内容 | `3.6.0`支持 Schema |
| offText | `string \| IconSchema \| SchemaCollection` | | 关闭时开关显示的内容 | `3.6.0`支持 Schema |
| trueValue | `boolean \| string \| number` | `true` | 标识真值 |
| falseValue | `boolean \| string \| number` | `false` | 标识假值 |
| size | `"sm" \| "md"` | `"md"` | 开关大小 |
| loading | `boolean` | `false` | 是否处于加载状态 | `3.6.0` |
IconSchema 配置
| 属性名 | 类型 | 默认值 | 说明 |
| ---------- | -------- | --------- | ------------ |
| type | `string` | | `icon` |
| icon | `string` | | icon 的类型 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ------------------------------------ | ---------------- |
| change | `[name]: string \| boolean` 组件的值 | 开关值变化时触发 |
### change
switch 值更新时弹出确认提示,确认后发送请求。
```schema: scope="body"
{
"type": "crud",
"syncLocation": false,
"api": "/api/mock2/sample",
"columns": [
{
"name": "id",
"label": "ID",
"id": "u:daa79afa2e53"
},
{
"name": "engine",
"label": "Rendering engine",
"id": "u:3343cf518656"
},
{
"name": "browser",
"label": "Browser",
"id": "u:fbdc85e45e2f"
},
{
"name": "platform",
"label": "Platform(s)",
"id": "u:ccdb48cc1804"
},
{
"name": "switch",
"label": "开关",
"id": "u:30a36768acce",
"type": "switch",
"inline": true,
"onEvent": {
"change": {
"weight": 0,
"actions": [
{
"actionType": "confirmDialog",
"dialog": {
"type": "dialog",
"title": "弹框标题",
"body": [
{
"type": "tpl",
"tpl": "确定要修改${id}吗?",
"wrapperComponent": "",
"inline": false,
"id": "u:1965506c7599"
}
],
"showCloseButton": true,
"showErrorMsg": true,
"showLoading": true,
"className": "app-popover",
"id": "u:d9783223df98",
"actions": [
{
"type": "button",
"actionType": "cancel",
"label": "取消",
"id": "u:302efee8613b"
},
{
"type": "button",
"actionType": "confirm",
"label": "确定",
"primary": true,
"id": "u:4a4d63cf35e1"
}
]
}
},
{
"actionType": "ajax",
"outputVar": "responseResult",
"options": {
},
"api": {
"method": "get",
"url": "/api/mock2/form/saveForm"
}
}
]
}
},
"value": false
}
],
"id": "u:6c781a765f97"
}
```
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------------------- | ---------------------------------------------------------------------- | --- |
| clear | - | 清空,6.3.1 及以上版本支持 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue`,6.3.1 及以上版本支持 | |
| setValue | `value: string \| boolean` 更新的数据 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "switch",
"label": "开关",
"type": "switch",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "switch",
"label": "开关",
"type": "switch",
"id": "reset_text",
"value": true
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
[
{
"type": "button",
"label": "修改开关的值",
"className": "mb-2",
"onEvent": {
"click": {
"actions": [
{
"componentId": "u:6613bfa3a18e",
"actionType": "setValue",
"args": {
"value": true
}
}
]
}
},
"id": "u:9d7d695145bb"
},
{
"type": "form",
"title": "表单",
"debug": true,
"body": [
{
"label": "开启",
"type": "switch",
"name": "switch",
"id": "u:6613bfa3a18e",
"value": false,
"mode": "inline"
}
],
"id": "u:82d44e407eb0",
"actions": [
{
"type": "submit",
"label": "提交",
"primary": true
}
]
}
]
```

View File

@@ -0,0 +1,559 @@
---
title: TabsTransferPicker 穿梭选择器
description:
type: 0
group: null
menuName: TabsTransferPicker 穿梭选择器
icon:
---
在[TabsTransfer 组合穿梭器](./tabs-transfer)的基础上扩充了弹窗选择模式,展示值用的是简单的 input 框,但是编辑的操作是弹窗个穿梭框来完成。
适合用来做复杂选人组件。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"label": "选人",
"type": "tabs-transfer-picker",
"name": "a",
"sortable": true,
"selectMode": "tree",
"pickerSize": "md",
"menuTpl": "<div class='flex justify-between'><span>${label}</span>${email ? `<div class='text-muted m-r-xs text-sm text-right'>${email}<br />${phone}</div>`: ''}</div>",
"valueTpl": "${label}(${value})",
"options": [
{
"label": "成员",
"selectMode": "tree",
"searchable": true,
"children": [
{
"label": "法师",
"children": [
{
"label": "诸葛亮",
"value": "zhugeliang",
"email": "zhugeliang@timi.com",
"phone": 13111111111
}
]
},
{
"label": "战士",
"children": [
{
"label": "曹操",
"value": "caocao",
"email": "caocao@timi.com",
"phone": 13111111111
},
{
"label": "钟无艳",
"value": "zhongwuyan",
"email": "zhongwuyan@timi.com",
"phone": 13111111111
}
]
},
{
"label": "打野",
"children": [
{
"label": "李白",
"value": "libai",
"email": "libai@timi.com",
"phone": 13111111111
},
{
"label": "韩信",
"value": "hanxin",
"email": "hanxin@timi.com",
"phone": 13111111111
},
{
"label": "云中君",
"value": "yunzhongjun",
"email": "yunzhongjun@timi.com",
"phone": 13111111111
}
]
}
]
},
{
"label": "角色",
"selectMode": "list",
"children": [
{
"label": "角色 1",
"value": "role1",
},
{
"label": "角色 2",
"value": "role2",
},
{
"label": "角色 3",
"value": "role3",
},
{
"label": "角色 4",
"value": "role4",
}
]
},
{
"label": "部门",
"selectMode": "tree",
"children": [
{
"label": "总部",
"value": "dep0",
"children": [
{
"label": "部门 1",
"value": "dep1",
"children": [
{
"label": "部门 4",
"value": "dep4",
},
{
"label": "部门 5",
"value": "dep5",
}
]
},
{
"label": "部门 2",
"value": "dep2",
},
{
"label": "部门 3",
"value": "dep3",
}
]
}
]
}
]
}
]
}
```
## 属性表
更多配置请参考[TabsTransfer 组合穿梭器](./tabs-transfer)。
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | -------------------------------------------------------- | ------------------------- |
| change | `[name]: string` 组件的值<br/>`items: object[]` 选项集合 | picker 弹窗确认提交时触发 |
| focus | `[name]: string` 组件的值 | 获取焦点(非内嵌模式) |
| blur | `[name]: string` 组件的值 | 失去焦点(非内嵌模式) |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | -------------------------------------- | --------------------------------------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` \| `string[]` 更新的值 | 更新数据,开启`multiple`支持设置多项,开启`joinValues`时,多值用`,`分隔,否则多值用数组 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"label": "穿梭选择器",
"type": "tabs-transfer-picker",
"name": "a",
"sortable": true,
"selectMode": "tree",
"options": [
{
"label": "成员",
"selectMode": "tree",
"searchable": true,
"children": [
{
"label": "法师",
"children": [
{
"label": "诸葛亮",
"value": "zhugeliang"
}
]
},
{
"label": "战士",
"children": [
{
"label": "曹操",
"value": "caocao"
},
{
"label": "钟无艳",
"value": "zhongwuyan"
}
]
},
{
"label": "打野",
"children": [
{
"label": "李白",
"value": "libai"
},
{
"label": "韩信",
"value": "hanxin"
},
{
"label": "云中君",
"value": "yunzhongjun"
}
]
}
]
},
{
"label": "用户",
"selectMode": "chained",
"children": [
{
"label": "法师",
"children": [
{
"label": "诸葛亮",
"value": "zhugeliang2"
}
]
},
{
"label": "战士",
"children": [
{
"label": "曹操",
"value": "caocao2"
},
{
"label": "钟无艳",
"value": "zhongwuyan2"
}
]
},
{
"label": "打野",
"children": [
{
"label": "李白",
"value": "libai2"
},
{
"label": "韩信",
"value": "hanxin2"
},
{
"label": "云中君",
"value": "yunzhongjun2"
}
]
}
]
}
],
"value": "zhugeliang",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"label": "穿梭选择器",
"type": "tabs-transfer-picker",
"name": "a",
"sortable": true,
"selectMode": "tree",
"options": [
{
"label": "成员",
"selectMode": "tree",
"searchable": true,
"children": [
{
"label": "法师",
"children": [
{
"label": "诸葛亮",
"value": "zhugeliang"
}
]
},
{
"label": "战士",
"children": [
{
"label": "曹操",
"value": "caocao"
},
{
"label": "钟无艳",
"value": "zhongwuyan"
}
]
},
{
"label": "打野",
"children": [
{
"label": "李白",
"value": "libai"
},
{
"label": "韩信",
"value": "hanxin"
},
{
"label": "云中君",
"value": "yunzhongjun"
}
]
}
]
},
{
"label": "用户",
"selectMode": "chained",
"children": [
{
"label": "法师",
"children": [
{
"label": "诸葛亮",
"value": "zhugeliang2"
}
]
},
{
"label": "战士",
"children": [
{
"label": "曹操",
"value": "caocao2"
},
{
"label": "钟无艳",
"value": "zhongwuyan2"
}
]
},
{
"label": "打野",
"children": [
{
"label": "李白",
"value": "libai2"
},
{
"label": "韩信",
"value": "hanxin2"
},
{
"label": "云中君",
"value": "yunzhongjun2"
}
]
}
]
}
],
"value": "zhugeliang",
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"label": "穿梭选择器",
"type": "tabs-transfer-picker",
"name": "a",
"sortable": true,
"selectMode": "tree",
"options": [
{
"label": "成员",
"selectMode": "tree",
"searchable": true,
"children": [
{
"label": "法师",
"children": [
{
"label": "诸葛亮",
"value": "zhugeliang"
}
]
},
{
"label": "战士",
"children": [
{
"label": "曹操",
"value": "caocao"
},
{
"label": "钟无艳",
"value": "zhongwuyan"
}
]
},
{
"label": "打野",
"children": [
{
"label": "李白",
"value": "libai"
},
{
"label": "韩信",
"value": "hanxin"
},
{
"label": "云中君",
"value": "yunzhongjun"
}
]
}
]
},
{
"label": "用户",
"selectMode": "chained",
"children": [
{
"label": "法师",
"children": [
{
"label": "诸葛亮",
"value": "zhugeliang2"
}
]
},
{
"label": "战士",
"children": [
{
"label": "曹操",
"value": "caocao2"
},
{
"label": "钟无艳",
"value": "zhongwuyan2"
}
]
},
{
"label": "打野",
"children": [
{
"label": "李白",
"value": "libai2"
},
{
"label": "韩信",
"value": "hanxin2"
},
{
"label": "云中君",
"value": "yunzhongjun2"
}
]
}
]
}
],
"value": "zhugeliang",
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "yunzhongjun2"
}
}
]
}
}
}
]
}
```

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,262 @@
---
title: Textarea 多行文本输入框
description:
type: 0
group: null
menuName: Textarea 多行文本输入框
icon:
order: 57
---
## 基本使用
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "textarea",
"type": "textarea",
"label": "多行文本"
}
]
}
```
## 清空输入框
带移除图标的输入框,点击图标删除所有内容。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "textarea",
"type": "textarea",
"label": "多行文本",
"clearable": true,
"value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmodtion tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
}
]
}
```
设置`resetValue`,清空输入框后重置为指定值
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"name": "textarea",
"type": "textarea",
"label": "多行文本",
"clearable": true,
"resetValue": "reset"
}
]
}
```
## 显示计数器
配置`"showCounter": true`后输入框将显示计数器,一般会配合`maxLength`属性以限制输入长度,如果不设置`maxLength`,则仅展示计数器,并不会限制用户的输入长度。
```schema: scope="body"
{
"type": "form",
"body": [
{
"name": "a",
"type": "textarea",
"label": "A",
"showCounter": true,
"placeholder": "请输入",
"clearable": true
},
{
"name": "b",
"type": "textarea",
"label": "B",
"showCounter": true,
"maxLength": 30,
"placeholder": "请输入"
}
]
}
```
## 属性表
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ------------ | --------- | ------- | ---------------------------- |
| minRows | `number` | `3` | 最小行数 |
| maxRows | `number` | `20` | 最大行数 |
| trimContents | `boolean` | `true` | 是否去除首尾空白文本 |
| readOnly | `boolean` | `false` | 是否只读 |
| showCounter | `boolean` | `false` | 是否显示计数器 |
| maxLength | `number` | - | 限制最大字数 |
| clearable | `boolean` | `false` | 是否可清除 |
| resetValue | `string` | `""` | 清除后设置此配置项给定的值。 |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | -------------------------- | -------------------- |
| change | `[name]: string` 组件的值 | 值变化时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点时触发 |
| blur | `[name]: string ` 组件的值 | 输入框失去焦点时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | ------------------------ | ------------------------------------------------ |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| focus | - | 获取焦点 |
| setValue | `value: string` 更新的值 | 更新数据 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "clear_text",
"type": "textarea",
"label": "text",
"value": "清空我"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "reset_text",
"type": "textarea",
"label": "text",
"value": "重置我"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### focus
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "focus_text",
"type": "textarea",
"label": "text",
"value": "聚焦我"
},
{
"type": "button",
"label": "聚焦",
"onEvent": {
"click": {
"actions": [
{
"actionType": "focus",
"componentId": "focus_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"name": "text",
"id": "setvalue_text",
"type": "textarea",
"label": "text",
"value": "amis"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "amis go go go!"
}
}
]
}
}
}
]
}
```

View File

@@ -0,0 +1,330 @@
---
title: TransferPicker 穿梭选择器
description:
type: 0
group: null
menuName: TransferPicker 穿梭选择器
icon:
---
在[穿梭器(Transfer)](./transfer)的基础上扩充了弹窗选择模式,展示值用的是简单的 input 框,但是编辑的操作是弹窗个穿梭框来完成。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"body": [
{
"label": "组合穿梭器",
"type": "transfer-picker",
"name": "a",
"sortable": true,
"selectMode": "tree",
"searchable": true,
"options": [
{
"label": "法师",
"children": [
{
"label": "诸葛亮",
"value": "zhugeliang"
}
]
},
{
"label": "战士",
"children": [
{
"label": "曹操",
"value": "caocao"
},
{
"label": "钟无艳",
"value": "zhongwuyan"
}
]
},
{
"label": "打野",
"children": [
{
"label": "李白",
"value": "libai"
},
{
"label": "韩信",
"value": "hanxin"
},
{
"label": "云中君",
"value": "yunzhongjun"
}
]
}
]
}
]
}
```
## 自定义选项展示
```schema: scope="body"
{
"type": "form",
"body": [
{
"label": "默认",
"type": "transfer-picker",
"name": "transfer",
"menuTpl": "<div class='flex justify-between'><span>${label}</span><span class='text-muted m-r text-sm'>${tag}</span></div>",
"valueTpl": "${label}(${value})",
"options": [
{
"label": "诸葛亮",
"value": "zhugeliang",
"tag": "法师",
},
{
"label": "曹操",
"value": "caocao",
"tag": "战士",
},
{
"label": "钟无艳",
"value": "zhongwuyan",
"tag": "战士",
},
{
"label": "李白",
"value": "libai",
"tag": "打野"
},
{
"label": "韩信",
"value": "hanxin",
"tag": "打野"
},
{
"label": "云中君",
"value": "yunzhongjun",
"tag": "打野"
}
]
}
]
}
```
## 属性表
下面属性为`transfer-picker`独占属性,更多属性用法,参考[穿梭器(Transfer)](./transfer)
| 属性名 | 类型 | 默认值 | 说明 |
| ---------- | -------------------------------- | ------ | -------------------------------------------------------------- |
| borderMode | `'full'` \| `'half'` \| `'none'` | | 边框模式,`'full'`为全边框,`'half'`为半边框,`'none'`为没边框 |
| pickerSize | string | | 弹窗大小,支持: xs、sm、md、lg、xl、full |
## 事件表
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
| 事件名称 | 事件参数 | 说明 |
| -------- | ----------------------------------------------------------------------------------------- | -------------------------------- |
| change | `[name]: string` 组件的值<br/>`items: object[]`选项集合(< 2.3.2 及以下版本 为`options`) | picker 弹窗确认提交时触发 |
| focus | `[name]: string` 组件的值 | 输入框获取焦点(非内嵌模式)时触发 |
| blur | `[name]: string` 组件的值 | 输入框失去焦点(非内嵌模式)时触发 |
## 动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
| 动作名称 | 动作配置 | 说明 |
| -------- | -------------------------------------- | --------------------------------------------------------------------------------------- |
| clear | - | 清空 |
| reset | - | 将值重置为初始值。6.3.0 及以下版本为`resetValue` |
| setValue | `value: string` \| `string[]` 更新的值 | 更新数据,开启`multiple`支持设置多项,开启`joinValues`时,多值用`,`分隔,否则多值用数组 |
### clear
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"label": "默认",
"type": "transfer-picker",
"name": "transfer",
"value": "zhugeliang,libai",
"options": [
{
"label": "诸葛亮",
"value": "zhugeliang"
},
{
"label": "曹操",
"value": "caocao"
},
{
"label": "钟无艳",
"value": "zhongwuyan"
},
{
"label": "李白",
"value": "libai"
},
{
"label": "韩信",
"value": "hanxin"
},
{
"label": "云中君",
"value": "yunzhongjun"
}
],
"value": "zhugeliang",
"id": "clear_text"
},
{
"type": "button",
"label": "清空",
"onEvent": {
"click": {
"actions": [
{
"actionType": "clear",
"componentId": "clear_text"
}
]
}
}
}
]
}
```
### reset
如果配置了`resetValue`,则重置时使用`resetValue`的值,否则使用初始值。
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"label": "默认",
"type": "transfer-picker",
"name": "transfer",
"value": "zhugeliang,libai",
"options": [
{
"label": "诸葛亮",
"value": "zhugeliang"
},
{
"label": "曹操",
"value": "caocao"
},
{
"label": "钟无艳",
"value": "zhongwuyan"
},
{
"label": "李白",
"value": "libai"
},
{
"label": "韩信",
"value": "hanxin"
},
{
"label": "云中君",
"value": "yunzhongjun"
}
],
"value": "zhugeliang",
"id": "reset_text"
},
{
"type": "button",
"label": "重置",
"onEvent": {
"click": {
"actions": [
{
"actionType": "reset",
"componentId": "reset_text"
}
]
}
}
}
]
}
```
### setValue
```schema: scope="body"
{
"type": "form",
"debug": true,
"body": [
{
"label": "默认",
"type": "transfer-picker",
"name": "transfer",
"value": "zhugeliang,libai",
"options": [
{
"label": "诸葛亮",
"value": "zhugeliang"
},
{
"label": "曹操",
"value": "caocao"
},
{
"label": "钟无艳",
"value": "zhongwuyan"
},
{
"label": "李白",
"value": "libai"
},
{
"label": "韩信",
"value": "hanxin"
},
{
"label": "云中君",
"value": "yunzhongjun"
}
],
"value": "zhugeliang",
"id": "setvalue_text"
},
{
"type": "button",
"label": "赋值",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "setvalue_text",
"args": {
"value": "yunzhongjun"
}
}
]
}
}
}
]
}
```

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
---
title: UUID 字段
description:
type: 0
group: null
menuName: UUID 字段
icon:
order: 30
---
## 基本用法
随机生成一个 id,可以用于防止表单重复提交。
```schema: scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "uuid",
"name": "uuid"
}
]
}
```
这个字段是不显示的,上面这个例子之所以显示是因为加了 `debug: true`。
## length
目前 uuid 的唯一可设置参数是 length,用于生成短随机数
```schema:height="200" scope="body"
{
"type": "form",
"api": "/api/mock2/form/saveForm",
"debug": true,
"body": [
{
"type": "uuid",
"name": "uuid",
"length": 8
}
]
}
```