2022-03-15 13:40:02 +08:00
|
|
|
|
---
|
|
|
|
|
title: 事件动作
|
|
|
|
|
description: 事件动作
|
|
|
|
|
type: 0
|
|
|
|
|
group: 💡 概念
|
|
|
|
|
menuName: 事件动作
|
|
|
|
|
icon:
|
|
|
|
|
order: 9
|
|
|
|
|
---
|
|
|
|
|
|
2022-03-15 16:17:01 +08:00
|
|
|
|
> 1.7.0 及以上版本
|
|
|
|
|
|
2022-03-15 13:40:02 +08:00
|
|
|
|
上一节我们介绍了如何实现联动,是比较基础和局限的,而事件动作是更简单、更灵活、更高级的用法,可以解决复杂的 UI 交互场景,支持渲染器事件监听和响应设计,无需关心组件层级关系。例如:
|
|
|
|
|
|
|
|
|
|
- 传递数据
|
|
|
|
|
- 点击「按钮」,发送一个远程请求,返回的数据回填给一个表单
|
|
|
|
|
- 弹窗提交后,将弹窗内表单数据回填给另一个表单
|
|
|
|
|
- 联动刷新
|
|
|
|
|
- 下拉选择不同项,联动刷新表单数据
|
|
|
|
|
- 状态控制
|
|
|
|
|
- 勾选不同按钮,控制相应组件的显示/隐藏
|
|
|
|
|
- 勾选不同按钮,控制相应组件的启用/禁用
|
|
|
|
|
- 多个组件监听同一个事件做出不同响应
|
|
|
|
|
- 下拉选择不同项,组件 A 监听后发送一个远程请求,组件 B 监听后进行刷新
|
|
|
|
|
- 逻辑编排
|
|
|
|
|
- 针对监听到的事件,循环执行一些动作作为响应,还可以控制循环跳出或跳过
|
|
|
|
|
- 针对监听到的事件,根据条件选择性的执行动作响应
|
|
|
|
|
- 针对监听到的事件,并行执行多个动作作为响应
|
2022-03-30 21:30:20 +08:00
|
|
|
|
- 执行完当前动作后,可以选择是否继续执行后续动作,是否关闭事件默认行为的执行
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
## 基本使用
|
|
|
|
|
|
|
|
|
|
通过`onEvent`属性实现渲染器事件与响应动作的绑定。`onEvent`内配置事件和动作映射关系,`actions`是事件对应的响应动作的集合。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
label: '尝试点击、鼠标移入/移出',
|
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '派发点击事件'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
mouseenter: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '派发鼠标移入事件'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
mouseleave: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '派发鼠标移出事件'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## 事件与动作
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
事件包含`渲染器事件`和`广播事件`。
|
|
|
|
|
|
|
|
|
|
- 渲染器事件,由具体的渲染器组件提供,每个渲染器组件暴露的事件可以查看具体的[组件文档](./components/page);
|
|
|
|
|
- 广播事件,即自定义事件,可以自定义派发的事件名称`eventName`,其他渲染器可以监听该自定义事件并配置响应动作。
|
|
|
|
|
|
|
|
|
|
动作包含`通用动作`、`组件动作`、`广播动作`、`自定义动作`,可以通过配置`actionType`来指定具体执行什么动作。
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## 触发通用动作
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通用动作包含发送 http 请求、跳转链接、打开/关闭弹窗、打开/关闭抽屉、打开对话框、弹出 Toast 提示、刷新、控制显示隐藏、控制启用禁用状态。
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 发送 http 请求
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
通过配置`actionType: 'ajax'`和`api`实现 http 请求发送。如果是`post`请求,args 中的附加参数将作为请求参数。
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
data: {
|
|
|
|
|
name: 'lll'
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
id: 'b_001',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
label: '发送 Ajax 请求',
|
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'ajax',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
api: {
|
|
|
|
|
url: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/saveForm?name=${name}',
|
|
|
|
|
method: 'get'
|
|
|
|
|
},
|
|
|
|
|
messages: {
|
|
|
|
|
success: '成功了!欧耶',
|
|
|
|
|
failed: '失败了呢。。'
|
|
|
|
|
},
|
|
|
|
|
age: 18
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ------------------------------------ | ----------------------------------- | ------ | ------------------------- |
|
|
|
|
|
| actionType | `string` | `ajax` | ajax 请求 |
|
|
|
|
|
| api / args.api`(>=v1.9.0)` | [API](../../../docs/types/api) | - | 接口配置 |
|
|
|
|
|
| options / args.options`(>=v1.9.0)` | `object` | - | 其他配置 |
|
|
|
|
|
| messages / args.messages`(>=v1.9.0)` | `{success: string, failed: string}` | - | 请求成功/失败后的提示信息 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 打开弹窗(模态)
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'dialog'`和`dialog`实现 Dialog 弹窗。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
className: 'ml-2',
|
|
|
|
|
label: '打开弹窗(模态)',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'dialog',
|
|
|
|
|
dialog: {
|
|
|
|
|
type: 'dialog',
|
|
|
|
|
title: '模态弹窗',
|
2022-04-13 18:28:08 +08:00
|
|
|
|
id: 'dialog_001',
|
|
|
|
|
data: {
|
2022-04-14 19:13:35 +08:00
|
|
|
|
myage: '22'
|
2022-04-13 18:28:08 +08:00
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'tpl',
|
|
|
|
|
tpl: '<p>对,你打开了模态弹窗</p>',
|
|
|
|
|
inline: false
|
2022-03-29 17:46:24 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
name: 'myname',
|
2022-04-13 18:28:08 +08:00
|
|
|
|
mode: 'horizontal',
|
|
|
|
|
onEvent: {
|
|
|
|
|
change: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'confirm',
|
|
|
|
|
componentId: 'dialog_001'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
2022-03-29 17:46:24 +08:00
|
|
|
|
],
|
|
|
|
|
onEvent: {
|
|
|
|
|
confirm: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
msg: 'confirm'
|
|
|
|
|
}
|
|
|
|
|
]
|
2022-04-13 18:28:08 +08:00
|
|
|
|
},
|
|
|
|
|
cancel: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
msg: 'cancel'
|
|
|
|
|
}
|
|
|
|
|
]
|
2022-03-29 17:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | ----------------------- | -------- | ------------------------------------------ |
|
|
|
|
|
| actionType | `string` | `dialog` | 点击后显示一个弹出框 |
|
|
|
|
|
| dialog | `string`/`DialogObject` | - | 指定弹框内容,格式可参考[Dialog](./dialog) |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 关闭弹窗(模态)
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'closeDialog'`实现关闭当前弹窗;附加配置`componentId`可以实现关闭指定弹窗。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
id: 'b_003',
|
|
|
|
|
label: '打开弹窗(模态)',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'dialog',
|
|
|
|
|
dialog: {
|
|
|
|
|
type: 'dialog',
|
2022-04-13 18:28:08 +08:00
|
|
|
|
id: 'dialog_002',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
title: '模态弹窗',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '打开子弹窗,然后关闭它的父亲',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'dialog',
|
|
|
|
|
dialog: {
|
|
|
|
|
type: 'dialog',
|
|
|
|
|
title: '模态子弹窗',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '关闭指定弹窗(关闭父弹窗)',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'closeDialog',
|
2022-04-13 18:28:08 +08:00
|
|
|
|
componentId: 'dialog_002'
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '关闭当前弹窗',
|
|
|
|
|
className: 'ml-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'closeDialog'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ----------- | -------- | ------------- | --------------- |
|
|
|
|
|
| actionType | `string` | `closeDialog` | 关闭弹窗 |
|
|
|
|
|
| componentId | `string` | - | 指定弹框组件 id |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 打开抽屉(模态)
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'drawer'`和`drawer`实现 Drawer 抽屉打开。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
id: 'b_004',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
label: '打开抽屉(模态)',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'drawer',
|
|
|
|
|
drawer: {
|
|
|
|
|
type: 'drawer',
|
|
|
|
|
title: '模态抽屉',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'tpl',
|
|
|
|
|
tpl: '<p>对,你打开了模态抽屉</p>',
|
|
|
|
|
inline: false
|
|
|
|
|
}
|
2022-04-13 18:28:08 +08:00
|
|
|
|
],
|
|
|
|
|
onEvent: {
|
|
|
|
|
confirm: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
msg: 'confirm'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
cancel: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
msg: 'cancel'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | ----------------------- | -------- | ------------------------------------------ |
|
|
|
|
|
| actionType | `string` | `drawer` | 点击后显示一个侧边栏 |
|
|
|
|
|
| drawer | `string`/`DrawerObject` | - | 指定弹框内容,格式可参考[Drawer](./drawer) |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 关闭抽屉(模态)
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'closeDrawer'`实现关闭当前抽屉;附加配置`componentId`可以实现关闭指定抽屉。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '打开抽屉(模态)',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'drawer',
|
|
|
|
|
drawer: {
|
|
|
|
|
type: 'drawer',
|
|
|
|
|
id: 'drawer_1',
|
|
|
|
|
title: '模态抽屉',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '打开子抽屉,然后关闭它的父亲',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'drawer',
|
|
|
|
|
drawer: {
|
|
|
|
|
type: 'drawer',
|
|
|
|
|
title: '模态子抽屉',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '关闭指定抽屉(关闭父抽屉)',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'closeDrawer',
|
|
|
|
|
componentId: 'drawer_1'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '关闭当前抽屉',
|
|
|
|
|
className: 'ml-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'closeDrawer'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ----------- | -------- | ------------- | --------------- |
|
|
|
|
|
| actionType | `string` | `closeDrawer` | 关闭抽屉 |
|
|
|
|
|
| componentId | `string` | - | 指定抽屉组件 id |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 打开对话框
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'alert'`或`actionType: 'confirm'`打开不同对话框。
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
#### 提示对话框
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
data: {
|
|
|
|
|
msg: '去吃饭了'
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '提示对话框(模态)',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'alert',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msg: '<a href="http://www.baidu.com" target="_blank">${msg}~</a>'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| --------------------------- | -------- | ------- | -------------- |
|
|
|
|
|
| actionType | `string` | `alert` | 打开提示对话框 |
|
|
|
|
|
| msg / args.msg`(>=v1.9.0) ` | `string` | - | 对话框提示内容 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
#### 确认对话框
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
data: {
|
|
|
|
|
title: '操作确认',
|
|
|
|
|
msg: '要删除它吗?'
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '确认对话框(模态)',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
2022-04-13 18:28:08 +08:00
|
|
|
|
actionType: 'confirmDialog',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
title: '${title}',
|
|
|
|
|
msg: '<span style="color:red">${msg}</span>'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ------------------------------ | -------- | --------------- | -------------- |
|
|
|
|
|
| actionType | `string` | `confirmDialog` | 打开确认对话框 |
|
|
|
|
|
| title / args.title`(>=v1.9.0)` | `string` | - | 对话框标题 |
|
|
|
|
|
| msg / args.msg `(>=v1.9.0)` | `string` | - | 对话框提示内容 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 跳转链接
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'url'`或`actionType: 'link'`实现链接跳转。
|
|
|
|
|
|
|
|
|
|
**打开页面链接**
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
2022-04-13 18:28:08 +08:00
|
|
|
|
data: {
|
2022-04-20 15:20:42 +08:00
|
|
|
|
myname: 'lvxj',
|
|
|
|
|
myjon: 'player'
|
2022-04-13 18:28:08 +08:00
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '百度一下',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
className: 'ml-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'url',
|
2022-04-14 21:16:03 +08:00
|
|
|
|
args: {
|
2022-04-20 15:20:42 +08:00
|
|
|
|
url: 'http://www.baidu.com',
|
|
|
|
|
blank: true,
|
|
|
|
|
params: {
|
|
|
|
|
name: 'jack',
|
|
|
|
|
jon: '${myjon}'
|
|
|
|
|
},
|
2022-04-14 21:16:03 +08:00
|
|
|
|
name: '${myname}',
|
|
|
|
|
age: 18
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ------------------------------ | --------- | ------- | ------------------------------------------------ |
|
|
|
|
|
| actionType | `string` | `url` | 页面跳转 |
|
|
|
|
|
| url / args.url`(>=v1.9.0)` | `string` | - | 按钮点击后,会打开指定页面。可用 `${xxx}` 取值。 |
|
|
|
|
|
| blank / args.blank`(>=v1.9.0)` | `boolean` | `false` | 如果为 `true` 将在新 tab 页面打开。 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
**打开单页链接**
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
label: '跳转至「表达式」',
|
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
className: 'ml-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'link',
|
|
|
|
|
link: './expression'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | -------- | ------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
|
|
|
| actionType | `string` | `link` | 单页跳转 |
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| link / args.link`(>=v1.9.0)` | `string` | `link` | 用来指定跳转地址,跟 url 不同的是,这是单页跳转方式,不会渲染浏览器,请指定 amis 平台内的页面。可用 `${xxx}` 取值。 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 浏览器回退
|
2022-03-21 14:14:08 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'goBack'`实现页面回退。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '回退',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-21 14:14:08 +08:00
|
|
|
|
className: 'ml-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'goBack'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | -------- | -------- | ------------ |
|
|
|
|
|
| actionType | `string` | `goBack` | 返回上个页面 |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 前进/后退到指定页面
|
2022-03-21 14:14:08 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'goPage'`实现浏览器页面的前进/后退。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '后退到上上个页面',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-21 14:14:08 +08:00
|
|
|
|
className: 'ml-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'goPage',
|
|
|
|
|
delta: -2
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ------------------------------ | -------- | -------- | --------------- |
|
|
|
|
|
| actionType | `string` | `goPage` | 前进/后退到页面 |
|
|
|
|
|
| delta / args.delta`(>=v1.9.0)` | `string` | `0` | 位置 |
|
2022-03-21 14:14:08 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 浏览器刷新
|
2022-03-21 14:14:08 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'refresh'`实现浏览器刷新。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '刷新页面',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-21 14:14:08 +08:00
|
|
|
|
className: 'ml-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'refresh'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | -------- | --------- | ------------ |
|
|
|
|
|
| actionType | `string` | `refresh` | 返回上个页面 |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### toast 提示
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'toast'`和`msg`实现弹出 toast
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '警告',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'warning',
|
|
|
|
|
className: 'mr-2 mb-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'warning',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '成功',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'success',
|
|
|
|
|
className: 'mr-2 mb-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'success',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '错误',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'danger',
|
|
|
|
|
className: 'mr-2 mb-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'error',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '提示',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'info',
|
|
|
|
|
className: 'mb-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'tpl',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
tpl: '<br>',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '左上',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mr-2 mt-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'top-left'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '中上',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mr-2 mt-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'top-center'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '右上',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mt-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-04-14 14:18:27 +08:00
|
|
|
|
{
|
|
|
|
|
type: 'tpl',
|
|
|
|
|
tpl: '<br>',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '屏幕的中央',
|
|
|
|
|
className: 'ml-10 mt-2 mb-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'center'
|
|
|
|
|
}
|
2022-04-14 14:18:27 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'tpl',
|
|
|
|
|
tpl: '<br>',
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '左下',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mr-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'bottom-left'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '中下',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mr-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'bottom-center'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '右下',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
|
|
|
|
position: 'bottom-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ------------------------------------------ | --------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
|
|
|
| actionType | `string` | `"toast"` | 指定 toast 动作 |
|
|
|
|
|
| msgType / args.msgType`(>=v1.9.0)` | `string` | `"info"` | 消息类型 `"info"、"success"、"error"、"warning"` |
|
|
|
|
|
| msg / args.msg`(>=v1.9.0)` | `string` | - | 消息内容 |
|
|
|
|
|
| position / args.position`(>=v1.9.0)` | `string` | `top-center(移动端为center)` | 提示显示位置,可用'top-right'、'top-center'、'top-left'、'bottom-center'、'bottom-left'、'bottom-right'、'center' |
|
|
|
|
|
| closeButton / args.closeButton`(>=v1.9.0)` | `boolean` | `false` | 是否展示关闭按钮 |
|
|
|
|
|
| showIcon / args.showIcon`(>=v1.9.0)` | `boolean` | `true` | 是否展示图标 |
|
|
|
|
|
| timeout / args.timeout`(>=v1.9.0)` | `number` | `5000(error类型为6000,移动端为3000)` | 持续时间 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 复制
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-04-14 14:18:27 +08:00
|
|
|
|
通过配置`actionType: 'copy'`和复制属性实现文本的复制操作,该动作需实现 env.copy(contents: string, options?: any) => void 方法。
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '复制一段文本',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
|
|
|
|
className: 'mr-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'copy',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
content: 'http://www.baidu.com'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '复制一段富文本',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'copy',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
ormat: 'text/html',
|
|
|
|
|
content: "<a href='http://www.baidu.com'>link</a> <b>bold</b>"
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------------------------------------- | ------------------------------------ | ----------- | ------------------------------------ |
|
|
|
|
|
| actionType | `string` | `copy` | 复制一段内容到粘贴板 |
|
|
|
|
|
| copyFormat / args.copyFormat`(>=v1.9.0)` | `string` | `text/html` | 复制格式 |
|
|
|
|
|
| content / args.content`(>=v1.9.0)` | [模板](../../docs/concepts/template) | - | 指定复制的内容。可用 `${xxx}` 取值。 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 发送邮件
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'email'`和邮件属性实现发送邮件操作。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '发送邮件',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'email',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
to: 'amis@baidu.com',
|
|
|
|
|
cc: 'baidu@baidu.com',
|
|
|
|
|
subject: '这是邮件主题',
|
|
|
|
|
body: '这是邮件正文'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------------------------------- | -------- | ------- | -------------------------------- |
|
|
|
|
|
| actionType | `string` | `email` | 点击后显示一个弹出框 |
|
|
|
|
|
| to / args.to`(>=v1.9.0)` | `string` | - | 收件人邮箱,可用 ${xxx} 取值。 |
|
|
|
|
|
| cc / args.cc`(>=v1.9.0)` | `string` | - | 抄送邮箱,可用 ${xxx} 取值。 |
|
|
|
|
|
| bcc / args.bcc`(>=v1.9.0)` | `string` | - | 匿名抄送邮箱,可用 ${xxx} 取值。 |
|
|
|
|
|
| subject / args.subject`(>=v1.9.0)` | `string` | - | 邮件主题,可用 ${xxx} 取值。 |
|
|
|
|
|
| body / args.body`(>=v1.9.0)` | `string` | - | 邮件正文,可用 ${xxx} 取值。 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 刷新
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-30 21:30:20 +08:00
|
|
|
|
通过配置`actionType: 'reload'`实现对指定组件的刷新操作,限于`form`、`dialog`、`drawer`、`wizard`、`service`、`page`、`app`、`chart`、`crud`,以及选择类组件。
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '刷新(表单)',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mr-2',
|
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'reload',
|
|
|
|
|
componentId: 'form-reload'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '刷新(下拉框)',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'reload',
|
|
|
|
|
componentId: 'select-reload'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '下拉框',
|
|
|
|
|
type: 'select',
|
|
|
|
|
id: 'select-reload',
|
|
|
|
|
mode: 'horizontal',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mt-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
name: 'select',
|
|
|
|
|
source:
|
|
|
|
|
'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/getOptions?waitSeconds=1'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
id: 'form-reload',
|
|
|
|
|
name: 'form-reload',
|
|
|
|
|
initApi:
|
|
|
|
|
'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/page/initData',
|
|
|
|
|
title: '表单',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
id: 'date-input-01',
|
|
|
|
|
name: 'date',
|
|
|
|
|
label: '时间戳'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-03-24 20:22:01 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ----------- | -------- | -------- | --------------------- |
|
|
|
|
|
| actionType | `string` | `reload` | 刷新组件 |
|
|
|
|
|
| componentId | `string` | - | 指定刷新的目标组件 id |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 显示与隐藏
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-04-08 11:32:52 +08:00
|
|
|
|
通过配置`actionType: 'show'`或`'hidden'`实现对指定组件的显示和隐藏,且显隐动作的控制高于组件显隐属性的设置。
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '显示',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
|
|
|
|
className: 'mr-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'show',
|
|
|
|
|
componentId: 'input-text_001'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '隐藏',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'hidden',
|
|
|
|
|
componentId: 'input-text_001'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '愿望',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mt-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
id: 'input-text_001',
|
2022-04-08 11:32:52 +08:00
|
|
|
|
mode: 'horizontal',
|
|
|
|
|
hidden: true
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-03-24 20:22:01 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ----------- | -------- | ------------------ | --------------------------- |
|
|
|
|
|
| actionType | `string` | `show` or `hidden` | 显示或隐藏组件 |
|
|
|
|
|
| componentId | `string` | - | 指定显示或隐藏的目标组件 id |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 控制状态
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-24 20:22:01 +08:00
|
|
|
|
通过配置`actionType: 'enabled'`或`actionType: 'disabled'`实现对指定组件的启用和禁用,限于数据输入类组件。
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
id: 'b_dis',
|
|
|
|
|
label: '禁用',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
|
|
|
|
className: 'mr-2 mb-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'disabled',
|
|
|
|
|
componentId: 'form_disable'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '启用',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
|
|
|
|
className: 'mb-2',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'enabled',
|
|
|
|
|
componentId: 'form_disable'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
id: 'form_disable',
|
|
|
|
|
title: '表单',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'group',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
className: 'ml-2',
|
|
|
|
|
label: '我的状态变了'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
className: 'ml-2',
|
|
|
|
|
label: '禁用上面的按钮',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'disabled',
|
|
|
|
|
componentId: 'b_dis'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
className: 'ml-2',
|
|
|
|
|
label: '启用用上面的按钮',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'enabled',
|
|
|
|
|
componentId: 'b_dis'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-03-24 20:22:01 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ----------- | -------- | ----------------------- | --------------------------- |
|
|
|
|
|
| actionType | `string` | `enabled` or `disabled` | 启用或禁用组件 |
|
|
|
|
|
| componentId | `string` | - | 指定启用或禁用的目标组件 id |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 更新数据
|
2022-03-24 20:22:01 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'setValue'`实现组件数据变量的更新,限于`form`、`dialog`、`drawer`、`wizard`、`service`、`page`、`app`、`chart`,以及数据输入类组件。
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
#### 更新 表单 数据
|
|
|
|
|
|
|
|
|
|
直接更新指定的表单组件的数据。
|
2022-03-24 20:22:01 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
data: {
|
|
|
|
|
globalData: {
|
|
|
|
|
myrole: '法官',
|
|
|
|
|
mymsg: '该吃饭了!'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '更新',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
|
|
|
|
className: 'mb-2',
|
2022-03-24 20:22:01 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
|
|
|
|
componentId: 'form_data',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: '${globalData}'
|
|
|
|
|
}
|
2022-03-24 20:22:01 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
id: 'form_data',
|
|
|
|
|
title: '表单',
|
|
|
|
|
debug: true,
|
|
|
|
|
data: {
|
|
|
|
|
myrole: '预言家',
|
|
|
|
|
age: '18'
|
|
|
|
|
},
|
|
|
|
|
"initApi": "/api/mock2/form/initData",
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '角色',
|
|
|
|
|
name: 'myrole',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '年龄',
|
|
|
|
|
name: 'age',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
#### 更新 弹窗 数据
|
2022-03-24 20:22:01 +08:00
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
这种场景一般用在弹窗内某个异步操作后,数据的回填。请求返回的数据可以指定存储在`outputVar`变量里,其他动作可以通过`event.data.{{outputVar}}`直接获取该数据。
|
2022-03-24 20:22:01 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
data: {
|
|
|
|
|
globalData: {
|
|
|
|
|
website: "http://www.baidu.com",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
email: "amis!@baidu.com",
|
|
|
|
|
rememberMe: true
|
2022-03-24 20:22:01 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '打开弹窗',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-24 20:22:01 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'dialog',
|
|
|
|
|
"dialog": {
|
|
|
|
|
"title": "在弹框中的表单",
|
2022-04-13 18:28:08 +08:00
|
|
|
|
"id": "dialog_003",
|
2022-03-24 20:22:01 +08:00
|
|
|
|
"data": {
|
2022-04-20 15:20:42 +08:00
|
|
|
|
username: 'amis',
|
|
|
|
|
rememberMe: '${globalData.rememberMe}'
|
2022-03-24 20:22:01 +08:00
|
|
|
|
},
|
|
|
|
|
"body": {
|
|
|
|
|
"type": "form",
|
|
|
|
|
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/saveForm?waitSeconds=2",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"name": "username",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入用户名",
|
|
|
|
|
"label": "用户名"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "input-password",
|
|
|
|
|
"name": "password",
|
|
|
|
|
"label": "密码",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入密码"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "checkbox",
|
|
|
|
|
"name": "rememberMe",
|
|
|
|
|
"label": "记住登录"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '请求后更新',
|
|
|
|
|
className: 'm',
|
|
|
|
|
primary: true,
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'ajax',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
api: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/initData'
|
|
|
|
|
},
|
2022-03-24 20:22:01 +08:00
|
|
|
|
outputVar: 'myResult'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
2022-04-13 18:28:08 +08:00
|
|
|
|
componentId: 'dialog_003',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: {
|
|
|
|
|
username: '${event.data.myResult.name}'
|
|
|
|
|
}
|
2022-03-24 20:22:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
#### 更新 向导 数据
|
|
|
|
|
|
|
|
|
|
直接更新指定的向导组件的数据。
|
2022-03-24 20:22:01 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
data: {
|
|
|
|
|
globalData: {
|
|
|
|
|
website: "http://www.baidu.com",
|
|
|
|
|
email: "amis!@baidu.com"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '更新',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
|
|
|
|
className: 'mb-2',
|
2022-03-24 20:22:01 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
|
|
|
|
componentId: 'wizard_data',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: '${globalData}'
|
|
|
|
|
}
|
2022-03-24 20:22:01 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "wizard",
|
|
|
|
|
"id": "wizard_data",
|
|
|
|
|
"mode": "vertical",
|
|
|
|
|
"data": {
|
|
|
|
|
"website": "test",
|
|
|
|
|
"email": "test"
|
|
|
|
|
},
|
|
|
|
|
"steps": [
|
|
|
|
|
{
|
|
|
|
|
"title": "第一步",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"name": "website",
|
|
|
|
|
"label": "网址",
|
|
|
|
|
"type": "input-url"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"title": "Step 2",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"name": "email",
|
|
|
|
|
"label": "邮箱",
|
|
|
|
|
"type": "input-email",
|
|
|
|
|
"required": true
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
#### 更新 输入类组件 数据
|
|
|
|
|
|
|
|
|
|
直接更新指定输入框、下拉框等输入类组件的数据。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
id: 'mypage',
|
|
|
|
|
data: {
|
|
|
|
|
globalData: {
|
|
|
|
|
myrole: '法官',
|
|
|
|
|
mymsg: '该吃饭了!',
|
|
|
|
|
title: 'beijing time'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '更新',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
|
|
|
|
className: 'mr-2 mb-2',
|
2022-03-29 17:46:24 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
|
|
|
|
componentId: 'input_data_msg',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: '我是amis!'
|
|
|
|
|
}
|
2022-03-29 17:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '更新表单内输入框',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
|
|
|
|
className: 'mb-2',
|
2022-03-29 17:46:24 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
|
|
|
|
componentId: 'input_data_role',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: '预言家'
|
|
|
|
|
}
|
2022-03-29 17:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "input-text",
|
|
|
|
|
label: "消息",
|
|
|
|
|
id: "input_data_msg",
|
|
|
|
|
mode: 'horizontal',
|
|
|
|
|
name: "mymsg"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
title: '表单',
|
|
|
|
|
debug: true,
|
|
|
|
|
data: {
|
|
|
|
|
myrole: '杀手',
|
|
|
|
|
age: '18'
|
|
|
|
|
},
|
|
|
|
|
"initApi": "/api/mock2/form/initData",
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
id: "input_data_role",
|
|
|
|
|
label: '角色',
|
|
|
|
|
name: 'myrole',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '年龄',
|
|
|
|
|
name: 'age',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 联动更新
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
当某组件的值发生变化时,联动去更新另一个组件的数据,可以通过`${事件参数}`来获取事件产生的数据,例如输入框`change`事件的参数是`value: string | string[]`d,则可以通过`${event.data.value}`来获取输入的值。
|
2022-03-29 17:46:24 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '输入角色',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
mode: 'horizontal',
|
2022-03-29 17:46:24 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
change: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
|
|
|
|
componentId: 'form_data_2',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: {
|
|
|
|
|
myrole: '${event.data.value}'
|
|
|
|
|
}
|
2022-03-29 17:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '输入年龄',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
mode: 'horizontal',
|
2022-03-29 17:46:24 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
change: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
|
|
|
|
componentId: 'form_data_2',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: {
|
|
|
|
|
age: '${event.data.value}'
|
|
|
|
|
}
|
2022-03-29 17:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
id: 'form_data_2',
|
|
|
|
|
title: '表单',
|
|
|
|
|
debug: true,
|
|
|
|
|
"initApi": "/api/mock2/form/initData",
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '角色',
|
|
|
|
|
name: 'myrole',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '年龄',
|
|
|
|
|
name: 'age',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'select',
|
|
|
|
|
label: '选择消息',
|
|
|
|
|
name: 'message',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
mode: 'horizontal',
|
2022-03-29 17:46:24 +08:00
|
|
|
|
"options": [
|
|
|
|
|
{
|
|
|
|
|
"label": "Hi",
|
|
|
|
|
"value": "Hi!"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Hello",
|
|
|
|
|
"value": "Hello!"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Hey",
|
|
|
|
|
"value": "Hey!"
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
onEvent: {
|
|
|
|
|
change: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
|
|
|
|
componentId: 'input_data_msg2',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: '${event.data.value}'
|
|
|
|
|
}
|
2022-03-29 17:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "input-text",
|
|
|
|
|
label: "消息",
|
|
|
|
|
id: "input_data_msg2",
|
|
|
|
|
mode: 'horizontal',
|
|
|
|
|
name: "mymsg"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 数据回填
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
远程请求后、表单提交后,将数据回填给另一个组件。请求返回的数据可以指定存储在`outputVar`变量里,其他动作可以通过`event.data.{{outputVar}}`直接获取该数据。
|
2022-03-29 17:46:24 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
data: {
|
|
|
|
|
globalData: {
|
|
|
|
|
website: "http://www.baidu.com",
|
|
|
|
|
email: "amis!@baidu.com"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
id: 'form_data_3',
|
|
|
|
|
title: '表单',
|
|
|
|
|
debug: true,
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '名称',
|
|
|
|
|
name: 'name',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '作者',
|
|
|
|
|
name: 'author',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '去获取表单数据',
|
|
|
|
|
primary: true,
|
|
|
|
|
wrapWithPanel: false,
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'dialog',
|
|
|
|
|
"dialog": {
|
|
|
|
|
"title": "登录",
|
2022-04-13 18:28:08 +08:00
|
|
|
|
"id": "dialog_004",
|
2022-03-29 17:46:24 +08:00
|
|
|
|
"data": {
|
|
|
|
|
username: 'amis'
|
|
|
|
|
},
|
|
|
|
|
"body": {
|
|
|
|
|
"type": "form",
|
|
|
|
|
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/saveForm?waitSeconds=2",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"name": "username",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入用户名",
|
|
|
|
|
"label": "用户名"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "input-password",
|
|
|
|
|
"name": "password",
|
|
|
|
|
"label": "密码",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入密码"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "checkbox",
|
|
|
|
|
"name": "rememberMe",
|
|
|
|
|
"label": "记住登录"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '提交后回填表单',
|
|
|
|
|
className: 'm',
|
|
|
|
|
primary: true,
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'ajax',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
api: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/initData',
|
|
|
|
|
},
|
2022-03-29 17:46:24 +08:00
|
|
|
|
outputVar: 'myResult'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'setValue',
|
|
|
|
|
componentId: 'form_data_3',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
value: '${event.data.myResult}'
|
|
|
|
|
}
|
2022-03-29 17:46:24 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'closeDialog'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-24 20:22:01 +08:00
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ------------------------------ | -------- | ---------- | ---------------------------- |
|
|
|
|
|
| actionType | `string` | `setValue` | 变量赋值,即设置组件的数据值 |
|
|
|
|
|
| componentId | `string` | - | 指定赋值的目标组件 id |
|
|
|
|
|
| value / args.value`(>=v1.9.0)` | `any` | - | 值 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
### 自定义 JS
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'custom'`实现自定义 JS。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
label: '发送一个 http 请求',
|
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'custom',
|
|
|
|
|
script:
|
2022-04-20 15:20:42 +08:00
|
|
|
|
"doAction({actionType: 'ajax', args: {api: '/api/mock2/form/saveForm'}});\n //event.stopPropagation();"
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-04-14 19:13:35 +08:00
|
|
|
|
如果是在 js 中也能直接写函数,这个函数可以接收到 3 个参数,分别是:
|
|
|
|
|
|
|
|
|
|
- context,上下文信息
|
|
|
|
|
- doAction 方法,用于调用其它动作
|
|
|
|
|
- event,事件传递的数据,以及可以禁止
|
|
|
|
|
|
2022-03-15 13:40:02 +08:00
|
|
|
|
**动作属性**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | ------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
|
|
|
| actionType | `string` | `custom` | 自定义 JS |
|
|
|
|
|
| script | `string`/`function` | - | 自定义 JS 脚本代码,代码内可以通过调用`doAction`执行任何[动作](../../docs/concepts/event-action#动作) ,通过事件对象`event`可以实现事件动作干预 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## 触发其他组件的动作
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
通过配置`componentId`来触发指定组件的动作,组件动作参考通过`args`传入`(>=v1.9.0)`,动作参数请查看对应的组件文档。
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '选中选项卡2',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
className: 'mr-3 mb-3',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'changeActiveKey',
|
|
|
|
|
componentId: 'tabs-change-receiver',
|
2022-04-18 17:13:24 +08:00
|
|
|
|
args: {
|
|
|
|
|
activeKey: 1
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'tabs-change-receiver',
|
|
|
|
|
type: 'tabs',
|
|
|
|
|
mode: 'line',
|
|
|
|
|
tabs: [
|
|
|
|
|
{
|
|
|
|
|
title: '选项卡1',
|
|
|
|
|
body: '选项卡内容1'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '选项卡2',
|
|
|
|
|
body: '选项卡内容2'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '选项卡3',
|
|
|
|
|
body: '选项卡内容3'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## 触发广播动作
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'broadcast'`和`eventName`实现触发一个广播,可以通过配置动作执行优先级`weight`来控制所有监听者的动作执行顺序。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
"name": "role",
|
|
|
|
|
"type": "select",
|
|
|
|
|
"label": "广播一下",
|
|
|
|
|
"mode": "row",
|
|
|
|
|
"options": [
|
|
|
|
|
{
|
|
|
|
|
"label": "海贼王的男人",
|
|
|
|
|
"value": "路飞"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "海上华佗",
|
|
|
|
|
"value": "乔巴"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "海上食神",
|
|
|
|
|
"value": "山治"
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"onEvent": {
|
|
|
|
|
"change": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'broadcast',
|
|
|
|
|
eventName: 'broadcast_1',
|
|
|
|
|
args: {
|
|
|
|
|
myrole: '${role}',
|
|
|
|
|
age: 18
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
id: 'form_001_form_01',
|
|
|
|
|
title: '表单1(优先级低)',
|
|
|
|
|
name: 'sub-form1',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '昵称',
|
|
|
|
|
name: 'myname',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
onEvent: {
|
|
|
|
|
broadcast_1: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'reload',
|
|
|
|
|
args: {
|
|
|
|
|
myname: '${event.data.value}', // 从事件数据中取
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"actionType": "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
"msgType": "info",
|
|
|
|
|
"msg": "表单1刷新完成"
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
name: 'form2',
|
|
|
|
|
id: 'form_002',
|
|
|
|
|
title: '表单2(优先级中)',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '角色',
|
|
|
|
|
name: 'myrole',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
label: '年龄',
|
|
|
|
|
name: 'age',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
onEvent: {
|
|
|
|
|
broadcast_1: {
|
|
|
|
|
weight: 2,
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'reload',
|
|
|
|
|
args: {
|
|
|
|
|
myrole: '${event.data.value}',
|
|
|
|
|
age: '${event.data.age}'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"actionType": "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
"msgType": "info",
|
|
|
|
|
"msg": "表单2刷新完成"
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
name: 'form3',
|
|
|
|
|
id: 'form_003',
|
|
|
|
|
title: '表单3(优先级高)',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
id: 'form_003_text_01',
|
|
|
|
|
label: '职业',
|
|
|
|
|
name: 'job',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
api: 'https://api/form/form3',
|
|
|
|
|
onEvent: {
|
|
|
|
|
broadcast_1: {
|
|
|
|
|
weight: 3,
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'reload',
|
|
|
|
|
args: {
|
|
|
|
|
job: '${event.data.value}'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"actionType": "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
"msgType": "info",
|
|
|
|
|
"msg": "表单3刷新完成"
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | -------- | ----------- | ------------------------------------------------ |
|
|
|
|
|
| actionType | `string` | `broadcast` | 广播动作 |
|
2022-04-14 14:18:27 +08:00
|
|
|
|
| eventName | `string` | - | 广播动作对应的自定义事件名称,用于广播事件的监听 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## 自定义动作
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
补充中...
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
# 编排动作
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
通过配置`actionType: 'for'`或`actionType: 'break'`或`actionType: 'continue'`或`actionType: 'switch'`或`actionType: 'parallel'`实现动作的逻辑编排,支持嵌套。
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
## 条件
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: {
|
|
|
|
|
type: 'form',
|
|
|
|
|
wrapWithPanel: false,
|
|
|
|
|
data: {
|
|
|
|
|
expression: 'okk'
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '符合条件的执行',
|
|
|
|
|
level: 'primary',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
args: {
|
|
|
|
|
msgType: 'success',
|
|
|
|
|
msg: '我okk~'
|
|
|
|
|
},
|
|
|
|
|
expression: 'expression === "okk"'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
args: {
|
|
|
|
|
msg: '1'
|
|
|
|
|
},
|
|
|
|
|
expression: 'expression === "nono"'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
args: {
|
|
|
|
|
msgType: 'success',
|
|
|
|
|
msg: '我也okk~'
|
|
|
|
|
},
|
|
|
|
|
expression: 'expression === "okk"'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | -------------------------------- | ------ | ---------------------------- |
|
|
|
|
|
| actionType | `string` | `for` | 循环执行动作 |
|
|
|
|
|
| expression | [表达式](../concepts/expression) | - | 执行条件,不设置表示默认执行 |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## 循环
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
**单层循环**
|
|
|
|
|
|
2022-03-15 13:40:02 +08:00
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: {
|
|
|
|
|
type: 'form',
|
|
|
|
|
wrapWithPanel: false,
|
|
|
|
|
data: {
|
2022-04-20 15:20:42 +08:00
|
|
|
|
loopName: 'loopData',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
loopData: [
|
|
|
|
|
{
|
|
|
|
|
name: 'lv',
|
|
|
|
|
age: '19'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'xj',
|
|
|
|
|
age: '21'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '循环发送两次请求,且每次携带了循环的数据',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'loop',
|
|
|
|
|
args: {
|
2022-04-20 15:20:42 +08:00
|
|
|
|
level: 3,
|
|
|
|
|
loopName: '${loopName}'
|
2022-03-15 13:40:02 +08:00
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'ajax',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
api: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/saveForm?name=${name}&age=${age}'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**嵌套循环**
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: {
|
|
|
|
|
type: 'form',
|
|
|
|
|
wrapWithPanel: false,
|
|
|
|
|
data: {
|
|
|
|
|
loopName: 'loopData',
|
|
|
|
|
loopData: [
|
|
|
|
|
{
|
|
|
|
|
name: 'lv',
|
|
|
|
|
age: '19'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'xj',
|
|
|
|
|
age: '21'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '循环',
|
|
|
|
|
className: 'm-2',
|
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'loop',
|
|
|
|
|
preventDefault: false,
|
|
|
|
|
stopPropagation: false,
|
|
|
|
|
args: {
|
|
|
|
|
loopName: '${loopName}',
|
|
|
|
|
level: 3
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
args: {
|
|
|
|
|
msg: '第1层循环动作1${name}'
|
|
|
|
|
},
|
|
|
|
|
preventDefault: false,
|
|
|
|
|
stopPropagation: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
args: {
|
|
|
|
|
msg: '第1层循环动作2${name}'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'loop',
|
|
|
|
|
args: {
|
|
|
|
|
loopName: '${loopName}',
|
|
|
|
|
level: 3
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
args: {
|
|
|
|
|
msg: '第2层循环动作1${name}'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
args: {
|
|
|
|
|
msg: '第2层循环动作2${name}'
|
|
|
|
|
},
|
|
|
|
|
preventDefault: false,
|
|
|
|
|
stopPropagation: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'continue'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'toast',
|
|
|
|
|
args: {
|
|
|
|
|
msg: '第2层循环动作3${name}'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | ---------------------------------------------------- | ------ | ------------------------------------- |
|
|
|
|
|
| actionType | `string` | `for` | 循环执行动作 |
|
2022-04-14 14:18:27 +08:00
|
|
|
|
| loopName | `string` | - | 循环变量 |
|
2022-03-15 13:40:02 +08:00
|
|
|
|
| children | Array<[动作](../../docs/concepts/event-action#动作)> | - | 子动作,可以通过`break动作`来跳出循环 |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## Break 动作
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: {
|
|
|
|
|
type: 'form',
|
|
|
|
|
wrapWithPanel: false,
|
|
|
|
|
data: {
|
2022-04-20 15:20:42 +08:00
|
|
|
|
loopName: 'loopData',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
loopData: [
|
|
|
|
|
{
|
|
|
|
|
name: 'lv',
|
|
|
|
|
age: '19'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'xj',
|
|
|
|
|
age: '21'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '只执行了第一个动作就跳出了循环',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'loop',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
loopName: '${loopName}'
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
children: [
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'success',
|
|
|
|
|
msg: '第 1 个动作',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'break'
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'success',
|
|
|
|
|
msg: '第 2 个动作',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | -------- | ------- | ------------ |
|
|
|
|
|
| actionType | `string` | `break` | 跳出循环动作 |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## Continue 动作
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: {
|
|
|
|
|
type: 'form',
|
|
|
|
|
wrapWithPanel: false,
|
|
|
|
|
data: {
|
2022-04-20 15:20:42 +08:00
|
|
|
|
loopName: 'loopData',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
loopData: [
|
|
|
|
|
{
|
|
|
|
|
name: 'lv',
|
|
|
|
|
age: '19'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'xj',
|
|
|
|
|
age: '21'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '只循环执行第一个动作',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'loop',
|
|
|
|
|
args: {
|
2022-04-20 15:20:42 +08:00
|
|
|
|
loopName: '${loopName}',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
level: 3
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'success',
|
|
|
|
|
msg: '第 1 个动作',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'continue'
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'success',
|
|
|
|
|
msg: '最后的动作',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | -------- | ---------- | -------- |
|
|
|
|
|
| actionType | `string` | `continue` | 跳出当前 |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## 排他(switch)
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: {
|
|
|
|
|
type: 'form',
|
|
|
|
|
wrapWithPanel: false,
|
|
|
|
|
data: {
|
|
|
|
|
branchCont: 18
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '只执行动作2',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'switch',
|
|
|
|
|
children: [
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '动作1',
|
|
|
|
|
position: 'top-right',
|
|
|
|
|
expression: 'this.branchCont > 19'
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
stopPropagation: true // 这里无效,因为条件不成立
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '动作2',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
expression: 'this.branchCont > 17'
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'info',
|
|
|
|
|
msg: '动作3',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
expression: 'this.branchCont > 16'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | ---------------------------------------------------- | -------- | ------------------------------------------------------ |
|
|
|
|
|
| actionType | `string` | `switch` | 只执行第一个符合条件的动作 |
|
|
|
|
|
| children | Array<[动作](../../docs/concepts/event-action#动作)> | - | 子动作,每个子动作可以通过配置`expression`来匹配的条件 |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
## 并行
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: {
|
|
|
|
|
type: 'form',
|
|
|
|
|
wrapWithPanel: false,
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '同时执行动作1、2',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'parallel',
|
|
|
|
|
children: [
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "alert",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msg: '动作1'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2022-03-29 12:42:23 +08:00
|
|
|
|
actionType: "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
msgType: 'success',
|
|
|
|
|
msg: '动作2',
|
|
|
|
|
position: 'top-right'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**动作属性**
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| ---------- | ---------------------------------------------------- | ---------- | ------------------------------------------ |
|
|
|
|
|
| actionType | `string` | `parallel` | 点击后显示一个弹出框 |
|
|
|
|
|
| children | Array<[动作](../../docs/concepts/event-action#动作)> | - | 指定弹框内容,格式可参考[Dialog](./dialog) |
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
# 动作间数据传递
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
从事件触发开始,整个数据流包含事件本身产生的事件数据和动作产生的动作数据,事件源头产生的数据在 AMIS 事件动作机制底层已经自动加入渲染器数据域,可以通过`event.data.xxx`直接获取,而部分动作产生的数据如何流动需要交互设计者进行介入,对于数据流动可以通过数据映射,将上一个动作产生的数据作为动作参数写入下一个动作。
|
|
|
|
|
|
|
|
|
|
**传递数据**
|
|
|
|
|
|
|
|
|
|
通过 `args` 指定输入的参数数据,它是一个键值对。
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
id: 'b_001',
|
|
|
|
|
label: '发一个广播,携带动作参数',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
className: 'mb-2',
|
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'broadcast',
|
|
|
|
|
eventName: 'broadcast_1',
|
|
|
|
|
args: {
|
|
|
|
|
name: 'lvxj',
|
|
|
|
|
age: 18
|
|
|
|
|
},
|
|
|
|
|
description: '一个按钮的点击事件'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
name: 'form1',
|
|
|
|
|
id: 'form_001',
|
|
|
|
|
title: '接收广播事件的参数',
|
|
|
|
|
debug: true,
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-text',
|
|
|
|
|
id: 'form_001_text_01',
|
|
|
|
|
label: '年龄',
|
|
|
|
|
name: 'age',
|
|
|
|
|
disabled: false,
|
|
|
|
|
mode: 'horizontal'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
data: {
|
|
|
|
|
name: 'amis'
|
|
|
|
|
},
|
|
|
|
|
onEvent: {
|
|
|
|
|
broadcast_1: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'reload',
|
|
|
|
|
args: {
|
|
|
|
|
age: '${event.data.age}'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**存储异步请求返回的数据**
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
通过 `outputVar` 指定输出的变量名,其他动作可以通过`${event.data.{{outputVar}}}`来获取变量值,如果未指定 `outputVar` ,则直接存储到`event.data`。
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
type: 'page',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
label: '发送Ajax请求,并把返回数据传给弹窗',
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
onEvent: {
|
|
|
|
|
click: {
|
|
|
|
|
actions: [
|
|
|
|
|
{
|
|
|
|
|
actionType: 'ajax',
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
api: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/saveForm',
|
|
|
|
|
messages: {
|
|
|
|
|
success: '成功了!欧耶',
|
|
|
|
|
failed: '失败了呢。。'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
},
|
|
|
|
|
outputVar: 'ajax1'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
actionType: 'dialog',
|
|
|
|
|
args: {
|
|
|
|
|
id: '${event.data.ajax1.id}'
|
|
|
|
|
},
|
|
|
|
|
dialog: {
|
|
|
|
|
type: 'dialog',
|
2022-04-13 18:28:08 +08:00
|
|
|
|
id: 'dialog_005',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
title: '弹框标题1',
|
|
|
|
|
data: {
|
|
|
|
|
id: '${id}'
|
|
|
|
|
},
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'tpl',
|
|
|
|
|
tpl: '<p>请求返回的数据:id=${id}</p>',
|
|
|
|
|
inline: false
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
# 事件动作干预
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
事件动作干预是指执行完当前动作后,干预所监听事件默认处理逻辑和后续其他动作的执行。通过`preventDefault`、`stopPropagation`分别阻止监听事件默认行为和停止下一个动作执行。
|
|
|
|
|
|
|
|
|
|
**阻止事件默认行为**
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
"type": "page",
|
|
|
|
|
"title": "事件/动作干预",
|
|
|
|
|
"regions": [
|
|
|
|
|
"body",
|
|
|
|
|
"toolbar",
|
|
|
|
|
"header"
|
|
|
|
|
],
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "阻止弹窗",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
"actionType": "dialog",
|
|
|
|
|
"onEvent": {
|
|
|
|
|
"click": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"actionType": "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
"msgType": 'info',
|
|
|
|
|
"msg": '动作1',
|
|
|
|
|
"preventDefault": true
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**停止后续动作执行**
|
|
|
|
|
|
|
|
|
|
```schema
|
|
|
|
|
{
|
|
|
|
|
"type": "page",
|
|
|
|
|
"title": "事件/动作干预",
|
|
|
|
|
"regions": [
|
|
|
|
|
"body",
|
|
|
|
|
"toolbar",
|
|
|
|
|
"header"
|
|
|
|
|
],
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "停止执行动作3",
|
2022-04-14 14:18:27 +08:00
|
|
|
|
level: 'primary',
|
2022-03-15 13:40:02 +08:00
|
|
|
|
"onEvent": {
|
|
|
|
|
"click": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"actionType": "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
"msgType": 'info',
|
|
|
|
|
"msg": '动作1'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"actionType": "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
"msgType": 'info',
|
|
|
|
|
"msg": '动作2'
|
|
|
|
|
},
|
2022-03-15 13:40:02 +08:00
|
|
|
|
"stopPropagation": true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"actionType": "toast",
|
2022-04-20 15:20:42 +08:00
|
|
|
|
args: {
|
|
|
|
|
"msgType": 'info',
|
|
|
|
|
"msg": '动作3'
|
|
|
|
|
}
|
2022-03-15 13:40:02 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-29 17:46:24 +08:00
|
|
|
|
# 典型场景
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
|
|
|
|
补充中...
|
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
# 属性表
|
2022-03-15 13:40:02 +08:00
|
|
|
|
|
2022-04-20 15:20:42 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| --------------- | -------------------------------- | ------ | ----------------------------------- |
|
|
|
|
|
| actionType | `string` | - | 动作名称 |
|
|
|
|
|
| args | `object` | - | 动作参数`{key:value}`,支持数据映射 |
|
|
|
|
|
| preventDefault | `boolean` | false | 阻止事件默认行为 |
|
|
|
|
|
| stopPropagation | `boolean` | false | 停止后续动作执行 |
|
|
|
|
|
| expression | [表达式](../concepts/expression) | - | 执行条件,不设置表示默认执行 |
|
|
|
|
|
| outputVar | `string` | - | 输出数据变量名 |
|