share.vue 4.7 KB

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