Skip to content

对话框 Dialog

弹出对话框时,对话框就会被弹出。

TIP

被包含在 Dialog 中的像素风组件不再需要设置 pollSizeChange,会自动正常渲染。

基础使用

visible 控制对话框的展示和隐藏,传入 visible 进入受控模式。不传或者为 undefined 则为非受控模式,此时可以传入 defaultVisible 属性作为默认值。

隐藏源代码

弹窗表单

只是一个对话框中使用表单的栗子🌰。就像栗子所展示的那样,你可以直接传入 classstyle 等 attrs 穿透到对话框容器元素上。

隐藏源代码

函数式

如果你完整注册了组件库,你可以以以下方式使用它:

  • window.$dialog
  • Vue 组件内: getCurrentInstance().appContext.config.globalProperties.PixeliumVue.dialog
  • @pixelium/web-vue 中导入。

按需引入时,也可以从 @pixelium/web-vue/es 中导入 Dialog 使用。

隐藏源代码

异步确认

传入 onBeforeOk 后,在确认时将会等待 onBeforeOk 执行完成,若结果不为 false 再执行后续代码。

隐藏源代码

API

Dialog Function

Dialog 上的函数调用后,返回一个 Promise<boolean>,通过确认关闭弹窗,则以 true fulfilled,否则为 false

ts
type DialogReturn = Promise<boolean> & {
	close: () => void
}

// ...
// Dialog
{
	[key in DialogOptions['type'] & string]: (
		options:
			| (Omit<DialogOptions, 'type'> & Omit<EmitEvent<DialogEvents>, 'update:visible'>)
			| string
	) => DialogReturn
}

Attrs

就像上面栗子所展示的那样🌰,作为组件时你可以直接传入 classstyle 等 attrs 穿透到对话框容器元素上。

DialogOptions

属性类型可选默认值描述版本
contentValidContent对话框内容。0.1.0
titleValidContent对话框标题。0.1.0
iconValidVNodeContent对话框标题图标。0.1.0
footerValidVNodeContent对话框底部区域。0.1.0
type'info' | 'success' | 'warning' | 'error' | 'normal' | 'confirm' | 'notice''normal'对话框类型。0.1.0
closablebooleantrue是否展示右上角关闭按钮。0.1.0
maskbooleantrue是否展示遮罩层。0.1.0
maskClosablebooleantrue点击遮罩层是否可以关闭对话框。0.1.0
escToClosebooleantrue是否可以按 ESC 键关闭对话框。0.1.0
showCancelboolean是否展示取消按钮,不设置时,受 type 字段影响,仅 'confirm' 时展示。0.1.0
okTextstring确认按钮文本内容。0.1.0
cancelTextstring取消按钮文本内容。0.1.0
showFooterbooleantrue是否展示对话框底部区域。0.1.0
zIndexnumber对话框的 z-index 属性。0.1.0
rootstring | HTMLElement'body'对话框挂载的根元素。0.1.0
okButtonPropsButtonProps & EmitEvent<ButtonEvents> & RestAttrs确认按钮的属性。0.1.0
cancelButtonPropsButtonProps & EmitEvent<ButtonEvents> & RestAttrs取消按钮的属性。0.1.0
maskPropsOmit<MaskProps, 'zIndex'>遮罩层的属性。0.1.0
containerPropsRestAttrs对话框容器元素的属性。0.1.0
headerPropsRestAttrs对话框头部区域元素的属性。0.1.0
bodyPropsRestAttrs对话框内容区域元素的属性。0.1.0
footerPropsRestAttrs对话框底部区域元素的属性。0.1.0

DialogProps

属性类型可选默认值描述版本
visibleboolean | null控制对话框展示,受控模式,支持 v-model0.1.0
defaultVisibleboolean | null控制对话框展示的默认值,非受控模式。0.1.0
titlestring''对话框标题。0.1.0
closablebooleantrue是否展示右上角关闭按钮。0.1.0
maskbooleantrue是否展示遮罩层。0.1.0
maskClosablebooleantrue点击遮罩层是否可以关闭对话框。0.1.0
escToClosebooleantrue是否可以按 ESC 键关闭对话框。0.1.0
showCancelbooleantrue是否展示取消按钮,不设置时,受 type 字段影响,仅 'confirm' 时展示。0.1.0
okTextstring确认按钮文本内容。0.1.0
cancelTextstring取消按钮文本内容。0.1.0
booleanbooleanfalse0.1.0
showFooterbooleantrue是否展示对话框底部区域。0.1.0
rootstring | HTMLElement'body'对话框挂载的根元素。0.1.0
zIndexnumber对话框的 z-index 属性。0.1.0
destroyOnHidebooleanfalse对话框内容是否在隐藏后销毁。0.1.0
okButtonPropsButtonProps & EmitEvent<ButtonEvents> & RestAttrs确认按钮的属性。0.1.0
cancelButtonPropsButtonProps & EmitEvent<ButtonEvents> & RestAttrs取消按钮的属性。0.1.0
maskPropsOmit<MaskProps, 'zIndex'>遮罩层的属性。0.1.0
containerPropsRestAttrs对话框容器元素的属性。0.1.0
headerPropsRestAttrs对话框头部区域元素的属性。0.1.0
bodyPropsRestAttrs对话框内容区域元素的属性。0.1.0
footerPropsRestAttrs对话框底部区域元素的属性。0.1.0

DialogSlots

插槽参数描述版本
default对话框内容。0.1.0
title对话框标题。0.1.0
icon对话框标题图标。0.1.0
footer对话框底部区域。0.1.0

DialogEvents

事件参数描述版本
update:visible用于更新受控模式的 visible 值。0.1.0
beforeOk用于异步确认,需返回一个 Promise<boolean | void> | boolean | void 类型的数据判断是否成功,await 操作后不为 false 即为确认成功。0.1.0
okevent: MouseEvent通过确认成功关闭弹窗的回调。0.1.0
cancelevent: MouseEvent | KeyboardEvent通过取消、关闭按钮、遮罩层、ESC 键等方法,关闭弹窗的回调。0.1.0
open弹窗打开时的回调。0.1.0
afterOpen弹窗打开动画结束后的回调。0.1.0
close弹窗关闭时的回调。0.1.0
afterClose弹窗关闭动画结束后的回调。0.1.0

DialogExpose

属性类型可选默认值描述版本
close() => void关闭弹窗。0.1.0
open() => void打开弹窗。0.1.0

ValidContent, ValidVNodeContent

ts
export type ValidContent = string | ((...args: any[]) => VNode | string | JSX.Element | null | void)
export type ValidVNodeContent = (...args: any[]) => VNode | JSX.Element

RestAttrs

ts
import type { StyleValue } from 'vue'

export type VueClassValue = string | Record<string, any> | VueClassValue[]
export type VueStyleValue = StyleValue

export type RestAttrs = {
	style?: VueStyleValue | null
	class?: VueClassValue | null
	[x: string]: any
}

EmitEvent

ts
export type EmitEvent<T extends Record<string, any>> = {
	[K in keyof T as `on${Capitalize<K & string>}`]?: (...args: T[K]) => void
}