2020-07-28 10:03:53 +08:00
|
|
|
|
---
|
|
|
|
|
title: Drawer 抽屉
|
2020-07-29 16:20:21 +08:00
|
|
|
|
description:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
type: 0
|
|
|
|
|
group: ⚙ 组件
|
|
|
|
|
menuName: Drawer 抽屉
|
2020-07-29 16:20:21 +08:00
|
|
|
|
icon:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
order: 43
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 基本用法
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"label": "弹出",
|
|
|
|
|
"type": "button",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"title": "抽屉标题",
|
|
|
|
|
"body": "这是一个抽屉"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 多级弹框
|
|
|
|
|
|
|
|
|
|
可以嵌套使用。
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "多级抽屉",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "提示",
|
|
|
|
|
"body": "这是个简单的抽屉",
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"actionType": "confirm",
|
|
|
|
|
"label": "确认",
|
|
|
|
|
"primary": true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"label": "再弹一个",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "抽屉中的抽屉",
|
|
|
|
|
"body": "如果你想,可以继续弹下去",
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"label": "来吧",
|
|
|
|
|
"level": "info",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "抽屉中的抽屉",
|
|
|
|
|
"body": "如果你想,可以无限弹下去",
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"actionType": "confirm",
|
|
|
|
|
"label": "不弹了",
|
|
|
|
|
"primary": true
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2022-08-17 11:28:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
## 指定弹出方向
|
|
|
|
|
|
|
|
|
|
通过配置 `position`,可以指定抽屉弹出的方向,可选 `left`、`right`、`top` 和 `bottom`。默认为 `right`。
|
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": "button-toolbar",
|
|
|
|
|
"buttons": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "左侧弹出",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"position": "left",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个从左侧弹出的抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "右侧弹出",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"position": "right",
|
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个从右侧弹出的抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "顶部弹出",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"position": "top",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个从顶部弹出的抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "底部弹出",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"position": "bottom",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个从底部弹出的抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
}
|
2022-02-17 10:58:07 +08:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
2022-04-14 21:16:03 +08:00
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
## 抽屉尺寸
|
2022-04-14 21:16:03 +08:00
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
通过设置 `size` 来控制抽屉的大小,可选值:`xs`、`sm`、`md`、`lg` 和 `xl`。
|
2022-02-17 10:58:07 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "button-toolbar",
|
|
|
|
|
"buttons": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "极小框",
|
2022-02-17 10:58:07 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"size": "xs",
|
2022-02-17 10:58:07 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个极小的抽屉"
|
2022-02-17 10:58:07 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "小框",
|
2022-02-17 10:58:07 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"size": "sm",
|
2022-02-17 10:58:07 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个小抽屉"
|
2022-02-17 10:58:07 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "中框",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"size": "md",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个标准的抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "大框",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"size": "lg",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个大抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "超大框",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"size": "xl",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个超大的抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 自定义抽屉尺寸
|
|
|
|
|
|
|
|
|
|
通过设置 `width`(`position` 为 `left` 或 `right` 时生效)和 `height`(`position` 为 `top` 或 `bottom` 时生效)来控制抽屉的尺寸。
|
|
|
|
|
|
|
|
|
|
值如果是数字类型,单位默认使用 `px`, 如果是字符串类型,可以使用自定义 css 宽度变量,如:`%`、`vw`、`px` 等。
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "button-toolbar",
|
|
|
|
|
"buttons": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "自定义宽度",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"position": "right",
|
|
|
|
|
"width": 300,
|
|
|
|
|
"title": "提示",
|
|
|
|
|
"body": "这是一个自定义 300px 宽度的抽屉"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "自定义高度",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"position": "bottom",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"height": 300,
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个自定义 300px 高度的抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 可拖拽抽屉大小
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
配置 `"resizable": true`,可以拖拽调整 `drawer` 大小。
|
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": "button",
|
|
|
|
|
"label": "可拖拽调整大小",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"resizable": true,
|
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个可拖拽的抽屉"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-02-17 10:58:07 +08:00
|
|
|
|
## 是否展示关闭按钮
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
配置 `"showCloseButton": false`,可以隐藏关闭按钮。
|
2022-02-17 10:58:07 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "无关闭按钮",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个没有关闭按钮的抽屉",
|
2022-02-17 10:58:07 +08:00
|
|
|
|
"showCloseButton": false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
## 蒙层显示
|
2020-07-28 10:03:53 +08:00
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
通过配置 `overlay`,来控制是否显示蒙层。默认为 `true`。
|
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
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"type": "button-toolbar",
|
|
|
|
|
"buttons": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "默认",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"overlay": true,
|
|
|
|
|
"title": "提示",
|
|
|
|
|
"body": "这是一个有蒙层的抽屉"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "不显示",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"overlay": false,
|
|
|
|
|
"title": "提示",
|
|
|
|
|
"body": "这是一个没有蒙层的抽屉"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2020-07-28 10:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
## 关闭方式
|
2020-07-28 10:03:53 +08:00
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
通过配置 `closeOnOutside`,即可在点击抽屉外部时,直接关闭抽屉。
|
2020-07-28 10:03:53 +08:00
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
同时可以配置 `closeOnEsc`,让抽屉支持 <kbd>Esc</kbd> 键关闭。
|
2023-05-05 11:03:30 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"type": "button-toolbar",
|
|
|
|
|
"buttons": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "点击抽屉外自动关闭(有蒙层)",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"closeOnOutside": true,
|
|
|
|
|
"title": "提示",
|
|
|
|
|
"body": "这是一个简单的抽屉"
|
2023-05-05 11:03:30 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "点击抽屉外自动关闭(无蒙层)",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"overlay": false,
|
|
|
|
|
"closeOnOutside": true,
|
|
|
|
|
"title": "提示",
|
|
|
|
|
"body": "这是一个简单的抽屉"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "按键关闭",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"closeOnEsc": true,
|
|
|
|
|
"title": "提示",
|
|
|
|
|
"body": "试试按下 Esc"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-05-05 11:03:30 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
## 动作后关闭抽屉
|
2023-05-05 11:03:30 +08:00
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
在抽屉中配置行为按钮,可以在按钮上配置 `"close": true`,在行为完成后,关闭当前抽屉。
|
2023-05-05 11:03:30 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "打开",
|
2023-05-05 11:03:30 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"title": "提示",
|
2023-05-05 11:03:30 +08:00
|
|
|
|
"body": [
|
2023-08-07 17:00:33 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "button-toolbar",
|
|
|
|
|
"buttons": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "默认的 ajax 请求",
|
|
|
|
|
"actionType": "ajax",
|
|
|
|
|
"api": "/api/mock2/form/saveForm?waitSeconds=1"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "ajax 请求成功后关闭抽屉",
|
|
|
|
|
"actionType": "ajax",
|
|
|
|
|
"api": "/api/mock2/form/saveForm?waitSeconds=1",
|
|
|
|
|
"close": true
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-05-05 11:03:30 +08:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
以上例子是关闭当前抽屉,如果希望关闭上层抽屉,则需要给目标抽屉设置 `name` 属性,然后配置按钮 `close` 属性为目标 `name` 属性如:
|
2023-05-05 11:03:30 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "多级抽屉",
|
2023-05-05 11:03:30 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是个简单的抽屉",
|
2023-05-05 11:03:30 +08:00
|
|
|
|
"name": "drawer_1",
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"actionType": "confirm",
|
|
|
|
|
"label": "确认",
|
|
|
|
|
"primary": true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"label": "再弹一个",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"title": "抽屉中的抽屉",
|
|
|
|
|
"body": "关闭当前抽屉时,将外层抽屉一并关闭",
|
2023-05-05 11:03:30 +08:00
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "关闭所有",
|
|
|
|
|
"level": "info",
|
|
|
|
|
"close": "drawer_1"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-07-25 19:20:25 +08:00
|
|
|
|
> 3.3.0 及以上版本
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
如果是表单,可以在表单上配置 `close: false`。
|
2023-07-25 19:20:25 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "弹个框",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"type": "form",
|
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"name": "name",
|
|
|
|
|
"label": "姓名"
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"close": false
|
2023-07-25 19:20:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
## 配置抽屉的按钮
|
2023-05-05 11:03:30 +08:00
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
默认抽屉会自动生成两个按钮,一个取消,一个确认。如果通过 `actions` 来自定义配置,则以配置的为准。
|
2023-05-05 11:03:30 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "button-toolbar",
|
|
|
|
|
"buttons": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "无按钮",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-05-05 11:03:30 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "这是一个没有按钮的抽屉",
|
|
|
|
|
"actions": []
|
2023-05-05 11:03:30 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "一个按钮",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-05-05 11:03:30 +08:00
|
|
|
|
"title": "提示",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"body": "只有一个 OK 的抽屉",
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"actionType": "confirm",
|
|
|
|
|
"label": "OK",
|
|
|
|
|
"primary": true
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-05-05 11:03:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 属性表
|
|
|
|
|
|
2022-04-14 21:16:03 +08:00
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| --------------- | ----------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------- |
|
|
|
|
|
| type | `string` | | `"drawer"` 指定为 Drawer 渲染器 |
|
|
|
|
|
| title | [SchemaNode](../../docs/types/schemanode) | | 弹出层标题 |
|
|
|
|
|
| body | [SchemaNode](../../docs/types/schemanode) | | 往 Drawer 内容区加内容 |
|
|
|
|
|
| size | `string` | | 指定 Drawer 大小,支持: `xs`、`sm`、`md`、`lg`、`xl` |
|
2023-07-27 08:54:38 +08:00
|
|
|
|
| position | `string` | `right` | 指定 Drawer 方向,支持: `left`、`right`、`top`、`bottom` |
|
|
|
|
|
| className | `string` | | Drawer 最外层容器的样式类名 |
|
2022-02-17 10:58:07 +08:00
|
|
|
|
| headerClassName | `string` | | Drawer 头部 区域的样式类名 |
|
2022-04-14 21:16:03 +08:00
|
|
|
|
| bodyClassName | `string` | `modal-body` | Drawer body 区域的样式类名 |
|
2022-02-17 10:58:07 +08:00
|
|
|
|
| footerClassName | `string` | | Drawer 页脚 区域的样式类名 |
|
2023-08-07 17:00:33 +08:00
|
|
|
|
| showCloseButton | `boolean` | `true` | 是否展示关闭按钮,当值为 `false` 时,默认开启 closeOnOutside |
|
|
|
|
|
| closeOnEsc | `boolean` | `false` | 是否支持按 <kbd>Esc</kbd> 关闭 Drawer |
|
2022-04-14 21:16:03 +08:00
|
|
|
|
| closeOnOutside | `boolean` | `false` | 点击内容区外是否关闭 Drawer |
|
|
|
|
|
| overlay | `boolean` | `true` | 是否显示蒙层 |
|
|
|
|
|
| resizable | `boolean` | `false` | 是否可通过拖拽改变 Drawer 大小 |
|
2023-08-07 17:00:33 +08:00
|
|
|
|
| width | `string \| number` | `500px` | 容器的宽度,在 `position` 为 `left` 或 `right` 时生效 |
|
|
|
|
|
| height | `string \| number` | `500px` | 容器的高度,在 `position` 为 `top` 或 `bottom` 时生效 |
|
2022-04-14 21:16:03 +08:00
|
|
|
|
| actions | Array<[Action](./action)> | 【确认】和【取消】 | 可以不设置,默认只有两个按钮。 |
|
|
|
|
|
| data | `object` | | 支持 [数据映射](../../docs/concepts/data-mapping),如果不设定将默认将触发按钮的上下文中继承数据。 |
|
2022-04-13 18:28:08 +08:00
|
|
|
|
|
|
|
|
|
## 事件表
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
当前组件会对外派发以下事件,可以通过 `onEvent` 来监听这些事件,并通过 `actions` 来配置执行的动作,在 `actions` 中可以通过 `${事件参数名}` 或 `${event.data.[事件参数名]}` 来获取事件产生的数据,详细请查看[事件动作](../../docs/concepts/event-action)。
|
2022-05-31 15:05:54 +08:00
|
|
|
|
|
2022-10-12 15:09:03 +08:00
|
|
|
|
| 事件名称 | 事件参数 | 说明 |
|
|
|
|
|
| -------- | ------------------------------------------------------------------------ | ------------------ |
|
|
|
|
|
| confirm | `event.data: object` 抽屉数据<br/>`[name]: any` 当前数据域中指定字段的值 | 点击确认提交时触发 |
|
|
|
|
|
| cancel | `event.data: object` 抽屉数据<br/>`[name]: any` 当前数据域中指定字段的值 | 点击取消时触发 |
|
2022-04-13 18:28:08 +08:00
|
|
|
|
|
2023-05-28 22:26:48 +08:00
|
|
|
|
### confirm
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
[
|
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "打开",
|
2023-05-28 22:26:48 +08:00
|
|
|
|
"type": "button",
|
|
|
|
|
"onEvent": {
|
|
|
|
|
"click": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"title": "标题",
|
|
|
|
|
"body": "这是一个抽屉",
|
2023-05-28 22:26:48 +08:00
|
|
|
|
"onEvent": {
|
|
|
|
|
"confirm": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"actions": [
|
2023-05-28 22:26:48 +08:00
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"actionType": "toast",
|
|
|
|
|
"args": {
|
|
|
|
|
"msg": "confirm"
|
|
|
|
|
}
|
2023-05-28 22:26:48 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
2023-05-28 22:26:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### cancel
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
[
|
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"label": "打开",
|
2023-05-28 22:26:48 +08:00
|
|
|
|
"type": "button",
|
|
|
|
|
"onEvent": {
|
|
|
|
|
"click": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"title": "标题",
|
|
|
|
|
"body": "这是一个抽屉",
|
2023-05-28 22:26:48 +08:00
|
|
|
|
"onEvent": {
|
|
|
|
|
"cancel": {
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"actions": [
|
2023-05-28 22:26:48 +08:00
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"actionType": "toast",
|
|
|
|
|
"args": {
|
|
|
|
|
"msg": "cancel"
|
|
|
|
|
}
|
2023-05-28 22:26:48 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
2023-05-28 22:26:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
```
|
|
|
|
|
|
2022-04-13 18:28:08 +08:00
|
|
|
|
## 动作表
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
当前组件对外暴露以下特性动作,其他组件可以通过指定 `actionType: 动作名称`、`componentId: 该组件id` 来触发这些动作,动作配置可以通过 `args: {动作配置项名称: xxx}` 来配置具体的参数,详细请查看[事件动作](../../docs/concepts/event-action#触发其他组件的动作)。
|
2022-05-31 15:05:54 +08:00
|
|
|
|
|
2022-04-26 21:12:00 +08:00
|
|
|
|
| 动作名称 | 动作配置 | 说明 |
|
|
|
|
|
| -------- | -------------------------- | ------------ |
|
|
|
|
|
| confirm | - | 确认(提交) |
|
|
|
|
|
| cancel | - | 取消(关闭) |
|
|
|
|
|
| setValue | `value: object` 更新的数据 | 更新数据 |
|
2023-07-13 08:44:12 +08:00
|
|
|
|
|
|
|
|
|
### confirm 动作
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "弹个表单",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "在抽屉中的表单",
|
|
|
|
|
"id": "drawer_confirm",
|
|
|
|
|
"body": {
|
|
|
|
|
"type": "form",
|
|
|
|
|
"api": "/api/mock2/form/saveForm?waitSeconds=2",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"name": "username",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入用户名",
|
|
|
|
|
"label": "用户名"
|
2023-07-13 08:44:12 +08:00
|
|
|
|
},
|
2023-08-07 17:00:33 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "input-password",
|
|
|
|
|
"name": "password",
|
|
|
|
|
"label": "密码",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入密码"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "checkbox",
|
|
|
|
|
"name": "rememberMe",
|
|
|
|
|
"label": "记住登录"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "触发确认",
|
|
|
|
|
"onEvent": {
|
|
|
|
|
"click": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"actionType": "confirm",
|
|
|
|
|
"componentId": "drawer_confirm"
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### cancel 动作
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "弹个表单",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "在抽屉中的表单",
|
|
|
|
|
"id": "drawer_cancel",
|
|
|
|
|
"body": {
|
|
|
|
|
"type": "form",
|
|
|
|
|
"api": "/api/mock2/form/saveForm?waitSeconds=2",
|
|
|
|
|
"body": [
|
2023-07-13 08:44:12 +08:00
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"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": "触发取消",
|
|
|
|
|
"onEvent": {
|
|
|
|
|
"click": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"actionType": "cancel",
|
|
|
|
|
"componentId": "drawer_cancel"
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### setValue 动作
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
通过 `setValue` 更新指定抽屉的数据。
|
2023-07-13 08:44:12 +08:00
|
|
|
|
|
|
|
|
|
#### 合并数据
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
默认 `setValue` 会将新数据与目标组件数据进行合并。
|
2023-07-13 08:44:12 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "弹个表单",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "在抽屉中的表单",
|
|
|
|
|
"id": "drawer_setvalue",
|
|
|
|
|
"data": {
|
|
|
|
|
"username": "amis",
|
|
|
|
|
"password": "amis@baidu.com"
|
|
|
|
|
},
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "alert",
|
|
|
|
|
"body": "初始化时,抽屉的数据 data 为 {username: 'amis', password: 'fex'},表单内或者表单外都可以读取这些数据,当点击【更新抽屉数据】按钮后,抽屉的数据被更新为 {username: 'aisuda', password: 'aisuda@baidu.com'}"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"label": "表单外的密码",
|
|
|
|
|
"name": "password"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
|
|
|
|
"api": "/api/mock2/form/saveForm?waitSeconds=2",
|
2023-07-13 08:44:12 +08:00
|
|
|
|
"body": [
|
2023-08-07 17:00:33 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"name": "username",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入用户名",
|
|
|
|
|
"label": "用户名"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "input-password",
|
|
|
|
|
"name": "password",
|
|
|
|
|
"label": "密码",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入密码"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "更新抽屉数据",
|
|
|
|
|
"onEvent": {
|
|
|
|
|
"click": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"actionType": "setValue",
|
|
|
|
|
"componentId": "drawer_setvalue",
|
|
|
|
|
"args": {
|
|
|
|
|
"value": {
|
|
|
|
|
"username": "aisuda",
|
|
|
|
|
"password": "aisuda@baidu.com"
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
}
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 覆盖数据
|
|
|
|
|
|
2023-08-07 17:00:33 +08:00
|
|
|
|
可以通过 `"dataMergeMode": "override"` 来覆盖目标组件数据。
|
2023-07-13 08:44:12 +08:00
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "弹个表单",
|
|
|
|
|
"actionType": "drawer",
|
|
|
|
|
"drawer": {
|
|
|
|
|
"title": "在抽屉中的表单",
|
|
|
|
|
"id": "drawer_setvalue2",
|
|
|
|
|
"data": {
|
|
|
|
|
"username": "amis",
|
|
|
|
|
"password": "amis@baidu.com"
|
|
|
|
|
},
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "alert",
|
|
|
|
|
"body": "初始化时,抽屉的数据 data 为 {username: 'amis', password: 'fex'},表单内或者表单外都可以读取这些数据,当点击【更新抽屉数据】按钮后,抽屉的数据被更新为 {username: 'aisuda'},即 password 将被删除"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "input-text",
|
|
|
|
|
"label": "表单外的密码",
|
|
|
|
|
"name": "password"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
|
|
|
|
"api": "/api/mock2/form/saveForm?waitSeconds=2",
|
2023-07-13 08:44:12 +08:00
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "input-text",
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"name": "username",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入用户名",
|
|
|
|
|
"label": "用户名"
|
2023-07-13 08:44:12 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-07 17:00:33 +08:00
|
|
|
|
"type": "input-password",
|
|
|
|
|
"name": "password",
|
|
|
|
|
"label": "密码",
|
|
|
|
|
"required": true,
|
|
|
|
|
"placeholder": "请输入密码"
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"type": "button",
|
|
|
|
|
"label": "更新抽屉数据",
|
|
|
|
|
"onEvent": {
|
|
|
|
|
"click": {
|
|
|
|
|
"actions": [
|
|
|
|
|
{
|
|
|
|
|
"actionType": "setValue",
|
|
|
|
|
"componentId": "drawer_setvalue2",
|
|
|
|
|
"args": {
|
|
|
|
|
"value": {
|
|
|
|
|
"username": "aisuda"
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
},
|
|
|
|
|
"dataMergeMode": "override"
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
]
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
2023-08-07 17:00:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-07-13 08:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
```
|