mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(Dialog): add new prop context @rex-zsd (#912)
This commit is contained in:
parent
41d74319f9
commit
1fb41206e0
@ -137,6 +137,7 @@ Page({
|
||||
| overlay | 是否展示蒙层 | `Boolean` | `true` |
|
||||
| closeOnClickOverlay | 点击蒙层时是否关闭弹窗 | `Boolean` | `false` |
|
||||
| asyncClose | 是否异步关闭弹窗,开启后需要手动控制弹窗的关闭 | `Boolean` | `false` |
|
||||
| context | 选择器的选择范围,可以传入自定义组件的 this 作为上下文 | `Object` | 当前页面 |
|
||||
|
||||
### API
|
||||
|
||||
|
@ -5,6 +5,7 @@ type DialogOptions = {
|
||||
show?: boolean;
|
||||
title?: string;
|
||||
zIndex?: number;
|
||||
context?: any;
|
||||
message?: string;
|
||||
overlay?: boolean;
|
||||
selector?: string;
|
||||
@ -30,12 +31,15 @@ interface Dialog {
|
||||
currentOptions?: DialogOptions;
|
||||
}
|
||||
|
||||
function getContext() {
|
||||
const pages = getCurrentPages();
|
||||
return pages[pages.length - 1];
|
||||
}
|
||||
|
||||
const Dialog: Dialog = options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const pages = getCurrentPages();
|
||||
const ctx = pages[pages.length - 1];
|
||||
|
||||
const dialog = ctx.selectComponent(options.selector);
|
||||
const context = options.context || getContext();
|
||||
const dialog = context.selectComponent(options.selector);
|
||||
delete options.selector;
|
||||
|
||||
if (dialog) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user