modal.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import type { ModalApi } from './modal-api';
  2. import type { Component, Ref } from 'vue';
  3. export interface ModalProps {
  4. /**
  5. * 取消按钮文字
  6. */
  7. cancelText?: string;
  8. /**
  9. * 是否居中
  10. * @default false
  11. */
  12. centered?: boolean;
  13. class?: string;
  14. /**
  15. * 是否显示右上角的关闭按钮
  16. * @default true
  17. */
  18. closable?: boolean;
  19. /**
  20. * 点击弹窗遮罩是否关闭弹窗
  21. * @default true
  22. */
  23. closeOnClickModal?: boolean;
  24. /**
  25. * 按下 ESC 键是否关闭弹窗
  26. * @default true
  27. */
  28. closeOnPressEscape?: boolean;
  29. /**
  30. * 确定按钮 loading
  31. * @default false
  32. */
  33. confirmLoading?: boolean;
  34. /**
  35. * 确定按钮文字
  36. */
  37. confirmText?: string;
  38. contentClass?: string;
  39. /**
  40. * 弹窗描述
  41. */
  42. description?: string;
  43. /**
  44. * 是否可拖拽
  45. * @default false
  46. */
  47. draggable?: boolean;
  48. /**
  49. * 是否显示底部
  50. * @default true
  51. */
  52. footer?: boolean;
  53. footerClass?: string;
  54. /**
  55. * 是否全屏
  56. * @default false
  57. */
  58. fullscreen?: boolean;
  59. /**
  60. * 是否显示全屏按钮
  61. * @default true
  62. */
  63. fullscreenButton?: boolean;
  64. /**
  65. * 是否显示顶栏
  66. * @default true
  67. */
  68. header?: boolean;
  69. headerClass?: string;
  70. /**
  71. * 弹窗是否显示
  72. * @default false
  73. */
  74. loading?: boolean;
  75. /**
  76. * 是否显示遮罩
  77. * @default true
  78. */
  79. modal?: boolean;
  80. /**
  81. * 是否自动聚焦
  82. */
  83. openAutoFocus?: boolean;
  84. /**
  85. * 是否显示取消按钮
  86. * @default true
  87. */
  88. showCancelButton?: boolean;
  89. /**
  90. * 是否显示确认按钮
  91. * @default true
  92. */
  93. showConfirmButton?: boolean;
  94. /**
  95. * 弹窗标题
  96. */
  97. title?: string;
  98. /**
  99. * 弹窗标题提示
  100. */
  101. titleTooltip?: string;
  102. }
  103. export interface ModalState extends ModalProps {
  104. /** 弹窗打开状态 */
  105. isOpen?: boolean;
  106. /**
  107. * 共享数据
  108. */
  109. sharedData?: Record<string, any>;
  110. }
  111. export type ExtendedModalApi = {
  112. useStore: <T = NoInfer<ModalState>>(
  113. selector?: (state: NoInfer<ModalState>) => T,
  114. ) => Readonly<Ref<T>>;
  115. } & ModalApi;
  116. export interface ModalApiOptions extends ModalState {
  117. /**
  118. * 独立的弹窗组件
  119. */
  120. connectedComponent?: Component;
  121. /**
  122. * 关闭前的回调,返回 false 可以阻止关闭
  123. * @returns
  124. */
  125. onBeforeClose?: () => void;
  126. /**
  127. * 点击取消按钮的回调
  128. */
  129. onCancel?: () => void;
  130. /**
  131. * 点击确定按钮的回调
  132. */
  133. onConfirm?: () => void;
  134. /**
  135. * 弹窗状态变化回调
  136. * @param isOpen
  137. * @returns
  138. */
  139. onOpenChange?: (isOpen: boolean) => void;
  140. }