share.vue 4.8 KB

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