shareF.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="content">
  3. <image src="http://xxl.liuniu946.com/static/image/share-bg.png" mode="" class="bg"></image>
  4. <view class="">
  5. </view>
  6. <view class="share-user-logo">
  7. <image :src="userlogo" mode=""></image>
  8. </view>
  9. <view class="good">
  10. <image src="http://xxl.liuniu946.com/static/image/good.png" mode=""></image>
  11. </view>
  12. <view class="good-tit">
  13. {{goodname}}
  14. </view>
  15. <!-- #ifdef MP-WEIXIN -->
  16. <button class="share-btn" open-type="share" v-if="couldshare == 1">
  17. 立即分享
  18. </button>
  19. <!-- #endif -->
  20. <!-- #ifdef H5 -->
  21. <button class="share-btn" open-type="share" v-if="couldshare == 1" @click="imgShare = true">
  22. 立即分享
  23. </button>
  24. <!-- #endif -->
  25. <view class="share-btn" v-if="couldshare == 2" @click="getGift">
  26. {{jsspan}}
  27. </view>
  28. <image src="../../static/img/shareimg.png" mode="" style="position: fixed;top:0;width: 750rpx;height: 100%;"
  29. v-if="imgShare" @click="imgShare = !imgShare">
  30. </image>
  31. </view>
  32. </template>
  33. <script>
  34. // #ifdef H5
  35. import {
  36. weixindata,
  37. shareLoad
  38. } from '@/utils/wxAuthorized';
  39. // #endif
  40. import {
  41. getGift
  42. } from '@/api/shop.js'
  43. export default {
  44. data() {
  45. return {
  46. code: '',
  47. imgShare: false,
  48. userlogo: '',
  49. shareId: '',
  50. nickname: '',
  51. goodimg: '',
  52. couldshare: 0,
  53. jsspan: '立即领取',
  54. goodname: ''
  55. }
  56. },
  57. onLoad(opt) {
  58. this.code = opt.code
  59. this.userlogo = opt.logo
  60. this.shareId = opt.shareid
  61. this.nickname = decodeURI(opt.nickname)
  62. this.couldshare = opt.type
  63. this.goodname = decodeURI(opt.goodname)
  64. // #ifdef MP
  65. if (opt.type == 2) {
  66. if (opt.scene) {
  67. // 存储小程序邀请人
  68. uni.setStorage({
  69. key: 'spread_code',
  70. data: opt.scene
  71. });
  72. }
  73. }
  74. // #endif
  75. // #ifdef H5
  76. this.IndexShare()
  77. // #endif
  78. },
  79. // 分享
  80. onShareAppMessage(options) {
  81. let obj = this
  82. // 设置菜单中的转发按钮触发转发事件时的转发内容
  83. let pages = getCurrentPages(); //获取加载的页面
  84. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  85. let url = currentPage.route; //当前页面url
  86. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  87. // let name = this.goodsObjact.store_name || this.goodsObjact.title;
  88. let shareObj = {
  89. title: obj.nickname + '分享您' + obj.goodname, // 默认是小程序的名称(可以写slogan等)
  90. path: url + '?code=' + obj.code + '&type=2' +
  91. '&logo=' + obj.userlogo +
  92. '&nickname=' + encodeURI(obj.nickname) + '&goodname=' + encodeURI(obj
  93. .goodname), // 默认是当前页面,必须是以‘/’开头的完整路径
  94. imageUrl: 'http://xxl.liuniu946.com/static/image/good.png',
  95. success: function(res) {
  96. console.log(shareObj.path, 'path+++++++++++++++++++');
  97. // 转发成功之后的回调
  98. if (res.errMsg == 'shareAppMessage:ok') {}
  99. },
  100. fail: function() {
  101. // 转发失败之后的回调
  102. if (res.errMsg == 'shareAppMessage:fail cancel') {
  103. // 用户取消转发
  104. } else if (res.errMsg == 'shareAppMessage:fail') {
  105. // 转发失败,其中 detail message 为详细失败信息
  106. }
  107. }
  108. };
  109. return shareObj;
  110. },
  111. methods: {
  112. // #ifdef H5
  113. IndexShare() {
  114. let obj = this;
  115. console.log(obj.Path);
  116. let data = {
  117. link: obj.$store.state.baseURL + '/index/#/pages/shop/shareF?code=' + obj.code + '&type=2' +
  118. '&logo=' + obj.userlogo +
  119. '&nickname=' + encodeURI(obj.nickname) + '&goodname=' + encodeURI(obj.goodname),
  120. desc: obj.nickname + '向您分享' + obj.goodname,
  121. title: '欢迎加入想亮',
  122. imgUrl: 'http://xxl.liuniu946.com/static/image/good.png',
  123. success() {
  124. console.log('分享加载完成')
  125. }
  126. };
  127. weixindata().then(wxOjb => {
  128. wxOjb.updateAppMessageShareData(data);
  129. // 分享朋友圈
  130. wxOjb.updateTimelineShareData(data)
  131. })
  132. // 保存邀请人
  133. console.log(data, '分享数据');
  134. // weixindata(data);
  135. },
  136. // #endif
  137. getGift() {
  138. let obj = this
  139. console.log('ddd')
  140. getGift({
  141. code: obj.code
  142. }).then(res => {
  143. console.log(res)
  144. uni.showToast({
  145. title: '领取成功',
  146. duration: 2000
  147. });
  148. obj.jsspan = '已领取'
  149. setTimeout(() => {
  150. uni.switchTab({
  151. url: '/pages/index/index'
  152. })
  153. }, 1500)
  154. }).catch(err => {
  155. console.log(err)
  156. })
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. page {
  163. background-color: #f32556;
  164. width: 100%;
  165. height: 100%
  166. }
  167. .content {
  168. position: relative;
  169. background-color: #f32556;
  170. min-height: 100%;
  171. .bg {
  172. // position: absolute;
  173. width: 750rpx;
  174. height: 1334rpx;
  175. }
  176. .share-btn {
  177. width: 492rpx;
  178. height: 86rpx;
  179. background-color: #ebd49e;
  180. border-radius: 43rpx;
  181. text-align: center;
  182. line-height: 86rpx;
  183. color: #901b21;
  184. font-weight: bold;
  185. font-size: 36rpx;
  186. position: absolute;
  187. top: 1159rpx;
  188. left: 130rpx;
  189. }
  190. .share-user-logo {
  191. position: absolute;
  192. top: 400rpx;
  193. left: 0;
  194. right: 0;
  195. margin: auto;
  196. width: 118rpx;
  197. height: 118rpx;
  198. border-radius: 50%;
  199. image {
  200. width: 118rpx;
  201. height: 118rpx;
  202. border-radius: 50%;
  203. }
  204. }
  205. .good {
  206. width: 290rpx;
  207. height: 290rpx;
  208. border-radius: 20rpx;
  209. position: absolute;
  210. top: 560rpx;
  211. left: 0;
  212. right: 0;
  213. margin: auto;
  214. image {
  215. width: 290rpx;
  216. height: 290rpx;
  217. border-radius: 20rpx;
  218. }
  219. }
  220. .good-tit {
  221. position: absolute;
  222. font-size: 32rpx;
  223. color: #901b21;
  224. text-align: center;
  225. width: 750rpx;
  226. top: 880rpx;
  227. }
  228. }
  229. </style>