share.vue 3.8 KB

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