tui-bubble-popup.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view :class="{ 'tui-flex-end': flexEnd }">
  3. <view class="tui-popup-list" :class="{ 'tui-popup-show': show,'tui-z_index':show && position!='relative' }" :style="{ width: width, backgroundColor: backgroundColor, borderRadius: radius, color: color, position: position, left: left, right: right, bottom: bottom, top: top,transform:`translate(${translateX},${translateY})` }">
  4. <view class="tui-triangle" :style="{
  5. borderWidth: borderWidth,
  6. borderColor: `transparent transparent ${backgroundColor} transparent`,
  7. left: triangleLeft,
  8. right: triangleRight,
  9. top: triangleTop,
  10. bottom: triangleBottom
  11. }"
  12. v-if="direction == 'top'"></view>
  13. <view class="tui-triangle" :style="{
  14. borderWidth: borderWidth,
  15. borderColor: `${backgroundColor} transparent transparent transparent`,
  16. left: triangleLeft,
  17. right: triangleRight,
  18. top: triangleTop,
  19. bottom: triangleBottom
  20. }"
  21. v-if="direction == 'bottom'"></view>
  22. <view class="tui-triangle" :style="{
  23. borderWidth: borderWidth,
  24. borderColor: `transparent ${backgroundColor} transparent transparent`,
  25. left: triangleLeft,
  26. right: triangleRight,
  27. top: triangleTop,
  28. bottom: triangleBottom
  29. }"
  30. v-if="direction == 'left'"></view>
  31. <view class="tui-triangle" :style="{
  32. borderWidth: borderWidth,
  33. borderColor: `transparent transparent transparent ${backgroundColor}`,
  34. left: triangleLeft,
  35. right: triangleRight,
  36. top: triangleTop,
  37. bottom: triangleBottom
  38. }"
  39. v-if="direction == 'right'"></view>
  40. <slot></slot>
  41. </view>
  42. <view @touchmove.stop.prevent="stop" class="tui-popup-mask" :class="{ 'tui-popup-show': show }" :style="{ backgroundColor: maskBgColor }"
  43. v-if="mask" @tap="handleClose"></view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. name: 'tuiBubblePopup',
  49. emits: ['close'],
  50. props: {
  51. //宽度
  52. width: {
  53. type: String,
  54. default: '300rpx'
  55. },
  56. //popup圆角
  57. radius: {
  58. type: String,
  59. default: '8rpx'
  60. },
  61. //popup 定位 left right top bottom值
  62. left: {
  63. type: String,
  64. default: 'auto'
  65. },
  66. right: {
  67. type: String,
  68. default: 'auto'
  69. },
  70. top: {
  71. type: String,
  72. default: 'auto'
  73. },
  74. bottom: {
  75. type: String,
  76. default: 'auto'
  77. },
  78. translateX:{
  79. type: String,
  80. default: '0'
  81. },
  82. translateY:{
  83. type: String,
  84. default: '0'
  85. },
  86. //背景颜色
  87. backgroundColor: {
  88. type: String,
  89. default: '#4c4c4c'
  90. },
  91. //字体颜色
  92. color: {
  93. type: String,
  94. default: '#fff'
  95. },
  96. //三角border-width
  97. borderWidth: {
  98. type: String,
  99. default: '12rpx'
  100. },
  101. //三角形方向 top left right bottom
  102. direction: {
  103. type: String,
  104. default: 'top'
  105. },
  106. //定位 left right top bottom值
  107. triangleLeft: {
  108. type: String,
  109. default: 'auto'
  110. },
  111. triangleRight: {
  112. type: String,
  113. default: 'auto'
  114. },
  115. triangleTop: {
  116. type: String,
  117. default: 'auto'
  118. },
  119. triangleBottom: {
  120. type: String,
  121. default: 'auto'
  122. },
  123. //定位 relative absolute fixed
  124. position: {
  125. type: String,
  126. default: 'fixed'
  127. },
  128. //flex-end
  129. flexEnd: {
  130. type: Boolean,
  131. default: false
  132. },
  133. //是否需要mask
  134. mask: {
  135. type: Boolean,
  136. default: true
  137. },
  138. maskBgColor: {
  139. type: String,
  140. default: 'rgba(0, 0, 0, 0.4)'
  141. },
  142. //控制显示
  143. show: {
  144. type: Boolean,
  145. default: false
  146. }
  147. },
  148. methods: {
  149. handleClose() {
  150. if (!this.show) {
  151. return;
  152. }
  153. this.$emit('close', {});
  154. },
  155. stop() {
  156. return false;
  157. }
  158. }
  159. };
  160. </script>
  161. <style scoped>
  162. .tui-popup-list {
  163. z-index: 1;
  164. transition: all 0.3s ease-in-out;
  165. opacity: 0;
  166. visibility: hidden;
  167. }
  168. .tui-flex-end {
  169. width: 100%;
  170. display: flex;
  171. justify-content: flex-end;
  172. }
  173. .tui-triangle {
  174. position: absolute;
  175. width: 0;
  176. height: 0;
  177. border-style: solid;
  178. z-index: 997;
  179. }
  180. .tui-popup-mask {
  181. position: fixed;
  182. top: 0;
  183. left: 0;
  184. right: 0;
  185. bottom: 0;
  186. z-index: 995;
  187. transition: all 0.3s ease-in-out;
  188. opacity: 0;
  189. visibility: hidden;
  190. }
  191. .tui-popup-show {
  192. opacity: 1;
  193. visibility: visible;
  194. }
  195. .tui-z_index {
  196. z-index: 996;
  197. }
  198. </style>