SDrawer2.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. const n = `<template>
  2. <a-drawer
  3. rootClassName="s-drawer-wrap"
  4. :title="title"
  5. :placement="mode"
  6. :width="width"
  7. :height="height"
  8. :visible="visible"
  9. @close="handClose"
  10. :bodyStyle="{
  11. padding: 0,
  12. display: 'flex',
  13. flexDirection: 'column'
  14. }"
  15. >
  16. <div class="s-drawer-body">
  17. <slot />
  18. </div>
  19. <div class="s-drawer-footer">
  20. <a-space :size="spaceSize">
  21. <slot name="footer">
  22. <a-button @click="handClose">{{ $l('取消') }}</a-button>
  23. <a-button type="primary" @click="handConfirm">{{ $l('确定') }}</a-button>
  24. </slot>
  25. </a-space>
  26. </div>
  27. </a-drawer>
  28. </template>
  29. <script setup>
  30. import { ref, watch, watchEffect } from 'vue'
  31. const emit = defineEmits(['update:value', 'confirm'])
  32. const props = defineProps({
  33. // 显隐(v-model:value)
  34. value: {
  35. type: Boolean,
  36. default: false
  37. },
  38. // 抽屉标题
  39. title: {
  40. type: String,
  41. default: ''
  42. },
  43. // 弹出方向:right / left / top / bottom
  44. mode: {
  45. type: String,
  46. default: 'right'
  47. },
  48. // 左右方向时的宽度,单位 px
  49. width: {
  50. type: Number,
  51. default: 500
  52. },
  53. // 上下方向时的高度,单位 px
  54. height: {
  55. type: Number,
  56. default: 378
  57. }
  58. })
  59. const visible = ref(props.value)
  60. watch(
  61. () => props.value,
  62. (val) => {
  63. visible.value = val
  64. },
  65. { immediate: true }
  66. )
  67. const placement = ref(props.mode)
  68. const spaceSize = ref(8)
  69. watchEffect(() => {
  70. const modes = {
  71. left: '',
  72. right: '',
  73. top: '',
  74. bottom: ''
  75. }
  76. if (!Object.keys(modes).includes(props.mode)) {
  77. console.warn(\`当前设置mode【\${props.mode}】不在【\${modes}】中,已默认为【right】\`)
  78. placement.value = 'right'
  79. }
  80. })
  81. const handClose = () => {
  82. emit('update:value', false)
  83. }
  84. const handConfirm = () => {
  85. emit('update:value', false)
  86. emit('confirm')
  87. }
  88. <\/script>
  89. <style lang="less" scoped>
  90. .s-drawer-wrap {
  91. max-height: calc(100vh - 4rpx);
  92. overflow: hidden;
  93. }
  94. .s-drawer-body {
  95. height: calc(100% - 60px);
  96. overflow: hidden auto;
  97. padding: 12px;
  98. box-sizing: border-box;
  99. }
  100. .s-drawer-footer {
  101. height: 60px;
  102. display: flex;
  103. justify-content: flex-end;
  104. align-items: center;
  105. border-top: 1px solid var(--s-border-color-split);
  106. padding: 0 12px;
  107. box-sizing: border-box;
  108. }
  109. </style>
  110. `;
  111. export {
  112. n as default
  113. };