mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(Dialog): option context support function (#5043)
This commit is contained in:
parent
ba064e5a71
commit
a8d5999d89
@ -1,6 +1,10 @@
|
|||||||
let queue: WechatMiniprogram.Component.TrivialInstance[] = [];
|
let queue: WechatMiniprogram.Component.TrivialInstance[] = [];
|
||||||
export type Action = 'confirm' | 'cancel' | 'overlay';
|
export type Action = 'confirm' | 'cancel' | 'overlay';
|
||||||
|
|
||||||
|
type DialogContext =
|
||||||
|
| WechatMiniprogram.Page.TrivialInstance
|
||||||
|
| WechatMiniprogram.Component.TrivialInstance;
|
||||||
|
|
||||||
interface DialogOptions {
|
interface DialogOptions {
|
||||||
lang?: string;
|
lang?: string;
|
||||||
show?: boolean;
|
show?: boolean;
|
||||||
@ -8,9 +12,7 @@ interface DialogOptions {
|
|||||||
width?: string | number | null;
|
width?: string | number | null;
|
||||||
zIndex?: number;
|
zIndex?: number;
|
||||||
theme?: string;
|
theme?: string;
|
||||||
context?:
|
context?: (() => DialogContext) | DialogContext;
|
||||||
| WechatMiniprogram.Page.TrivialInstance
|
|
||||||
| WechatMiniprogram.Component.TrivialInstance;
|
|
||||||
message?: string;
|
message?: string;
|
||||||
overlay?: boolean;
|
overlay?: boolean;
|
||||||
selector?: string;
|
selector?: string;
|
||||||
@ -79,7 +81,10 @@ const Dialog = (options: DialogOptions) => {
|
|||||||
|
|
||||||
return new Promise<WechatMiniprogram.Component.TrivialInstance>(
|
return new Promise<WechatMiniprogram.Component.TrivialInstance>(
|
||||||
(resolve, reject) => {
|
(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);
|
const dialog = context.selectComponent(options.selector as string);
|
||||||
|
|
||||||
delete options.context;
|
delete options.context;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user