2020-07-28 10:03:53 +08:00
|
|
|
|
---
|
|
|
|
|
title: Switch 开关
|
2021-01-07 23:35:03 +08:00
|
|
|
|
description:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
type: 0
|
|
|
|
|
group: null
|
|
|
|
|
menuName: Switch
|
2021-01-07 23:35:03 +08:00
|
|
|
|
icon:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
order: 51
|
|
|
|
|
---
|
2021-01-07 23:35:03 +08:00
|
|
|
|
|
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-07 10:09:55 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "switch",
|
|
|
|
|
"type": "switch",
|
|
|
|
|
"label": "开关",
|
|
|
|
|
"option": "开关说明"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 配置真假值
|
|
|
|
|
|
|
|
|
|
默认情况:
|
2021-01-07 23:35:03 +08:00
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
- 开关打开时,表单项值为:true
|
|
|
|
|
- 开关关闭时,表单项值为:false
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
2021-06-07 10:09:55 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "switch",
|
|
|
|
|
"type": "switch",
|
|
|
|
|
"label": "开关"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果你想调整这个值,可以配置`trueValue`和`falseValue`
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
2021-06-07 10:09:55 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "switch",
|
|
|
|
|
"type": "switch",
|
|
|
|
|
"label": "开关",
|
|
|
|
|
"trueValue": 1,
|
|
|
|
|
"falseValue": 0
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
调整开关,观察数据域变化,会发现打开后值为`1`,而关闭后为`0`
|
|
|
|
|
|
2021-03-14 16:07:37 +08:00
|
|
|
|
## 配置开启和关闭状态的文本
|
|
|
|
|
|
|
|
|
|
> 1.1.5 版本之后支持
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-06-07 10:09:55 +08:00
|
|
|
|
"body": [
|
2021-03-14 16:07:37 +08:00
|
|
|
|
{
|
|
|
|
|
"name": "switch",
|
|
|
|
|
"type": "switch",
|
|
|
|
|
"onText": "已开启飞行模式",
|
|
|
|
|
"offText": "已关闭飞行模式"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-03 14:31:35 +08:00
|
|
|
|
## 默认值
|
|
|
|
|
|
|
|
|
|
和其它表单项一样,如果要设置默认值,可以使用 value 属性
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"name": "switch",
|
|
|
|
|
"type": "switch",
|
|
|
|
|
"label": "开关",
|
|
|
|
|
"value": false
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 属性表
|
|
|
|
|
|
|
|
|
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
|
|
|
|
|
2022-03-03 14:31:35 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | --------------------------- | ------- | -------------------- |
|
|
|
|
|
| option | `string` | | 选项说明 |
|
|
|
|
|
| onText | `string / IconSchema` | | 开启时开关显示的内容 |
|
|
|
|
|
| offText | `string / IconSchema` | | 关闭时开关显示的内容 |
|
|
|
|
|
| trueValue | `boolean / string / number` | `true` | 标识真值 |
|
|
|
|
|
| falseValue | `boolean / string / number` | `false` | 标识假值 |
|
2022-02-24 10:10:50 +08:00
|
|
|
|
|
|
|
|
|
IconSchema 配置
|
2022-03-03 14:31:35 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
2022-02-24 10:10:50 +08:00
|
|
|
|
| ---------- | -------- | --------- | ------------ |
|
2022-03-03 14:31:35 +08:00
|
|
|
|
| type | `string` | | `icon` |
|
|
|
|
|
| icon | `string` | | icon 的类型 |
|
2022-03-16 20:48:29 +08:00
|
|
|
|
|
|
|
|
|
## 事件表
|
|
|
|
|
|
2022-04-26 21:12:00 +08:00
|
|
|
|
| 事件名称 | 事件参数 | 说明 |
|
|
|
|
|
| -------- | --------------------------------- | -------------------- |
|
|
|
|
|
| change | `value: string \| boolean` 值变化 | 开关值发生变化时触发 |
|
2022-03-16 20:48:29 +08:00
|
|
|
|
|
|
|
|
|
## 动作表
|
|
|
|
|
|
2022-04-26 21:12:00 +08:00
|
|
|
|
| 动作名称 | 动作配置 | 说明 |
|
|
|
|
|
| -------- | ------------------------------------- | -------- |
|
|
|
|
|
| setValue | `value: string \| boolean` 更新的数据 | 更新数据 |
|