mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-24 23:49:14 +08:00
types(Dialog): dialog fn use ts (#8114)
This commit is contained in:
parent
9c3dbfc0b6
commit
89b65077d3
@ -13,6 +13,7 @@ import ActionBarButton from '../action-bar-button';
|
|||||||
|
|
||||||
const [createComponent, bem, t] = createNamespace('dialog');
|
const [createComponent, bem, t] = createNamespace('dialog');
|
||||||
|
|
||||||
|
export type DialogTheme = 'default' | 'round-button';
|
||||||
export type DialogAction = 'confirm' | 'cancel';
|
export type DialogAction = 'confirm' | 'cancel';
|
||||||
export type DialogMessageAlign = 'left' | 'center' | 'right';
|
export type DialogMessageAlign = 'left' | 'center' | 'right';
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ export default createComponent({
|
|||||||
props: {
|
props: {
|
||||||
...popupSharedProps,
|
...popupSharedProps,
|
||||||
title: String,
|
title: String,
|
||||||
theme: String,
|
theme: String as PropType<DialogTheme>,
|
||||||
width: [Number, String],
|
width: [Number, String],
|
||||||
message: String,
|
message: String,
|
||||||
callback: Function as PropType<(action?: DialogAction) => void>,
|
callback: Function as PropType<(action?: DialogAction) => void>,
|
||||||
|
@ -1,8 +1,40 @@
|
|||||||
|
import { App, TeleportProps } from 'vue';
|
||||||
import { inBrowser } from '../utils';
|
import { inBrowser } from '../utils';
|
||||||
|
import { Interceptor } from '../utils/interceptor';
|
||||||
import { mountComponent, usePopupState } from '../utils/mount-component';
|
import { mountComponent, usePopupState } from '../utils/mount-component';
|
||||||
import VanDialog from './Dialog';
|
import VanDialog, {
|
||||||
|
DialogTheme,
|
||||||
|
DialogAction,
|
||||||
|
DialogMessageAlign,
|
||||||
|
} from './Dialog';
|
||||||
|
|
||||||
let instance;
|
export type DialogOptions = {
|
||||||
|
title?: string;
|
||||||
|
width?: string | number;
|
||||||
|
theme?: DialogTheme;
|
||||||
|
message?: string;
|
||||||
|
overlay?: boolean;
|
||||||
|
teleport?: TeleportProps['to'];
|
||||||
|
className?: any;
|
||||||
|
allowHtml?: boolean;
|
||||||
|
lockScroll?: boolean;
|
||||||
|
transition?: string;
|
||||||
|
beforeClose?: Interceptor;
|
||||||
|
messageAlign?: DialogMessageAlign;
|
||||||
|
overlayClass?: string;
|
||||||
|
overlayStyle?: Record<string, any>;
|
||||||
|
closeOnPopstate?: boolean;
|
||||||
|
cancelButtonText?: string;
|
||||||
|
showCancelButton?: boolean;
|
||||||
|
showConfirmButton?: boolean;
|
||||||
|
cancelButtonColor?: string;
|
||||||
|
confirmButtonText?: string;
|
||||||
|
confirmButtonColor?: string;
|
||||||
|
closeOnClickOverlay?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO remove any
|
||||||
|
let instance: any;
|
||||||
|
|
||||||
function initInstance() {
|
function initInstance() {
|
||||||
const Wrapper = {
|
const Wrapper = {
|
||||||
@ -15,7 +47,7 @@ function initInstance() {
|
|||||||
({ instance } = mountComponent(Wrapper));
|
({ instance } = mountComponent(Wrapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
function Dialog(options) {
|
function Dialog(options: DialogOptions) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!inBrowser) {
|
if (!inBrowser) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@ -29,7 +61,7 @@ function Dialog(options) {
|
|||||||
instance.open({
|
instance.open({
|
||||||
...Dialog.currentOptions,
|
...Dialog.currentOptions,
|
||||||
...options,
|
...options,
|
||||||
callback: (action) => {
|
callback: (action: DialogAction) => {
|
||||||
(action === 'confirm' ? resolve : reject)(action);
|
(action === 'confirm' ? resolve : reject)(action);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -62,9 +94,13 @@ Dialog.defaultOptions = {
|
|||||||
closeOnClickOverlay: false,
|
closeOnClickOverlay: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Dialog.currentOptions = {
|
||||||
|
...Dialog.defaultOptions,
|
||||||
|
};
|
||||||
|
|
||||||
Dialog.alert = Dialog;
|
Dialog.alert = Dialog;
|
||||||
|
|
||||||
Dialog.confirm = (options) =>
|
Dialog.confirm = (options: DialogOptions) =>
|
||||||
Dialog({
|
Dialog({
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
...options,
|
...options,
|
||||||
@ -76,7 +112,7 @@ Dialog.close = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Dialog.setDefaultOptions = (options) => {
|
Dialog.setDefaultOptions = (options: DialogOptions) => {
|
||||||
Object.assign(Dialog.currentOptions, options);
|
Object.assign(Dialog.currentOptions, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,10 +120,8 @@ Dialog.resetDefaultOptions = () => {
|
|||||||
Dialog.currentOptions = { ...Dialog.defaultOptions };
|
Dialog.currentOptions = { ...Dialog.defaultOptions };
|
||||||
};
|
};
|
||||||
|
|
||||||
Dialog.resetDefaultOptions();
|
Dialog.install = (app: App) => {
|
||||||
|
app.use(VanDialog as any);
|
||||||
Dialog.install = (app) => {
|
|
||||||
app.use(VanDialog);
|
|
||||||
app.config.globalProperties.$dialog = Dialog;
|
app.config.globalProperties.$dialog = Dialog;
|
||||||
};
|
};
|
||||||
|
|
@ -47,6 +47,7 @@ const defaultOptions: ToastOptions = {
|
|||||||
closeOnClickOverlay: false,
|
closeOnClickOverlay: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO remove any
|
||||||
let queue: any[] = [];
|
let queue: any[] = [];
|
||||||
let allowMultiple = false;
|
let allowMultiple = false;
|
||||||
let currentOptions = { ...defaultOptions };
|
let currentOptions = { ...defaultOptions };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user