t-rt-popup.vue 2.6 KB

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