share.vue 3.8 KB

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