drawer.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import type { Component, Ref } from 'vue';
  2. import type { ClassType } from '@vben-core/typings';
  3. import type { DrawerApi } from './drawer-api';
  4. export type DrawerPlacement = 'bottom' | 'left' | 'right' | 'top';
  5. export type CloseIconPlacement = 'left' | 'right';
  6. export interface DrawerProps {
  7. /**
  8. * 是否挂载到内容区域
  9. * @default false
  10. */
  11. appendToMain?: boolean;
  12. /**
  13. * 取消按钮文字
  14. */
  15. cancelText?: string;
  16. class?: ClassType;
  17. /**
  18. * 是否显示关闭按钮
  19. * @default true
  20. */
  21. closable?: boolean;
  22. /**
  23. * 关闭按钮的位置
  24. */
  25. closeIconPlacement?: CloseIconPlacement;
  26. /**
  27. * 点击弹窗遮罩是否关闭弹窗
  28. * @default true
  29. */
  30. closeOnClickModal?: boolean;
  31. /**
  32. * 按下 ESC 键是否关闭弹窗
  33. * @default true
  34. */
  35. closeOnPressEscape?: boolean;
  36. /**
  37. * 确定按钮 loading
  38. * @default false
  39. */
  40. confirmLoading?: boolean;
  41. /**
  42. * 确定按钮文字
  43. */
  44. confirmText?: string;
  45. contentClass?: string;
  46. /**
  47. * 弹窗描述
  48. */
  49. description?: string;
  50. /**
  51. * 是否显示底部
  52. * @default true
  53. */
  54. footer?: boolean;
  55. /**
  56. * 弹窗底部样式
  57. */
  58. footerClass?: ClassType;
  59. /**
  60. * 是否显示顶栏
  61. * @default true
  62. */
  63. header?: boolean;
  64. /**
  65. * 弹窗头部样式
  66. */
  67. headerClass?: ClassType;
  68. /**
  69. * 弹窗是否显示
  70. * @default false
  71. */
  72. loading?: boolean;
  73. /**
  74. * 是否显示遮罩
  75. * @default true
  76. */
  77. modal?: boolean;
  78. /**
  79. * 是否自动聚焦
  80. */
  81. openAutoFocus?: boolean;
  82. /**
  83. * 弹窗遮罩模糊效果
  84. */
  85. overlayBlur?: number;
  86. /**
  87. * 抽屉位置
  88. * @default right
  89. */
  90. placement?: DrawerPlacement;
  91. /**
  92. * 是否显示取消按钮
  93. * @default true
  94. */
  95. showCancelButton?: boolean;
  96. /**
  97. * 是否显示确认按钮
  98. * @default true
  99. */
  100. showConfirmButton?: boolean;
  101. /**
  102. * 弹窗标题
  103. */
  104. title?: string;
  105. /**
  106. * 弹窗标题提示
  107. */
  108. titleTooltip?: string;
  109. /**
  110. * 抽屉层级
  111. */
  112. zIndex?: number;
  113. }
  114. export interface DrawerState extends DrawerProps {
  115. /** 弹窗打开状态 */
  116. isOpen?: boolean;
  117. /**
  118. * 共享数据
  119. */
  120. sharedData?: Record<string, any>;
  121. }
  122. export type ExtendedDrawerApi = DrawerApi & {
  123. useStore: <T = NoInfer<DrawerState>>(
  124. selector?: (state: NoInfer<DrawerState>) => T,
  125. ) => Readonly<Ref<T>>;
  126. };
  127. export interface DrawerApiOptions extends DrawerState {
  128. /**
  129. * 独立的抽屉组件
  130. */
  131. connectedComponent?: Component;
  132. /**
  133. * 在关闭时销毁抽屉。仅在使用 connectedComponent 时有效
  134. */
  135. destroyOnClose?: boolean;
  136. /**
  137. * 关闭前的回调,返回 false 可以阻止关闭
  138. * @returns
  139. */
  140. onBeforeClose?: () => void;
  141. /**
  142. * 点击取消按钮的回调
  143. */
  144. onCancel?: () => void;
  145. /**
  146. * 弹窗关闭动画结束的回调
  147. * @returns
  148. */
  149. onClosed?: () => void;
  150. /**
  151. * 点击确定按钮的回调
  152. */
  153. onConfirm?: () => void;
  154. /**
  155. * 弹窗状态变化回调
  156. * @param isOpen
  157. * @returns
  158. */
  159. onOpenChange?: (isOpen: boolean) => void;
  160. /**
  161. * 弹窗打开动画结束的回调
  162. * @returns
  163. */
  164. onOpened?: () => void;
  165. }