drawer.ts 2.9 KB

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