cm-drawer.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="cm-drawer">
  3. <view class="mask" v-if="visible" :style="[offsetSize, { zIndex: zIndex - 1 }]" @click="$emit('close')"></view>
  4. <view class="drawer-content" :class="[position]" :style="[offsetSize, { zIndex: zIndex }]">
  5. <uni-transition :mode-class="modeClass" :show="visible">
  6. <view class="content">
  7. <!-- 关闭弹框按钮 -->
  8. <view class="iconfont icon-iconfontguanbi close" @click="$emit('close')"></view>
  9. <view class="title" v-if="title">{{ title }}</view>
  10. <!-- 自定义插槽 -->
  11. <view><slot></slot></view>
  12. </view>
  13. </uni-transition>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'cm-drawer',
  20. props: {
  21. title: {
  22. type: String,
  23. default: ''
  24. },
  25. visible: {
  26. type: Boolean,
  27. default: false
  28. },
  29. position: {
  30. type: String,
  31. default: 'center'
  32. },
  33. offset: {
  34. type: Number,
  35. default: 0
  36. },
  37. zIndex: {
  38. type: Number,
  39. default: 99999
  40. }
  41. },
  42. computed: {
  43. offsetSize() {
  44. if (this.position === 'center' || this.offset === 0) {
  45. return {}
  46. }
  47. return {
  48. [this.position]: this.offset + 'rpx'
  49. }
  50. },
  51. modeClass() {
  52. let name = 'fade'
  53. switch (this.position) {
  54. case 'center':
  55. name = 'fade'
  56. break
  57. case 'top':
  58. name = 'slide-top'
  59. break
  60. case 'right':
  61. name = 'slide-right'
  62. break
  63. case 'bottom':
  64. name = 'slide-bottom'
  65. break
  66. case 'left':
  67. name = 'slide-left'
  68. break
  69. default:
  70. name = 'fade'
  71. break
  72. }
  73. return name
  74. }
  75. }
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. $drawer-size: 100rpx;
  80. .mask {
  81. position: fixed;
  82. bottom: 0;
  83. left: 0;
  84. width: 100%;
  85. height: 100%;
  86. background: rgba(0, 0, 0, 0.5);
  87. }
  88. .cm-drawer {
  89. .drawer-content {
  90. position: fixed;
  91. &.bottom {
  92. left: 0;
  93. bottom: 0;
  94. .content {
  95. border-radius: 16rpx 16rpx 0 0;
  96. }
  97. }
  98. &.top {
  99. top: 0;
  100. left: 0;
  101. .content {
  102. border-radius: 0 0 16rpx 16rpx;
  103. }
  104. }
  105. &.right {
  106. top: 0;
  107. right: 0;
  108. .content {
  109. border-radius: 16rpx 0 16rpx 0;
  110. }
  111. }
  112. &.left {
  113. top: 0;
  114. left: 0;
  115. .content {
  116. border-radius: 0 16rpx 16rpx 0;
  117. }
  118. }
  119. &.center {
  120. top: 50%;
  121. left: 50%;
  122. transform: translate(-50%, -50%);
  123. .content {
  124. width: 702rpx;
  125. min-height: 600rpx;
  126. max-height: 800rpx;
  127. overflow-y: scroll;
  128. border-radius: 16rpx;
  129. }
  130. }
  131. .content {
  132. position: relative;
  133. width: 750rpx;
  134. min-height: 180rpx;
  135. background: #fff;
  136. box-sizing: border-box;
  137. padding: 24rpx;
  138. .close {
  139. position: absolute;
  140. top: 26rpx;
  141. right: 26rpx;
  142. font-size: 34rpx;
  143. color: #b2b2b2;
  144. width: 60rpx;
  145. height: 60rpx;
  146. text-align: center;
  147. line-height: 60rpx;
  148. }
  149. .title {
  150. width: 100%;
  151. word-break: break-all;
  152. overflow: hidden;
  153. line-height: 50rpx;
  154. height: 50rpx;
  155. text-overflow: ellipsis;
  156. text-align: center;
  157. font-size: 34rpx;
  158. color: #333333;
  159. }
  160. }
  161. }
  162. }
  163. </style>