share.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="content">
  3. <!-- <view class="share" @click="shareHy()">
  4. 分享给好友
  5. </view> -->
  6. <!-- <view class="share" @click="sharePyq()">
  7. 分享至朋友圈
  8. </view> -->
  9. <image class="img" :src=bgImg mode=""></image>
  10. <view class="share">
  11. <view class="share-left" @click="shareHy()">
  12. <view class="title">
  13. 分享好友
  14. </view>
  15. <image src="../../static/img/share04.png" mode=""></image>
  16. </view>
  17. <view class="share-right" @click="sharePyq()">
  18. <view class="title">
  19. 分享朋友圈
  20. </view>
  21. <image src="../../static/img/share05.png" mode=""></image>
  22. </view>
  23. </view>
  24. <view class="share-img" v-show="isShow">
  25. <image class="img-share" src="../../static/user/share-right.png" mode=""></image>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. // #ifndef APP-PLUS
  31. import {
  32. weixindata,shareFun
  33. } from '@/utils/wxAuthorized.js'
  34. // #endif
  35. import {
  36. mapState,
  37. mapMutations
  38. } from 'vuex';
  39. import {
  40. setShare,
  41. share
  42. } from '../../api/user.js'
  43. export default {
  44. data() {
  45. return {
  46. isShow:false,
  47. bgImg:'',//背景图片
  48. };
  49. },
  50. computed: {
  51. ...mapState('user', ['userInfo'])
  52. },
  53. onLoad() {
  54. this.IndexShare();
  55. },
  56. methods: {
  57. IndexShare() {
  58. //h5分享
  59. share().then(res => {
  60. const {
  61. link,
  62. title,
  63. synopsis,
  64. img,
  65. wechat_share_pic
  66. } = res.data.data
  67. this.bgImg = wechat_share_pic
  68. let shareList = {
  69. link: `${link}${this.userInfo.phone}`,
  70. imgUrl: img,
  71. desc: synopsis,
  72. title,
  73. success: function(){
  74. // alert("分享成功+++++")
  75. setShare().then(res => {
  76. setTimeout(function() {
  77. uni.switchTab({
  78. url: './user'
  79. })({
  80. })
  81. }, 1500)
  82. })
  83. console.log('分享加载成功')
  84. },
  85. cancel : function() {
  86. alert("取消分享");
  87. }
  88. }
  89. console.log('分享加', shareList);
  90. shareFun(shareList);
  91. })
  92. },
  93. //分享好友
  94. shareHy() {
  95. // #ifdef H5 || MP-WEIXIN
  96. this.isShow = true
  97. // #endif
  98. // #ifdef APP-PLUS
  99. share().then(res => {
  100. const {
  101. link,
  102. title,
  103. synopsis,
  104. img
  105. } = res.data.data
  106. //app分享好友
  107. uni.share({
  108. //分享类型
  109. provider: "weixin",
  110. //分享方式:好友,朋友圈,收藏
  111. scene: "WXSceneSession",
  112. //默认图文0
  113. type: 0,
  114. //跳转链接
  115. href: `${link}${this.userInfo.phone}`,
  116. //标题
  117. title,
  118. //主体
  119. summary: synopsis,
  120. //分享图片1
  121. imageUrl: img,
  122. success(res) {
  123. setShare().then(res => {
  124. setTimeout(function() {
  125. uni.switchTab({
  126. url: './user'
  127. })({
  128. })
  129. }, 1500)
  130. })
  131. },
  132. fail(err) {
  133. console.log(err, '失败原因');
  134. }
  135. })
  136. })
  137. // #endif
  138. },
  139. sharePyq() {
  140. share().then(res => {
  141. const {
  142. link,
  143. title,
  144. synopsis,
  145. img
  146. } = res.data.data
  147. // #ifdef H5 || MP-WEIXIN
  148. this.isShow = true
  149. // #endif
  150. // #ifdef APP-PLUS
  151. uni.share({
  152. provider: "weixin",
  153. scene: "WXSceneTimeline",
  154. type: 0,
  155. //跳转链接
  156. href: `${link}${this.userInfo.phone}`,
  157. //标题
  158. title,
  159. //主体
  160. summary: synopsis,
  161. //分享图片1
  162. imageUrl: img,
  163. success(res) {
  164. setShare().then(res => {
  165. setTimeout(function() {
  166. uni.switchTab({
  167. url: './user'
  168. })({
  169. })
  170. }, 1500)
  171. })
  172. },
  173. fail(err) {
  174. console.log(err, '失败原因');
  175. }
  176. });
  177. // #endif
  178. })
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. page,
  185. .content {
  186. position: relative;
  187. height: 100%;
  188. width: 750rpx;
  189. margin: 0;
  190. padding: 0;
  191. z-index: 99;
  192. .img {
  193. width: 750rpx;
  194. height: 100vh;
  195. }
  196. .share-img {
  197. z-index: 99;
  198. width: 750rpx;
  199. height: 100vh;
  200. position: absolute;
  201. top: 0;
  202. .img-share {
  203. width: 100%;
  204. height: 100%;
  205. }
  206. }
  207. .share {
  208. width: 100%;
  209. z-index: 9;
  210. display: flex;
  211. justify-content: space-around;
  212. position: absolute;
  213. bottom: 100rpx;
  214. .share-left {
  215. display: flex;
  216. justify-content: center;
  217. width: 300rpx;
  218. height: 100rpx;
  219. .title {
  220. position: absolute;
  221. z-index: 10;
  222. color: #FFFFFF;
  223. font-size: 30rpx;
  224. line-height: 100rpx;
  225. }
  226. image {
  227. width: 100%;
  228. height: 100%;
  229. }
  230. }
  231. .share-right {
  232. display: flex;
  233. justify-content: center;
  234. width: 300rpx;
  235. height: 100rpx;
  236. .title {
  237. position: absolute;
  238. z-index: 10;
  239. font-weight: 500;
  240. color: #FFFFFF;
  241. font-size: 30rpx;
  242. line-height: 100rpx;
  243. }
  244. image {
  245. width: 100%;
  246. height: 100%;
  247. }
  248. }
  249. }
  250. }
  251. </style>