index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <script lang="ts" setup>
  2. import { type DrawerPlacement, Page, useVbenDrawer } from '@vben/common-ui';
  3. import { Button, Card } from 'ant-design-vue';
  4. import DocButton from '../doc-button.vue';
  5. import AutoHeightDemo from './auto-height-demo.vue';
  6. import BaseDemo from './base-demo.vue';
  7. import DynamicDemo from './dynamic-demo.vue';
  8. import FormDrawerDemo from './form-drawer-demo.vue';
  9. import inContentDemo from './in-content-demo.vue';
  10. import SharedDataDemo from './shared-data-demo.vue';
  11. const [BaseDrawer, baseDrawerApi] = useVbenDrawer({
  12. // 连接抽离的组件
  13. connectedComponent: BaseDemo,
  14. // placement: 'left',
  15. });
  16. const [InContentDrawer, inContentDrawerApi] = useVbenDrawer({
  17. // 连接抽离的组件
  18. connectedComponent: inContentDemo,
  19. // placement: 'left',
  20. });
  21. const [AutoHeightDrawer, autoHeightDrawerApi] = useVbenDrawer({
  22. connectedComponent: AutoHeightDemo,
  23. });
  24. const [DynamicDrawer, dynamicDrawerApi] = useVbenDrawer({
  25. connectedComponent: DynamicDemo,
  26. });
  27. const [SharedDataDrawer, sharedDrawerApi] = useVbenDrawer({
  28. connectedComponent: SharedDataDemo,
  29. });
  30. const [FormDrawer, formDrawerApi] = useVbenDrawer({
  31. connectedComponent: FormDrawerDemo,
  32. });
  33. function openBaseDrawer(placement: DrawerPlacement = 'right') {
  34. baseDrawerApi.setState({ placement });
  35. baseDrawerApi.open();
  36. }
  37. function openInContentDrawer(placement: DrawerPlacement = 'right') {
  38. inContentDrawerApi.setState({ class: '', placement });
  39. if (placement === 'top') {
  40. // 页面顶部区域的层级只有200,所以设置一个低于200的值,抽屉从顶部滑出来的时候才比较合适
  41. inContentDrawerApi.setState({ zIndex: 199 });
  42. } else {
  43. inContentDrawerApi.setState({ zIndex: undefined });
  44. }
  45. inContentDrawerApi.open();
  46. }
  47. function openMaxContentDrawer() {
  48. // 这里只是用来演示方便。实际上自己使用的时候可以直接将这些配置卸载Drawer的属性里
  49. inContentDrawerApi.setState({ class: 'w-full', placement: 'right' });
  50. inContentDrawerApi.open();
  51. }
  52. function openAutoHeightDrawer() {
  53. autoHeightDrawerApi.open();
  54. }
  55. function openDynamicDrawer() {
  56. dynamicDrawerApi.open();
  57. }
  58. function handleUpdateTitle() {
  59. dynamicDrawerApi.setState({ title: '外部动态标题' });
  60. dynamicDrawerApi.open();
  61. }
  62. function openSharedDrawer() {
  63. sharedDrawerApi.setData({
  64. content: '外部传递的数据 content',
  65. payload: '外部传递的数据 payload',
  66. });
  67. sharedDrawerApi.open();
  68. }
  69. function openFormDrawer() {
  70. formDrawerApi.setData({
  71. // 表单值
  72. values: { field1: 'abc', field2: '123' },
  73. });
  74. formDrawerApi.open();
  75. }
  76. </script>
  77. <template>
  78. <Page
  79. auto-content-height
  80. description="抽屉组件通常用于在当前页面上显示一个覆盖层,用以展示重要信息或提供用户交互界面。"
  81. title="抽屉组件示例"
  82. >
  83. <template #extra>
  84. <DocButton path="/components/common-ui/vben-drawer" />
  85. </template>
  86. <BaseDrawer />
  87. <InContentDrawer />
  88. <AutoHeightDrawer />
  89. <DynamicDrawer />
  90. <SharedDataDrawer />
  91. <FormDrawer />
  92. <Card class="mb-4" title="基本使用">
  93. <p class="mb-3">一个基础的抽屉示例</p>
  94. <Button class="mb-2" type="primary" @click="openBaseDrawer('right')">
  95. 右侧打开
  96. </Button>
  97. <Button
  98. class="mb-2 ml-2"
  99. type="primary"
  100. @click="openBaseDrawer('bottom')"
  101. >
  102. 底部打开
  103. </Button>
  104. <Button class="mb-2 ml-2" type="primary" @click="openBaseDrawer('left')">
  105. 左侧打开
  106. </Button>
  107. <Button class="mb-2 ml-2" type="primary" @click="openBaseDrawer('top')">
  108. 顶部打开
  109. </Button>
  110. </Card>
  111. <Card class="mb-4" title="在内容区域打开">
  112. <p class="mb-3">指定抽屉在内容区域打开,不会覆盖顶部和左侧菜单等区域</p>
  113. <Button class="mb-2" type="primary" @click="openInContentDrawer('right')">
  114. 右侧打开
  115. </Button>
  116. <Button
  117. class="mb-2 ml-2"
  118. type="primary"
  119. @click="openInContentDrawer('bottom')"
  120. >
  121. 底部打开
  122. </Button>
  123. <Button
  124. class="mb-2 ml-2"
  125. type="primary"
  126. @click="openInContentDrawer('left')"
  127. >
  128. 左侧打开
  129. </Button>
  130. <Button
  131. class="mb-2 ml-2"
  132. type="primary"
  133. @click="openInContentDrawer('top')"
  134. >
  135. 顶部打开
  136. </Button>
  137. <Button class="mb-2 ml-2" type="primary" @click="openMaxContentDrawer">
  138. 内容区域全屏打开
  139. </Button>
  140. </Card>
  141. <Card class="mb-4" title="内容高度自适应滚动">
  142. <p class="mb-3">可根据内容自动计算滚动高度</p>
  143. <Button type="primary" @click="openAutoHeightDrawer">打开抽屉</Button>
  144. </Card>
  145. <Card class="mb-4" title="动态配置示例">
  146. <p class="mb-3">通过 setState 动态调整抽屉数据</p>
  147. <Button type="primary" @click="openDynamicDrawer">打开抽屉</Button>
  148. <Button class="ml-2" type="primary" @click="handleUpdateTitle">
  149. 从外部修改标题并打开
  150. </Button>
  151. </Card>
  152. <Card class="mb-4" title="内外数据共享示例">
  153. <p class="mb-3">通过共享 sharedData 来进行数据交互</p>
  154. <Button type="primary" @click="openSharedDrawer">
  155. 打开抽屉并传递数据
  156. </Button>
  157. </Card>
  158. <Card class="mb-4" title="表单抽屉示例">
  159. <p class="mb-3">打开抽屉并设置表单schema以及数据</p>
  160. <Button type="primary" @click="openFormDrawer">
  161. 打开抽屉并设置表单schema以及数据
  162. </Button>
  163. </Card>
  164. </Page>
  165. </template>