share.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div>
  3. <u-popup v-model="shareShow" :round="10" mode="bottom" @close="cancel(1)">
  4. <view class="share">
  5. <!-- <u-mask :show="true" class="flex-items-plus flex-row"> -->
  6. <text class="h3">邀请好友</text>
  7. <view class="share-list">
  8. <view class="ul">
  9. <!-- #ifndef MP -->
  10. <!-- #ifndef APP -->
  11. <view class="li" @click="share('weixin')">
  12. <image class="icon" src="../static/images/share/weixin2x.png"></image>
  13. <label class="label">微信</label>
  14. </view>
  15. <view class="li" @click="share('qq')">
  16. <image class="icon" src="../static/images/share/qq2x.png"></image>
  17. <label class="label">QQ</label>
  18. </view>
  19. <view class="li" @click="share('weibo')">
  20. <image class="icon" src="../static/images/share/weibo2x.png"></image>
  21. <label class="label">微博</label>
  22. </view>
  23. <!-- #endif -->
  24. <view class="li" @click="share('lianjie')">
  25. <image class="icon" src="../static/images/share/lianjie.png"></image>
  26. <label class="label">链接</label>
  27. </view>
  28. <!-- #endif -->
  29. <!-- #ifdef MP-WEIXIN -->
  30. <button class="li" open-type="share">
  31. <image class="icon" src="../static/images/forward.png"></image>
  32. <label class="label">转发</label>
  33. </button>
  34. <!-- #endif -->
  35. </view>
  36. </view>
  37. <view class="btn-close" @click="cancel(1)">取消</view>
  38. </view>
  39. </u-popup>
  40. <u-popup v-model="wapShow" :round="10" mode="bottom" :border-radius="10" @close="cancel(2)">
  41. <view class="share-h5">
  42. <view class="text">
  43. 点击浏览器下方<view class="icon"><u-icon name="list" color="#fff" size="28"></u-icon></view>即可进行分享
  44. </view>
  45. </view>
  46. </u-popup>
  47. </div>
  48. </template>
  49. <script>
  50. import ClipboardJS from "clipboard"
  51. import UImage from "../uview-ui/components/u-image/u-image";
  52. const API = require('../config/api')
  53. export default {
  54. components: {UImage},
  55. props:{
  56. url:{
  57. type:String,
  58. dafault:''
  59. }
  60. },
  61. name:"share",
  62. data() {
  63. return {
  64. shareShow: false,
  65. wapShow: false,
  66. longUrl: ''
  67. };
  68. },
  69. mounted () {
  70. this.longUrl = API.shareLink + '/#' + this.url
  71. console.log(this.longUrl,this.url)
  72. },
  73. methods:{
  74. cancel(key){
  75. if(key === 1){
  76. this.shareShow = false
  77. this.$emit('shareCancel')
  78. } else if(key === 2) {
  79. this.wapShow = false
  80. }
  81. },
  82. share(key){
  83. var desc = `推荐好文:看到一篇不错的文章,值得一看,推荐给大家。`
  84. console.log(this.url)
  85. // #ifdef H5
  86. this.shareShow = false
  87. this.wapShow = true
  88. // #endif
  89. // #ifdef APP
  90. switch (key) {
  91. case 'weixin':
  92. break
  93. case 'qq':
  94. break
  95. case 'weibo':
  96. break
  97. case 'lianjie':
  98. uni.setClipboardData({
  99. data: this.longUrl,
  100. success: () => {
  101. uni.showToast({
  102. title: '复制成功'
  103. })
  104. }
  105. })
  106. break
  107. }
  108. // #endif
  109. },
  110. //重写分享方法
  111. overShare: function () {
  112. //监听路由切换
  113. //间接实现全局设置分享内容
  114. wx.onAppRoute(function (res) {
  115. //获取加载的页面
  116. let pages = getCurrentPages(),
  117. //获取当前页面的对象
  118. view = pages[pages.length - 1],
  119. data;
  120. if (view) {
  121. data = view.data;
  122. console.log('是否重写分享方法', data.isOverShare);
  123. if (!data.isOverShare) {
  124. data.isOverShare = true;
  125. view.onShareAppMessage = function () {
  126. //你的分享配置
  127. return {
  128. title: '标题',
  129. path: '/pages/nearby/index'
  130. };
  131. }
  132. }
  133. }
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss">
  140. .share{
  141. background-color: #F8F8F8;
  142. text-align: center;
  143. .h3{
  144. font-size: 30rpx;
  145. color: #333333;
  146. line-height: 42rpx;
  147. padding: 30rpx 0;
  148. border-bottom: 2px solid #F0F0F0;
  149. display: block;
  150. }
  151. .share-list{
  152. padding: 40rpx 0 54rpx;
  153. .ul{
  154. display: flex;
  155. justify-content: space-around;
  156. .li{
  157. &::after {
  158. border: none;
  159. }
  160. .icon{
  161. display: block;
  162. width: 92rpx;
  163. height: 92rpx;
  164. }
  165. .label{
  166. padding-top: 22rpx;
  167. font-size: 24rpx;
  168. line-height: 34rpx;
  169. color: #333333;
  170. display: block;
  171. }
  172. }
  173. }
  174. }
  175. .btn-close{
  176. background-color: #fff;
  177. padding: 30rpx 0;
  178. font-size: 26rpx;
  179. color: #333;
  180. }
  181. }
  182. .share-h5{
  183. padding:0 20rpx;
  184. display: flex;
  185. justify-content: center;
  186. .text{
  187. line-height: 100rpx;
  188. font-size: 30px;
  189. .icon{
  190. background-color: #333;
  191. border-radius: 50%;
  192. display: inline-block;
  193. width: 40rpx;
  194. height: 40rpx;
  195. text-align: center;
  196. line-height: 40rpx;
  197. margin: 0 10rpx;
  198. }
  199. }
  200. }
  201. </style>