tui-bubble-popup.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 />
  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. props: {
  50. //宽度
  51. width: {
  52. type: String,
  53. default: '300rpx'
  54. },
  55. //popup圆角
  56. radius: {
  57. type: String,
  58. default: '8rpx'
  59. },
  60. //popup 定位 left right top bottom值
  61. left: {
  62. type: String,
  63. default: 'auto'
  64. },
  65. right: {
  66. type: String,
  67. default: 'auto'
  68. },
  69. top: {
  70. type: String,
  71. default: 'auto'
  72. },
  73. bottom: {
  74. type: String,
  75. default: 'auto'
  76. },
  77. translateX:{
  78. type: String,
  79. default: '0'
  80. },
  81. translateY:{
  82. type: String,
  83. default: '0'
  84. },
  85. //背景颜色
  86. backgroundColor: {
  87. type: String,
  88. default: '#4c4c4c'
  89. },
  90. //字体颜色
  91. color: {
  92. type: String,
  93. default: '#fff'
  94. },
  95. //三角border-width
  96. borderWidth: {
  97. type: String,
  98. default: '12rpx'
  99. },
  100. //三角形方向 top left right bottom
  101. direction: {
  102. type: String,
  103. default: 'top'
  104. },
  105. //定位 left right top bottom值
  106. triangleLeft: {
  107. type: String,
  108. default: 'auto'
  109. },
  110. triangleRight: {
  111. type: String,
  112. default: 'auto'
  113. },
  114. triangleTop: {
  115. type: String,
  116. default: 'auto'
  117. },
  118. triangleBottom: {
  119. type: String,
  120. default: 'auto'
  121. },
  122. //定位 relative absolute fixed
  123. position: {
  124. type: String,
  125. default: 'fixed'
  126. },
  127. //flex-end
  128. flexEnd: {
  129. type: Boolean,
  130. default: false
  131. },
  132. //是否需要mask
  133. mask: {
  134. type: Boolean,
  135. default: true
  136. },
  137. maskBgColor: {
  138. type: String,
  139. default: 'rgba(0, 0, 0, 0.4)'
  140. },
  141. //控制显示
  142. show: {
  143. type: Boolean,
  144. default: false
  145. }
  146. },
  147. methods: {
  148. handleClose() {
  149. if (!this.show) {
  150. return;
  151. }
  152. this.$emit('close', {});
  153. },
  154. stop() {
  155. return false;
  156. }
  157. }
  158. };
  159. </script>
  160. <style scoped>
  161. .tui-popup-list {
  162. z-index: 1;
  163. transition: all 0.3s ease-in-out;
  164. opacity: 0;
  165. visibility: hidden;
  166. }
  167. .tui-flex-end {
  168. width: 100%;
  169. display: flex;
  170. justify-content: flex-end;
  171. }
  172. .tui-triangle {
  173. position: absolute;
  174. width: 0;
  175. height: 0;
  176. border-style: solid;
  177. z-index: 997;
  178. }
  179. .tui-popup-mask {
  180. position: fixed;
  181. top: 0;
  182. left: 0;
  183. right: 0;
  184. bottom: 0;
  185. z-index: 995;
  186. transition: all 0.3s ease-in-out;
  187. opacity: 0;
  188. visibility: hidden;
  189. }
  190. .tui-popup-show {
  191. opacity: 1;
  192. visibility: visible;
  193. }
  194. .tui-z_index {
  195. z-index: 996;
  196. }
  197. </style>