2020-07-28 10:03:53 +08:00
|
|
|
|
---
|
2021-06-03 22:09:30 +08:00
|
|
|
|
title: InputText 输入框
|
2020-07-29 16:20:21 +08:00
|
|
|
|
description:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
type: 0
|
|
|
|
|
group: null
|
2021-06-03 22:09:30 +08:00
|
|
|
|
menuName: InputText 输入框
|
2020-07-29 16:20:21 +08:00
|
|
|
|
icon:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
order: 56
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 基本使用
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "text",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-text",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"label": "text"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-07-11 17:01:19 +08:00
|
|
|
|
## 不同边框风格
|
|
|
|
|
|
|
|
|
|
```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"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 不同类型
|
|
|
|
|
|
|
|
|
|
配置`type`可以支持不同格式的文本输入框
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "text",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-text",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"label": "text"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "divider"
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-url",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "url",
|
|
|
|
|
"label": "链接"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "divider"
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-email",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "email",
|
|
|
|
|
"label": "邮箱"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "divider"
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-password",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "password",
|
|
|
|
|
"label": "密码"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 附加组件
|
|
|
|
|
|
2021-01-28 16:30:38 +08:00
|
|
|
|
可以配置`addOn`,附带附加组件,比如 button,还能设置 icon。
|
2020-07-28 10:03:53 +08:00
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "text",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-text",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"label": "text",
|
|
|
|
|
"addOn": {
|
|
|
|
|
"type": "button",
|
2021-01-28 17:04:31 +08:00
|
|
|
|
"icon": "https://suda.cdn.bcebos.com/images%2F2021-01%2Fsearch.svg",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"label": "搜索"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-03-19 09:40:59 +08:00
|
|
|
|
## 可清除
|
|
|
|
|
|
|
|
|
|
通过 `"clearable": true` 可以设置文本可清除
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2021-03-19 09:40:59 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "text",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-text",
|
2021-03-19 09:40:59 +08:00
|
|
|
|
"label": "text",
|
2021-03-26 16:11:09 +08:00
|
|
|
|
"clearable": true
|
2021-03-19 09:40:59 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 选择器模式
|
|
|
|
|
|
|
|
|
|
配置`options`即可支持选择器模式。
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "text",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-text",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"label": "text",
|
2021-09-08 13:59:39 +08:00
|
|
|
|
"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,
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"options": [
|
|
|
|
|
{
|
|
|
|
|
"label": "OptionA",
|
|
|
|
|
"value": "a"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "OptionB",
|
|
|
|
|
"value": "b"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "OptionC",
|
|
|
|
|
"value": "c"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "OptionD",
|
|
|
|
|
"value": "d"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-09-08 13:59:39 +08:00
|
|
|
|
## 多选模式
|
|
|
|
|
|
|
|
|
|
配置 multiple: true
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2022-04-02 16:52:13 +08:00
|
|
|
|
"debug": true,
|
2021-09-08 13:59:39 +08:00
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"name": "text",
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"label": "text",
|
|
|
|
|
"multiple": true,
|
|
|
|
|
"options": [
|
|
|
|
|
{
|
|
|
|
|
"label": "OptionA",
|
|
|
|
|
"value": "a"
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-14 19:36:37 +08:00
|
|
|
|
"label": "OptionB (with long suffix for testing ellipsis)",
|
2021-09-08 13:59:39 +08:00
|
|
|
|
"value": "b"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "OptionC",
|
|
|
|
|
"value": "c"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "OptionD",
|
|
|
|
|
"value": "d"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
2020-07-28 10:03:53 +08:00
|
|
|
|
|
2021-08-13 17:16:17 +08:00
|
|
|
|
## 前缀和后缀
|
|
|
|
|
|
2022-09-26 14:41:57 +08:00
|
|
|
|
`prefix` 和 `suffix` 属性支持数据映射。
|
|
|
|
|
|
2021-08-13 17:16:17 +08:00
|
|
|
|
```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}"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-08-24 21:24:54 +08:00
|
|
|
|
## 显示计数器
|
|
|
|
|
|
2022-09-26 14:41:57 +08:00
|
|
|
|
配置`"showCounter": true`后输入框将显示计数器,一般会配合`maxLength`属性以限制输入长度,如果不设置`maxLength`,则仅展示计数器,并不会限制用户的输入长度。
|
|
|
|
|
|
2021-08-24 21:24:54 +08:00
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"name": "a",
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"label": "A",
|
|
|
|
|
"showCounter": true,
|
2022-09-26 14:41:57 +08:00
|
|
|
|
"placeholder": "请输入",
|
|
|
|
|
"showCounter": true,
|
|
|
|
|
"options": [
|
|
|
|
|
{
|
|
|
|
|
"label": "aa",
|
|
|
|
|
"value": "aa"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "bb",
|
|
|
|
|
"value": "bb"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "cc",
|
|
|
|
|
"value": "cc"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "dd",
|
|
|
|
|
"value": "dd"
|
|
|
|
|
}
|
|
|
|
|
]
|
2021-08-24 21:24:54 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "b",
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"label": "B",
|
|
|
|
|
"showCounter": true,
|
2022-09-26 14:41:57 +08:00
|
|
|
|
"maxLength": 20,
|
2021-08-24 21:24:54 +08:00
|
|
|
|
"placeholder": "请输入"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-01-18 15:38:48 +08:00
|
|
|
|
## 自动转换值
|
|
|
|
|
|
|
|
|
|
可以配置 transform,来自动转换值,支持转小写或大写。
|
|
|
|
|
|
2022-04-28 11:37:40 +08:00
|
|
|
|
> 注意下面第一个示例,只有输入的内容才会触发 transform,下拉框选中的值是不会处理的。
|
|
|
|
|
|
2022-01-18 15:38:48 +08:00
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2022-04-28 11:37:40 +08:00
|
|
|
|
"debug": true,
|
2022-01-18 15:38:48 +08:00
|
|
|
|
"body": [
|
|
|
|
|
{
|
2022-04-28 11:37:40 +08:00
|
|
|
|
"name": "lower",
|
2022-01-18 15:38:48 +08:00
|
|
|
|
"type": "input-text",
|
2022-04-28 11:37:40 +08:00
|
|
|
|
"label": "转换小写",
|
2022-01-18 15:38:48 +08:00
|
|
|
|
"placeholder": "输入的英文自动转为小写",
|
|
|
|
|
"transform": {
|
|
|
|
|
"lowerCase": true
|
2022-04-28 11:37:40 +08:00
|
|
|
|
},
|
|
|
|
|
"multiple": true,
|
|
|
|
|
"options": ["APPLE", "ORANGE", "WATERMELON"],
|
2022-01-18 15:38:48 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2022-04-28 11:37:40 +08:00
|
|
|
|
"name": "upper",
|
2022-01-18 15:38:48 +08:00
|
|
|
|
"type": "input-text",
|
2022-04-28 11:37:40 +08:00
|
|
|
|
"label": "转换大写",
|
2022-01-18 15:38:48 +08:00
|
|
|
|
"placeholder": "输入的英文自动转为大写",
|
|
|
|
|
"transform": {
|
|
|
|
|
"upperCase": true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-10-24 14:20:05 +08:00
|
|
|
|
## 文本内容为空时去掉这个值
|
|
|
|
|
|
|
|
|
|
> 2.4.0 及以上版本
|
|
|
|
|
|
|
|
|
|
如果设置了 `"clearValueOnEmpty": true`,当输入框的值清空时,提交的表单项里就不会有这个值
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"name": "text",
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"label": "内容为空时清理这个表单项",
|
|
|
|
|
"value": "v",
|
|
|
|
|
"clearValueOnEmpty": true
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-17 20:19:05 +08:00
|
|
|
|
## 自动补全
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"name": "name",
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"label": "自动补全",
|
|
|
|
|
"autoComplete": "/api/mock2/options/autoComplete?term=$term",
|
|
|
|
|
"placeholder": "请输入",
|
|
|
|
|
"multiple": true
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 属性表
|
|
|
|
|
|
|
|
|
|
当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
|
|
|
|
|
2022-07-11 17:01:19 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| --------------------- | ----------------------------------------- | --------- | ------------------------------------------------------------------------------------------- |
|
|
|
|
|
| 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` | | 是否去除首尾空白文本。 |
|
2022-10-24 14:20:05 +08:00
|
|
|
|
| clearValueOnEmpty | `boolean` | | 文本内容为空时去掉这个值 |
|
2022-07-11 17:01:19 +08:00
|
|
|
|
| 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 类名 |
|
2023-10-24 14:28:48 +08:00
|
|
|
|
| nativeAutoComplete | `string` | `off` | 原生 input 标签的 `autoComplete` 属性,比如配置集成 `new-password` |
|
2022-03-16 20:50:59 +08:00
|
|
|
|
|
|
|
|
|
## 事件表
|
|
|
|
|
|
2023-05-28 22:26:48 +08:00
|
|
|
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,在`actions`中可以通过`${事件参数名}`或`${event.data.[事件参数名]}`来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
2022-10-12 15:09:03 +08:00
|
|
|
|
|
|
|
|
|
> `[name]`表示当前组件绑定的名称,即`name`属性,如果没有配置`name`属性,则通过`value`取值。
|
|
|
|
|
|
|
|
|
|
| 事件名称 | 事件参数 | 说明 |
|
|
|
|
|
| -------- | ------------------------- | ---------------------------------------------- |
|
|
|
|
|
| click | `[name]: string` 组件的值 | 点击输入框时触发,只针对选择器模式的输入框有效 |
|
|
|
|
|
| enter | `[name]: string` 组件的值 | 回车时触发,只针对选择器模式的输入框有效 |
|
|
|
|
|
| focus | `[name]: string` 组件的值 | 输入框获取焦点时触发 |
|
|
|
|
|
| blur | `[name]: string` 组件的值 | 输入框失去焦点时触发 |
|
|
|
|
|
| change | `[name]: string` 组件的值 | 值变化时触发 |
|
2023-09-04 11:53:46 +08:00
|
|
|
|
| clear | `[name]: string` 组件的值 | 点击清除按钮时触发 |
|
2022-03-16 20:50:59 +08:00
|
|
|
|
|
2023-12-28 18:28:33 +08:00
|
|
|
|
### 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}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-16 20:50:59 +08:00
|
|
|
|
## 动作表
|
|
|
|
|
|
2022-05-31 15:05:54 +08:00
|
|
|
|
当前组件对外暴露以下特性动作,其他组件可以通过指定`actionType: 动作名称`、`componentId: 该组件id`来触发这些动作,动作配置可以通过`args: {动作配置项名称: xxx}`来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
|
|
|
|
|
2022-04-26 21:12:00 +08:00
|
|
|
|
| 动作名称 | 动作配置 | 说明 |
|
|
|
|
|
| -------- | ------------------------ | -------------------------------------------------- |
|
|
|
|
|
| clear | - | 清空 |
|
|
|
|
|
| reset | - | 重置 |
|
|
|
|
|
| focus | - | 获取焦点 |
|
|
|
|
|
| reload | - | 刷新(重新加载),只针对配置了`source`的输入框有效 |
|
|
|
|
|
| setValue | `value: string` 更新的值 | 更新数据,开启`multiple`多选时用`,`分隔 |
|
2024-04-26 20:48:27 +08:00
|
|
|
|
|
|
|
|
|
### 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!"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|