shareEx.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="content">
  3. <image src="../../static/img/share-card.jpg" mode="" class="bg"></image>
  4. <view class=""></view>
  5. <view class="share-user-logo"><image :src="userlogo" mode=""></image></view>
  6. <view class="good">
  7. {{ num }}
  8. <text>元</text>
  9. </view>
  10. <view class="good-tit">某娘鲜食红包</view>
  11. <button class="share-btn" open-type="share" v-if="couldshare == 1">立即分享</button>
  12. <view class="share-btn" v-if="couldshare == 2" @click="getGift">{{ jsspan }}</view>
  13. </view>
  14. </template>
  15. <script>
  16. import { getredbag } from '@/api/user.js';
  17. export default {
  18. data() {
  19. return {
  20. userlogo: '',
  21. shareId: '',
  22. nickname: '',
  23. num: '',
  24. couldshare: 0,
  25. jsspan: '立即领取'
  26. };
  27. },
  28. onLoad(opt) {
  29. this.userlogo = opt.logo;
  30. this.shareId = opt.shareid;
  31. this.nickname = opt.nickname;
  32. this.num = opt.num;
  33. this.couldshare = opt.type;
  34. // #ifdef MP
  35. if (opt.type == 2) {
  36. if (opt.scene) {
  37. // 存储小程序邀请人
  38. uni.setStorage({
  39. key: 'spread_code',
  40. data: opt.scene
  41. });
  42. }
  43. }
  44. // #endif
  45. },
  46. // 分享
  47. onShareAppMessage(options) {
  48. let obj = this;
  49. // 设置菜单中的转发按钮触发转发事件时的转发内容
  50. let pages = getCurrentPages(); //获取加载的页面
  51. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  52. let url = currentPage.route; //当前页面url
  53. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  54. // let name = this.goodsObjact.store_name || this.goodsObjact.title;
  55. let shareObj = {
  56. title: obj.nickname + '分享某娘鲜食红包', // 默认是小程序的名称(可以写slogan等)
  57. path: url + '?shareid=' + item.shareid + '&scene=' + item.scene + '&logo=' + item.logo + '&num=' + item.num + '&type=2' + '&nickname=' + item.nickname, // 默认是当前页面,必须是以‘/’开头的完整路径
  58. success: function(res) {
  59. console.log(shareObj.path, 'path+++++++++++++++++++');
  60. // 转发成功之后的回调
  61. if (res.errMsg == 'shareAppMessage:ok') {
  62. }
  63. },
  64. fail: function() {
  65. // 转发失败之后的回调
  66. if (res.errMsg == 'shareAppMessage:fail cancel') {
  67. // 用户取消转发
  68. } else if (res.errMsg == 'shareAppMessage:fail') {
  69. // 转发失败,其中 detail message 为详细失败信息
  70. }
  71. }
  72. };
  73. return shareObj;
  74. },
  75. methods: {
  76. getGift() {
  77. let obj = this;
  78. console.log('ddd');
  79. getredbag({}, this.shareId)
  80. .then(res => {
  81. console.log(res);
  82. uni.showToast({
  83. title: '领取成功',
  84. duration: 2000
  85. });
  86. obj.jsspan = '已领取';
  87. setTimeout(() => {
  88. uni.switchTab({
  89. url: '/pages/index/index'
  90. });
  91. }, 1500);
  92. })
  93. .catch(err => {
  94. console.log(err);
  95. });
  96. }
  97. }
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. page {
  102. background-color: #ffffff;
  103. width: 100%;
  104. height: 100%;
  105. }
  106. .content {
  107. position: relative;
  108. background-color: #ffffff;
  109. min-height: 100%;
  110. .bg {
  111. // position: absolute;
  112. width: 750rpx;
  113. height: 1334rpx;
  114. }
  115. .share-btn {
  116. width: 492rpx;
  117. height: 86rpx;
  118. background-color: #ebd49e;
  119. border-radius: 43rpx;
  120. text-align: center;
  121. line-height: 86rpx;
  122. color: #ee2f72;
  123. font-weight: bold;
  124. font-size: 36rpx;
  125. position: absolute;
  126. top: 1159rpx;
  127. left: 130rpx;
  128. }
  129. .share-user-logo {
  130. position: absolute;
  131. top: 400rpx;
  132. left: 0;
  133. right: 0;
  134. margin: auto;
  135. width: 118rpx;
  136. height: 118rpx;
  137. border-radius: 50%;
  138. image {
  139. width: 118rpx;
  140. height: 118rpx;
  141. border-radius: 50%;
  142. }
  143. }
  144. .good {
  145. border-radius: 20rpx;
  146. position: absolute;
  147. top: 560rpx;
  148. left: 0;
  149. right: 0;
  150. margin: auto;
  151. color: #eb5648;
  152. font-weight: bold;
  153. text-align: center;
  154. font-size: 160rpx;
  155. text {
  156. font-size: 80rpx;
  157. }
  158. }
  159. .good-tit {
  160. font-size: 40rpx;
  161. position: absolute;
  162. color: #eb5648;
  163. text-align: center;
  164. width: 750rpx;
  165. top: 800rpx;
  166. }
  167. }
  168. </style>