t-rt-popup.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view>
  3. <tui-bubble-popup :show="popupShow" @close="toggle" :maskBgColor="maskBgColor" right="8px" :top="popupTop"
  4. triangleRight="16px" triangleTop="-22rpx">
  5. <view class="tui-popup-item" :class="{ 'tui-start': index === 0, 'tui-last': index === itemList.length - 1 }"
  6. hover-class="tui-item-active" :hover-stay-time="150" @tap="handleClick(index)" v-for="(item, index) in itemList"
  7. :key="index">
  8. <tui-icon :name="item.icon" color="#fff" :size="40" unit="rpx" v-if="item.icon && !isImage"></tui-icon>
  9. <image :src="item.icon" v-if="item.icon && isImage" :style="{width:width,height:height}"></image>
  10. <text class="tui-bubble-popup_title">{{ item.title }}</text>
  11. </view>
  12. </tui-bubble-popup>
  13. </view>
  14. </template>
  15. <script>
  16. //右上角气泡弹层
  17. export default {
  18. name: 'tRtPopup',
  19. emits: ['click'],
  20. props: {
  21. //如果图标是image,则icon传入图片地址
  22. itemList: {
  23. type: Array,
  24. default: () => {
  25. return [{
  26. title: '关闭',
  27. icon: 'close'
  28. }];
  29. }
  30. },
  31. //遮罩背景色
  32. maskBgColor: {
  33. type: String,
  34. default: 'transparent'
  35. },
  36. //图标是否为图片
  37. isImage: {
  38. type: Boolean,
  39. default: false
  40. },
  41. //图标宽度
  42. width: {
  43. type: String,
  44. default: '40rpx'
  45. },
  46. //图标高度
  47. height: {
  48. type: String,
  49. default: '40rpx'
  50. },
  51. //当为自定义header时传值
  52. top: {
  53. type: String,
  54. default: ''
  55. }
  56. },
  57. watch: {
  58. top(val) {
  59. if (val) {
  60. // #ifndef H5
  61. this.popupTop = val
  62. // #endif
  63. }
  64. }
  65. },
  66. created() {
  67. // #ifdef H5
  68. this.popupTop = 44 + uni.upx2px(12) + 'px';
  69. // #endif
  70. // #ifndef H5
  71. if (this.top) {
  72. this.popupTop = this.top
  73. }
  74. // #endif
  75. },
  76. data() {
  77. return {
  78. popupShow: false,
  79. popupTop: '12rpx'
  80. };
  81. },
  82. methods: {
  83. handleClick(index) {
  84. this.$emit('click', {
  85. index: index
  86. });
  87. this.toggle()
  88. },
  89. toggle() {
  90. this.popupShow = !this.popupShow;
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss" scoped>
  96. .tui-popup-item {
  97. padding: 34rpx;
  98. display: flex;
  99. align-items: center;
  100. font-size: 32rpx;
  101. position: relative;
  102. &::after {
  103. content: '';
  104. position: absolute;
  105. border-bottom: 1rpx solid #888;
  106. -webkit-transform: scaleY(0.5);
  107. transform: sc8aleY(0.5);
  108. bottom: 0;
  109. right: 0;
  110. left: 38rpx;
  111. }
  112. .tui-bubble-popup_title {
  113. padding-left: $uni-spacing-row-base;
  114. }
  115. }
  116. .tui-start {
  117. border-top-left-radius: 8rpx;
  118. border-top-right-radius: 8rpx;
  119. }
  120. .tui-last {
  121. border-bottom-left-radius: 8rpx;
  122. border-bottom-right-radius: 8rpx;
  123. &::after {
  124. border-bottom: 0 !important;
  125. }
  126. }
  127. .tui-item-active {
  128. background-color: #444;
  129. }
  130. </style>