多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
6.5 KiB

2 years ago
  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. <!-- #ifdef APP-PLUS -->
  10. <view class="li" @click="share('weixin')">
  11. <image class="icon" src="../static/images/share/weixin2x.png"></image>
  12. <label class="label">微信</label>
  13. </view>
  14. <view class="li" @click="share('weixinpyq')">
  15. <image class="icon" src="../static/images/share/pyq.png"></image>
  16. <label class="label">朋友圈</label>
  17. </view>
  18. <!-- #endif -->
  19. <!-- #ifdef MP-WEIXIN -->
  20. <view class="li">
  21. <button open-type="share" @share='onShareAppMessage' :data-obj="wxShareData" class="share-button">
  22. <image class="icon" src="../static/images/share/forward.png"></image>
  23. <label class="label">好友</label>
  24. </button>
  25. </view>
  26. <view class="li" @click="share('weixinpyq')">
  27. <image class="icon" src="../static/images/share/pyq.png"></image>
  28. <label class="label">朋友圈</label>
  29. </view>
  30. <!-- #endif -->
  31. <view class="li" @click="share('lianjie')">
  32. <image class="icon" src="../static/images/share/lianjie.png"></image>
  33. <label class="label">链接</label>
  34. </view>
  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. 点击浏览器下方
  44. <view class="icon">
  45. <u-icon name="list" color="#fff" size="28"></u-icon>
  46. </view>
  47. 即可进行分享
  48. </view>
  49. </view>
  50. </u-popup>
  51. </div>
  52. </template>
  53. <script>
  54. import ClipboardJS from "clipboard"
  55. import UImage from "../uview-ui/components/u-image/u-image";
  56. const API = require('../config/api')
  57. export default {
  58. components: {UImage},
  59. props: {
  60. img: {
  61. type: String,
  62. default: ""
  63. },
  64. url: {
  65. type: String,
  66. dafault: ''
  67. },
  68. title: {
  69. type: String,
  70. dafault: ''
  71. },
  72. urlParms: {
  73. type: String,
  74. default: ''
  75. },
  76. },
  77. onShareAppMessage(e) {
  78. if(e.from=='button'){
  79. // 点击button
  80. }
  81. if(e.from=='menu'){
  82. // 点击右上角按钮
  83. }
  84. // 获取按钮传进来的参数 data 中的item值
  85. let params = e.target.dataset.obj// 获取的为 data 中定义的item值
  86. return {
  87. path: `/pages_category_page1/goodsModule/inviteSpell?${params.url}`
  88. }
  89. },
  90. name: "share",
  91. data() {
  92. return {
  93. shareShow: false,
  94. wapShow: false,
  95. wxShareData: {
  96. url: ''
  97. }
  98. // longUrl: ''
  99. };
  100. },
  101. mounted() {
  102. // this.longUrl = API.shareLink + '/#' + this.url
  103. // console.log(this.longUrl, this.url
  104. this.wxShareData = this.url
  105. },
  106. computed:{
  107. longUrl(){
  108. return API.shareLink + '/#' + this.url
  109. }
  110. },
  111. methods: {
  112. cancel(key) {
  113. if (key === 1) {
  114. this.shareShow = false
  115. this.$emit('shareCancel')
  116. } else if (key === 2) {
  117. this.wapShow = false
  118. }
  119. },
  120. wxShare(type) {
  121. // #ifdef APP-PLUS
  122. uni.share({
  123. provider: "weixin",
  124. type: 0,
  125. title: this.title,
  126. scene: type,//WXSceneSession会话 WXSceneTimeline朋友圈
  127. imageUrl: this.img,
  128. href: this.longUrl,
  129. success: () => {
  130. },
  131. fail: (err) => {
  132. console.log("err",err)
  133. }
  134. })
  135. // #endif
  136. // #ifdef MP-WEIXIN
  137. uni.showToast({
  138. title:"请点击右上角打开菜单进行朋友圈分享",
  139. icon:"none"
  140. })
  141. // #endif
  142. },
  143. share(key) {
  144. switch (key) {
  145. case 'weixin':
  146. this.wxShare("WXSceneSession")
  147. break
  148. case 'weixinpyq':
  149. this.wxShare("WXSceneTimeline")
  150. break
  151. case 'qq':
  152. break
  153. case 'weibo':
  154. break
  155. case 'lianjie':
  156. uni.setClipboardData({
  157. data: this.title + this.longUrl,
  158. success: () => {
  159. uni.showToast({
  160. title: '复制成功'
  161. })
  162. }
  163. })
  164. break
  165. }
  166. },
  167. //重写分享方法
  168. overShare: function () {
  169. //监听路由切换
  170. //间接实现全局设置分享内容
  171. wx.onAppRoute(function (res) {
  172. //获取加载的页面
  173. let pages = getCurrentPages(),
  174. //获取当前页面的对象
  175. view = pages[pages.length - 1],
  176. data;
  177. if (view) {
  178. data = view.data;
  179. console.log('是否重写分享方法', data.isOverShare);
  180. if (!data.isOverShare) {
  181. data.isOverShare = true;
  182. view.onShareAppMessage = function () {
  183. //你的分享配置
  184. return {
  185. title: '标题',
  186. path: '/pages/nearby/index'
  187. };
  188. }
  189. }
  190. }
  191. })
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. .share{
  198. background-color: #F8F8F8;
  199. text-align: center;
  200. .h3{
  201. font-size: 30rpx;
  202. color: #333333;
  203. line-height: 42rpx;
  204. padding: 30rpx 0;
  205. border-bottom: 2px solid #F0F0F0;
  206. display: block;
  207. }
  208. .share-list{
  209. padding: 40rpx 0 54rpx;
  210. .ul{
  211. display: flex;
  212. justify-content: space-around;
  213. .li{
  214. &::after {
  215. border: none;
  216. }
  217. .icon{
  218. display: block;
  219. width: 92rpx;
  220. height: 92rpx;
  221. }
  222. .label{
  223. padding-top: 22rpx;
  224. font-size: 24rpx;
  225. line-height: 34rpx;
  226. color: #333333;
  227. display: block;
  228. }
  229. }
  230. }
  231. }
  232. .btn-close{
  233. background-color: #fff;
  234. padding: 30rpx 0;
  235. font-size: 26rpx;
  236. color: #333;
  237. }
  238. }
  239. .share-h5{
  240. padding:0 20rpx;
  241. display: flex;
  242. justify-content: center;
  243. .text{
  244. line-height: 100rpx;
  245. font-size: 30px;
  246. .icon{
  247. background-color: #333;
  248. border-radius: 50%;
  249. display: inline-block;
  250. width: 40rpx;
  251. height: 40rpx;
  252. text-align: center;
  253. line-height: 40rpx;
  254. margin: 0 10rpx;
  255. }
  256. }
  257. }
  258. .share-button::after {
  259. border: none;
  260. }
  261. </style>