UNPKG

13.2 kBTypeScriptView Raw
1import { RenderFunction, SetupContext, ComponentPublicInstance, Ref } from 'vue'
2import { VXEComponent, VxeComponentBase, VxeEvent, SizeType, ValueOf, SlotVNodeType } from './component'
3
4/* eslint-disable no-use-before-define */
5
6/**
7 * 组件 - 弹窗
8 * @example import { VxeModal } from 'vxe-table'
9 */
10export const VxeModal: VXEComponent<VxeModalProps, VxeModalEventProps, VxeModalSlots>
11/**
12 * 组件 - 弹窗
13 */
14export const Modal: typeof VxeModal
15
16export type VxeModalInstance = ComponentPublicInstance<VxeModalProps, VxeModalConstructor>
17
18export interface VxeModalConstructor extends VxeComponentBase, VxeModalMethods {
19 props: VxeModalProps
20 context: SetupContext<VxeModalEmits>
21 reactData: ModalReactData
22 getRefMaps(): ModalPrivateRef
23 renderVN: RenderFunction
24}
25
26export interface ModalPrivateRef {
27 refElem: Ref<HTMLDivElement>
28}
29export interface VxeModalPrivateRef extends ModalPrivateRef { }
30
31export interface ModalReactData {
32 inited: boolean
33 visible: boolean
34 contentVisible: boolean
35 modalTop: number
36 modalZindex: number
37 zoomLocat: {
38 left: number
39 top: number
40 width: number
41 height: number
42 } | null
43 firstOpen: boolean
44}
45
46export interface ModalMethods {
47 dispatchEvent(type: ValueOf<VxeModalEmits>, params: any, evnt?: Event): void
48 /**
49 * 手动打开窗口
50 */
51 open(): Promise<any>
52 /**
53 * 手动关闭窗口
54 */
55 close(): Promise<any>
56 /**
57 * 获取当前窗口元素
58 */
59 getBox(): HTMLElement
60 /**
61 * 获取窗口位置
62 */
63 getPosition(): {
64 top?: number
65 left?: number
66 } | null
67 /**
68 * 设置窗口位置
69 */
70 setPosition(top?: number, left?: number): Promise<any>
71 /**
72 * 判断是否最大化显示
73 */
74 isMaximized(): boolean
75 /**
76 * 切换窗口最大化/还原
77 */
78 zoom(): Promise<boolean>
79 /**
80 * 如果窗口处于常规状态,则最大化窗口
81 */
82 maximize(): Promise<any>
83 /**
84 * 如果窗口处于最大化状态,则还原窗口
85 */
86 revert(): Promise<any>
87}
88export interface VxeModalMethods extends ModalMethods { }
89
90export interface ModalPrivateMethods { }
91export interface VxeModalPrivateMethods extends ModalPrivateMethods { }
92
93/**
94 * 窗口类型
95 */
96export type ModalType = 'alert' | 'confirm' | 'message' | 'modal'
97/**
98 * 窗口状态
99 */
100export type ModalStatus = 'info' | 'success' | 'warning' | 'question' | 'error' | 'loading'
101
102export type ModalPosition = {
103 top?: number
104 left?: number
105}
106
107/**
108 * 窗口事件类型
109 */
110export type ModalEventTypes = 'model' | 'mask' | 'close' | 'confirm' | 'cancel' | 'exit' | 'exist'
111
112export namespace VxeModalPropTypes {
113 export type Size = SizeType
114 export type ModelValue = boolean
115 export type ID = string | null
116 export type Type = ModalType
117 export type Loading = boolean
118 export type Status = ModalStatus
119 export type IconStatus = string
120 export type ClassName = string
121 export type Top = number | string
122 export type Position = 'center' | ModalPosition
123 export type Title = string | number
124 export type Duration = number | string
125 export type Content = number | string | null
126 /**
127 * 请使用 content
128 * @deprecated
129 */
130 export type Message = Content
131 export type ShowCancelButton = boolean | null
132 export type CancelButtonText = string
133 export type ShowConfirmButton = boolean | null
134 export type ConfirmButtonText = string
135 export type LockView = boolean
136 export type LockScroll = boolean
137 export type Mask = boolean
138 export type MaskClosable = boolean
139 export type EscClosable = boolean
140 export type Resize = boolean
141 export type ShowHeader = boolean
142 export type ShowFooter = boolean
143 export type ShowZoom = boolean
144 export type ShowClose = boolean
145 export type DblclickZoom = boolean
146 export type Width = number | string
147 export type Height = number | string
148 export type MinWidth = number | string
149 export type MinHeight = number | string
150 export type ZIndex = number
151 export type MarginSize = number | string
152 export type Fullscreen = boolean
153 export type Draggable = boolean
154 export type Remember = boolean
155 export type DestroyOnClose = boolean
156 export type ShowTitleOverflow = boolean
157 export type Transfer = boolean
158 export type Storage = boolean
159 export type StorageKey = string
160 export type Animat = boolean
161 export type BeforeHideMethod = (params: ModalVisibleParams) => Promise<any>
162 export type Slots = ModalSlots
163}
164
165export type VxeModalProps = {
166 size?: VxeModalPropTypes.Size
167 modelValue?: VxeModalPropTypes.ModelValue
168 id?: VxeModalPropTypes.ID
169 type?: VxeModalPropTypes.Type
170 loading?: VxeModalPropTypes.Loading
171 status?: VxeModalPropTypes.Status
172 iconStatus?: VxeModalPropTypes.IconStatus
173 className?: VxeModalPropTypes.ClassName
174 top?: VxeModalPropTypes.Top
175 position?: VxeModalPropTypes.Position
176 title?: VxeModalPropTypes.Title
177 duration?: VxeModalPropTypes.Duration
178 content?: VxeModalPropTypes.Content
179 showCancelButton?: VxeModalPropTypes.ShowCancelButton
180 cancelButtonText?: VxeModalPropTypes.CancelButtonText
181 showConfirmButton?: VxeModalPropTypes.ShowConfirmButton
182 confirmButtonText?: VxeModalPropTypes.ConfirmButtonText
183 lockView?: VxeModalPropTypes.LockView
184 lockScroll?: VxeModalPropTypes.LockScroll
185 mask?: VxeModalPropTypes.Mask
186 maskClosable?: VxeModalPropTypes.MaskClosable
187 escClosable?: VxeModalPropTypes.EscClosable
188 resize?: VxeModalPropTypes.Resize
189 showHeader?: VxeModalPropTypes.ShowHeader
190 showFooter?: VxeModalPropTypes.ShowFooter
191 showZoom?: VxeModalPropTypes.ShowZoom
192 showClose?: VxeModalPropTypes.ShowClose
193 dblclickZoom?: VxeModalPropTypes.DblclickZoom
194 draggable?: VxeModalPropTypes.Draggable
195 width?: VxeModalPropTypes.Width
196 height?: VxeModalPropTypes.Height
197 minWidth?: VxeModalPropTypes.MinWidth
198 minHeight?: VxeModalPropTypes.MinHeight
199 zIndex?: VxeModalPropTypes.ZIndex
200 marginSize?: VxeModalPropTypes.MarginSize
201 fullscreen?: VxeModalPropTypes.Fullscreen
202 remember?: VxeModalPropTypes.Remember
203 destroyOnClose?: VxeModalPropTypes.DestroyOnClose
204 showTitleOverflow?: VxeModalPropTypes.ShowTitleOverflow
205 transfer?: VxeModalPropTypes.Transfer
206 storage?: VxeModalPropTypes.Storage
207 storageKey?: VxeModalPropTypes.StorageKey
208 animat?: VxeModalPropTypes.Animat
209 beforeHideMethod?: VxeModalPropTypes.BeforeHideMethod
210 slots?: VxeModalPropTypes.Slots
211 /**
212 * @deprecated 已废弃,请使用 content
213 */
214 message?: VxeModalPropTypes.Content
215}
216
217export type ModalSlots = {
218 /**
219 * 自定义窗口内容模板
220 */
221 default?(params: ModalDefaultSlotParams): SlotVNodeType[] | SlotVNodeType
222 /**
223 * 自定义窗口头部的模板
224 */
225 header?(params: ModalHeaderSlotParams): SlotVNodeType[] | SlotVNodeType
226 /**
227 * 自定义窗口标题的模板(如果使用了 header 插槽,则该插槽无效)
228 */
229 title?(params: ModalTitleSlotParams): SlotVNodeType[] | SlotVNodeType
230 /**
231 * 自定义窗口右上角的模板
232 */
233 corner?(params: ModalTitleSlotParams): SlotVNodeType[] | SlotVNodeType
234 /**
235 * 自定义窗口底部的模板
236 */
237 footer?(params: ModalFooterSlotParams): SlotVNodeType[] | SlotVNodeType
238}
239
240export type VxeModalEmits = [
241 'update:modelValue',
242 'show',
243 'hide',
244 'before-hide',
245 'close',
246 'confirm',
247 'cancel',
248 'zoom',
249 'resize',
250 'move'
251]
252
253/**
254 * 全局窗口控制器
255 */
256export interface ModalController {
257 /**
258 * 创建窗口
259 * @param options 参数
260 */
261 open(options: VxeModalDefines.ModalOptions): Promise<ModalEventTypes>
262 /**
263 * 创建提示框
264 * @param content 消息内容
265 * @param title 标题
266 * @param options 参数
267 */
268 alert(content: VxeModalPropTypes.Content, title?: VxeModalPropTypes.Title, options?: VxeModalDefines.ModalOptions): Promise<ModalEventTypes>
269 /**
270 * 创建提示框
271 * @param options 参数
272 */
273 alert(options: VxeModalDefines.ModalOptions): Promise<ModalEventTypes>
274 /**
275 * 创建确认框
276 * @param content 消息内容
277 * @param title 标题
278 * @param options 参数
279 */
280 confirm(content: VxeModalPropTypes.Content, title?: VxeModalPropTypes.Title, options?: VxeModalDefines.ModalOptions): Promise<ModalEventTypes>
281 /**
282 * 创建确认框
283 * @param options 参数
284 */
285 confirm(options: VxeModalDefines.ModalOptions): Promise<ModalEventTypes>
286 /**
287 * 创建消息提示
288 * @param content 消息内容
289 * @param title 标题
290 * @param options 参数
291 */
292 message(content: VxeModalPropTypes.Content, options?: VxeModalDefines.ModalOptions): Promise<ModalEventTypes>
293 /**
294 * 创建消息提示
295 * @param options 参数
296 */
297 message(options: VxeModalDefines.ModalOptions): Promise<ModalEventTypes>
298 /**
299 * 获取动态的活动窗口
300 * @param id 窗口唯一标识
301 */
302 get(id: string): VxeModalConstructor & VxeModalMethods
303 /**
304 * 关闭动态的活动窗口,如果为空则关闭所有
305 * @param id 窗口唯一标识
306 */
307 close(id?: VxeModalPropTypes.ID): Promise<any>
308}
309
310export interface ModalDefaultSlotParams {
311 $modal: VxeModalConstructor & VxeModalMethods
312}
313
314export interface ModalHeaderSlotParams extends ModalDefaultSlotParams { }
315export interface ModalTitleSlotParams extends ModalDefaultSlotParams { }
316export interface ModalFooterSlotParams extends ModalDefaultSlotParams { }
317
318interface ModalVisibleParams {
319 type: ModalEventTypes
320}
321
322export namespace VxeModalDefines {
323 export interface ModalOptions extends VxeModalProps, VxeModalEventProps {
324 key?: string | number
325 }
326
327 interface ModalEventParams extends VxeEvent {
328 $modal: VxeModalConstructor & VxeModalMethods
329 }
330
331 interface ModalBaseParams extends ModalVisibleParams { }
332
333 export interface ShowParams extends ModalBaseParams { }
334 export interface ShowEventParams extends ModalEventParams, ShowParams { }
335
336 export interface HideParams extends ModalBaseParams { }
337 export interface HideEventParams extends ModalEventParams, HideParams { }
338
339 export interface BeforeHideParams extends ModalBaseParams { }
340 export interface BeforeHideEventParams extends ModalEventParams, BeforeHideParams { }
341
342 export interface ConfirmParams extends ModalBaseParams { }
343 export interface ConfirmEventParams extends ModalEventParams, ConfirmParams { }
344
345 export interface CancelParams extends ModalBaseParams { }
346 export interface CancelEventParams extends ModalEventParams, CancelParams { }
347
348 export interface CloseParams extends ModalBaseParams { }
349 export interface CloseEventParams extends ModalEventParams, CloseParams { }
350
351 export interface ZoomParams extends ModalBaseParams { }
352 export interface ZoomEventParams extends ModalEventParams, ZoomParams { }
353
354 export interface ResizeParams extends ModalBaseParams { }
355 export interface ResizeEventParams extends ModalEventParams, ResizeParams { }
356
357 export interface MoveParams extends ModalBaseParams { }
358 export interface MoveEventParams extends ModalEventParams, MoveParams { }
359}
360
361export type VxeModalEventProps = {
362 onShow?: VxeModalEvents.Show
363 onHide?: VxeModalEvents.Hide
364 onBeforeHide?: VxeModalEvents.BeforeHide
365 onConfirm?: VxeModalEvents.Confirm
366 onCancel?: VxeModalEvents.Cancel
367 onClose?: VxeModalEvents.Close
368 onZoom?: VxeModalEvents.Zoom
369 onResize?: VxeModalEvents.Resize
370 onMove?: VxeModalEvents.Move
371}
372
373export interface VxeModalListeners {
374 show?: VxeModalEvents.Show
375 hide?: VxeModalEvents.Hide
376 beforeHide?: VxeModalEvents.BeforeHide
377 confirm?: VxeModalEvents.Confirm
378 cancel?: VxeModalEvents.Cancel
379 close?: VxeModalEvents.Close
380 zoom?: VxeModalEvents.Zoom
381 resize?: VxeModalEvents.Resize
382 move?: VxeModalEvents.Move
383}
384
385export namespace VxeModalEvents {
386 export type Show = (params: VxeModalDefines.ShowEventParams) => void
387 export type Hide = (params: VxeModalDefines.HideEventParams) => void
388 export type BeforeHide = (params: VxeModalDefines.BeforeHideEventParams) => void
389 export type Confirm = (params: VxeModalDefines.ConfirmEventParams) => void
390 export type Cancel = (params: VxeModalDefines.CancelEventParams) => void
391 export type Close = (params: VxeModalDefines.CloseEventParams) => void
392 export type Zoom = (params: VxeModalDefines.ZoomEventParams) => void
393 export type Resize = (params: VxeModalDefines.ResizeEventParams) => void
394 export type Move = (params: VxeModalDefines.MoveEventParams) => void
395}
396
397export interface VxeModalSlots {
398 /**
399 * 自定义窗口内容模板
400 */
401 default: (params: ModalDefaultSlotParams) => any
402 /**
403 * 自定义窗口头部的模板
404 */
405 header: (params: ModalHeaderSlotParams) => any
406 /**
407 * 自定义窗口标题的模板(如果使用了 header 插槽,则该插槽无效)
408 */
409 title: (params: ModalTitleSlotParams) => any
410 /**
411 * 自定义窗口右上角的模板
412 */
413 corner: (params: ModalTitleSlotParams) => any
414 /**
415 * 自定义窗口底部的模板
416 */
417 footer: (params: ModalFooterSlotParams) => any
418}