share.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view
  3. v-if="show"
  4. class="mask"
  5. @click="toggleMask"
  6. @touchmove.stop.prevent="stopPrevent"
  7. :style="{ backgroundColor: backgroundColor }"
  8. >
  9. <view
  10. class="mask-content"
  11. @click.stop.prevent="stopPrevent"
  12. :style="[
  13. {
  14. height: config.height,
  15. transform: transform
  16. }
  17. ]"
  18. >
  19. <scroll-view class="view-content" scroll-y>
  20. <view class="share-header"> 分享到 </view>
  21. <view class="share-list">
  22. <view
  23. v-for="(item, index) in shareList"
  24. :key="index"
  25. class="share-item"
  26. @click="shareToFriend(item.text)"
  27. >
  28. <image :src="item.icon" mode=""></image> <text>{{ item.text }}</text>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. <view class="bottom b-t" @click="toggleMask">取消</view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. transform: 'translateY(50vh)',
  41. timer: 0,
  42. backgroundColor: 'rgba(0,0,0,0)',
  43. show: false,
  44. config: {}
  45. }
  46. },
  47. props: {
  48. contentHeight: {
  49. type: Number,
  50. default: 0
  51. },
  52. //是否是tabbar页面
  53. hasTabbar: {
  54. type: Boolean,
  55. default: false
  56. },
  57. shareList: {
  58. type: Array,
  59. default: function() {
  60. return []
  61. }
  62. }
  63. },
  64. created() {
  65. const height = uni.upx2px(this.contentHeight) + 'px'
  66. this.config = {
  67. height: height,
  68. transform: `translateY(${height})`,
  69. backgroundColor: 'rgba(0,0,0,.4)'
  70. }
  71. this.transform = this.config.transform
  72. },
  73. methods: {
  74. toggleMask() {
  75. //防止高频点击
  76. if (this.timer == 1) {
  77. return
  78. }
  79. this.timer = 1
  80. setTimeout(() => {
  81. this.timer = 0
  82. }, 500)
  83. if (this.show) {
  84. this.transform = this.config.transform
  85. this.backgroundColor = 'rgba(0,0,0,0)'
  86. setTimeout(() => {
  87. this.show = false
  88. this.hasTabbar && uni.showTabBar()
  89. }, 200)
  90. return
  91. }
  92. this.show = true
  93. //等待mask重绘完成执行
  94. if (this.hasTabbar) {
  95. uni.hideTabBar({
  96. success: () => {
  97. setTimeout(() => {
  98. this.backgroundColor = this.config.backgroundColor
  99. this.transform = 'translateY(0px)'
  100. }, 10)
  101. }
  102. })
  103. } else {
  104. setTimeout(() => {
  105. this.backgroundColor = this.config.backgroundColor
  106. this.transform = 'translateY(0px)'
  107. }, 10)
  108. }
  109. },
  110. //防止冒泡和滚动穿透
  111. stopPrevent() {},
  112. //分享操作
  113. shareToFriend(type) {
  114. this.$api.msg(`分享给${type}`)
  115. this.toggleMask()
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss">
  121. .mask {
  122. position: fixed;
  123. left: 0;
  124. top: 0;
  125. right: 0;
  126. bottom: 0;
  127. display: flex;
  128. justify-content: center;
  129. align-items: flex-end;
  130. z-index: 998;
  131. transition: 0.3s;
  132. .bottom {
  133. position: absolute;
  134. left: 0;
  135. bottom: 0;
  136. display: flex;
  137. justify-content: center;
  138. align-items: center;
  139. width: 100%;
  140. height: 90upx;
  141. background: #fff;
  142. z-index: 9;
  143. font-size: $font-base + 2upx;
  144. color: $font-color-dark;
  145. }
  146. }
  147. .mask-content {
  148. width: 100%;
  149. height: 580upx;
  150. transition: 0.3s;
  151. background: #fff;
  152. &.has-bottom {
  153. padding-bottom: 90upx;
  154. }
  155. .view-content {
  156. height: 100%;
  157. }
  158. }
  159. .share-header {
  160. height: 110upx;
  161. font-size: $font-base + 2upx;
  162. color: font-color-dark;
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. padding-top: 10upx;
  167. &:before,
  168. &:after {
  169. content: '';
  170. width: 240upx;
  171. heighg: 0;
  172. border-top: 1px solid $border-color-base;
  173. transform: scaleY(0.5);
  174. margin-right: 30upx;
  175. }
  176. &:after {
  177. margin-left: 30upx;
  178. margin-right: 0;
  179. }
  180. }
  181. .share-list {
  182. display: flex;
  183. flex-wrap: wrap;
  184. }
  185. .share-item {
  186. min-width: 33.33%;
  187. display: flex;
  188. flex-direction: column;
  189. justify-content: center;
  190. align-items: center;
  191. height: 180upx;
  192. image {
  193. width: 80upx;
  194. height: 80upx;
  195. margin-bottom: 16upx;
  196. }
  197. text {
  198. font-size: $font-base;
  199. color: $font-color-base;
  200. }
  201. }
  202. </style>