@tplc/wot
Version:
132 lines (131 loc) • 3.17 kB
TypeScript
import type { ButtonProps } from '../wd-button/types'
import { type InputSize, type InputType } from '../wd-input/types'
export type MessageType = 'alert' | 'confirm' | 'prompt'
export type MessageBeforeConfirmOption = {
resolve: (isPass: boolean) => void
value?: string | number
}
export type MessageOptions = {
/**
* 标题
*/
title?: string
/**
* 是否展示取消按钮
*/
showCancelButton?: boolean
/**
* 是否支持点击蒙层进行关闭,点击蒙层回调传入的action为'modal'
*/
closeOnClickModal?: boolean
/**
* 确定按钮文案
*/
confirmButtonText?: string
/**
* 取消按钮文案
*/
cancelButtonText?: string
/**
* 消息文案
*/
msg?: string
/**
* 弹框类型
*/
type?: MessageType
/**
* 当type为prompt时,输入框类型
*/
inputType?: InputType
/**
* 设置输入框大小,可选值:large
*/
inputSize?: InputSize
/**
* 当type为prompt时,输入框初始值
*/
inputValue?: string | number
/**
* 当type为prompt时,输入框placeholder
*/
inputPlaceholder?: string
/**
* 当type为prompt时,输入框正则校验,点击确定按钮时进行校验
*/
inputPattern?: RegExp
/**
* 当type为prompt时,输入框校验函数,点击确定按钮时进行校验
*/
inputValidate?: InputValidate
/**
* 当type为prompt时,输入框检验不通过时的错误提示文案
*/
inputError?: string
/**
* 是否展示错误信息
*/
showErr?: boolean
/**
* 弹窗层级
*/
zIndex?: number
/**
* 弹层内容懒渲染,触发展示时才渲染内容
*/
lazyRender?: boolean
/**
* 确认前钩子
*/
beforeConfirm?: (options: MessageBeforeConfirmOption) => void
/**
* 取消按钮Props
*/
cancelButtonProps?: Partial<ButtonProps>
/**
* 确认按钮Props
*/
confirmButtonProps?: Partial<ButtonProps>
}
export type MessageOptionsWithCallBack = MessageOptions & {
show?: boolean
success?: (res: MessageResult) => void
fail?: (res: MessageResult) => void
}
export type ActionType = 'confirm' | 'cancel' | 'modal'
export type InputValidate = (inputValue: string | number) => boolean
export interface MessageResult {
action: ActionType
value?: string | number
}
export interface Message {
show(toastOptions: MessageOptions | string): Promise<MessageResult>
alert(toastOptions: MessageOptions | string): Promise<MessageResult>
confirm(toastOptions: MessageOptions | string): Promise<MessageResult>
prompt(toastOptions: MessageOptions | string): Promise<MessageResult>
close(): void
}
export declare const messageBoxProps: {
/**
* 指定唯一标识
*/
selector: {
type: import('vue').PropType<string>
default: string
}
/**
* 是否从页面中脱离出来,用于解决各种 fixed 失效问题 (H5: teleport, APP: renderjs, 小程序: root-portal)
*/
rootPortal: {
type: BooleanConstructor
default: boolean
}
customStyle: {
type: import('vue').PropType<string>
default: string
}
customClass: {
type: import('vue').PropType<string>
default: string
}
}