mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
parent
9bdfd34487
commit
5f07067efd
@ -1,6 +1,5 @@
|
|||||||
let queue = [];
|
let queue = [];
|
||||||
|
|
||||||
type DialogAction = 'confirm' | 'cancel';
|
|
||||||
type DialogOptions = {
|
type DialogOptions = {
|
||||||
lang?: string;
|
lang?: string;
|
||||||
show?: boolean;
|
show?: boolean;
|
||||||
@ -36,27 +35,41 @@ type DialogOptions = {
|
|||||||
confirmButtonOpenType?: string;
|
confirmButtonOpenType?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Dialog {
|
const defaultOptions: DialogOptions = {
|
||||||
(options: DialogOptions): Promise<DialogAction>;
|
show: false,
|
||||||
alert?: (options: DialogOptions) => Promise<DialogAction>;
|
title: '',
|
||||||
confirm?: (options: DialogOptions) => Promise<DialogAction>;
|
width: null,
|
||||||
close?: () => void;
|
theme: 'default',
|
||||||
stopLoading?: () => void;
|
message: '',
|
||||||
install?: () => void;
|
zIndex: 100,
|
||||||
setDefaultOptions?: (options: DialogOptions) => void;
|
overlay: true,
|
||||||
resetDefaultOptions?: () => void;
|
selector: '#van-dialog',
|
||||||
defaultOptions?: DialogOptions;
|
className: '',
|
||||||
currentOptions?: DialogOptions;
|
asyncClose: false,
|
||||||
}
|
transition: 'scale',
|
||||||
|
customStyle: '',
|
||||||
|
messageAlign: '',
|
||||||
|
overlayStyle: '',
|
||||||
|
confirmButtonText: '确认',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
showConfirmButton: true,
|
||||||
|
showCancelButton: false,
|
||||||
|
closeOnClickOverlay: false,
|
||||||
|
confirmButtonOpenType: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
let currentOptions: DialogOptions = { ...defaultOptions };
|
||||||
|
|
||||||
function getContext() {
|
function getContext() {
|
||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
return pages[pages.length - 1];
|
return pages[pages.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Dialog: Dialog = (options) => {
|
const Dialog = (
|
||||||
|
options: DialogOptions
|
||||||
|
): Promise<WechatMiniprogram.Component.TrivialInstance> => {
|
||||||
options = {
|
options = {
|
||||||
...Dialog.currentOptions,
|
...currentOptions,
|
||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -87,32 +100,9 @@ const Dialog: Dialog = (options) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Dialog.defaultOptions = {
|
Dialog.alert = (options: DialogOptions) => Dialog(options);
|
||||||
show: false,
|
|
||||||
title: '',
|
|
||||||
width: null,
|
|
||||||
theme: 'default',
|
|
||||||
message: '',
|
|
||||||
zIndex: 100,
|
|
||||||
overlay: true,
|
|
||||||
selector: '#van-dialog',
|
|
||||||
className: '',
|
|
||||||
asyncClose: false,
|
|
||||||
transition: 'scale',
|
|
||||||
customStyle: '',
|
|
||||||
messageAlign: '',
|
|
||||||
overlayStyle: '',
|
|
||||||
confirmButtonText: '确认',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
showConfirmButton: true,
|
|
||||||
showCancelButton: false,
|
|
||||||
closeOnClickOverlay: false,
|
|
||||||
confirmButtonOpenType: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
Dialog.alert = Dialog;
|
Dialog.confirm = (options: DialogOptions) =>
|
||||||
|
|
||||||
Dialog.confirm = (options) =>
|
|
||||||
Dialog({
|
Dialog({
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
...options,
|
...options,
|
||||||
@ -131,12 +121,17 @@ Dialog.stopLoading = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Dialog.setDefaultOptions = (options) => {
|
Dialog.currentOptions = currentOptions;
|
||||||
Object.assign(Dialog.currentOptions, options);
|
Dialog.defaultOptions = defaultOptions;
|
||||||
|
|
||||||
|
Dialog.setDefaultOptions = (options: DialogOptions) => {
|
||||||
|
currentOptions = { ...currentOptions, ...options };
|
||||||
|
Dialog.currentOptions = currentOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
Dialog.resetDefaultOptions = () => {
|
Dialog.resetDefaultOptions = () => {
|
||||||
Dialog.currentOptions = { ...Dialog.defaultOptions };
|
currentOptions = { ...defaultOptions };
|
||||||
|
Dialog.currentOptions = currentOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
Dialog.resetDefaultOptions();
|
Dialog.resetDefaultOptions();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user