share.vue 3.7 KB

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