feat(Dialog): option context support function (#5043)

This commit is contained in:
uxuip 2022-09-19 14:24:14 +08:00 committed by GitHub
parent ba064e5a71
commit a8d5999d89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,10 @@
let queue: WechatMiniprogram.Component.TrivialInstance[] = [];
export type Action = 'confirm' | 'cancel' | 'overlay';
type DialogContext =
| WechatMiniprogram.Page.TrivialInstance
| WechatMiniprogram.Component.TrivialInstance;
interface DialogOptions {
lang?: string;
show?: boolean;
@ -8,9 +12,7 @@ interface DialogOptions {
width?: string | number | null;
zIndex?: number;
theme?: string;
context?:
| WechatMiniprogram.Page.TrivialInstance
| WechatMiniprogram.Component.TrivialInstance;
context?: (() => DialogContext) | DialogContext;
message?: string;
overlay?: boolean;
selector?: string;
@ -79,7 +81,10 @@ const Dialog = (options: DialogOptions) => {
return new Promise<WechatMiniprogram.Component.TrivialInstance>(
(resolve, reject) => {
const context = options.context || getContext();
const context =
(typeof options.context === 'function'
? options.context()
: options.context) || getContext();
const dialog = context.selectComponent(options.selector as string);
delete options.context;