多租户商城-商户小程序端
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.

266 lines
6.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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="https://ceres.zkthink.com/static/img/share/weixin2x.png"></image>
  12. <label class="label">微信</label>
  13. </view>
  14. <view class="li" @click="share('weixinpyq')">
  15. <image class="icon" src="https://ceres.zkthink.com/static/img/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="https://ceres.zkthink.com/static/img/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="https://ceres.zkthink.com/static/img/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="https://ceres.zkthink.com/static/img/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. };
  99. },
  100. mounted() {
  101. this.wxShareData = this.url
  102. },
  103. computed:{
  104. longUrl(){
  105. return API.shareLink + '/#' + this.url
  106. }
  107. },
  108. methods: {
  109. cancel(key) {
  110. if (key === 1) {
  111. this.shareShow = false
  112. this.$emit('shareCancel')
  113. } else if (key === 2) {
  114. this.wapShow = false
  115. }
  116. },
  117. wxShare(type) {
  118. // #ifdef APP-PLUS
  119. uni.share({
  120. provider: "weixin",
  121. type: 0,
  122. title: this.title,
  123. scene: type,//WXSceneSession会话 WXSceneTimeline朋友圈
  124. imageUrl: this.img,
  125. href: this.longUrl,
  126. success: () => {
  127. },
  128. fail: (err) => {
  129. throw Error(err)
  130. }
  131. })
  132. // #endif
  133. // #ifdef MP-WEIXIN
  134. uni.showToast({
  135. title:"请点击右上角打开菜单进行朋友圈分享",
  136. icon:"none"
  137. })
  138. // #endif
  139. },
  140. share(key) {
  141. switch (key) {
  142. case 'weixin':
  143. this.wxShare("WXSceneSession")
  144. break
  145. case 'weixinpyq':
  146. this.wxShare("WXSceneTimeline")
  147. break
  148. case 'qq':
  149. break
  150. case 'weibo':
  151. break
  152. case 'lianjie':
  153. uni.setClipboardData({
  154. data: this.title + this.longUrl,
  155. success: () => {
  156. uni.showToast({
  157. title: '复制成功'
  158. })
  159. }
  160. })
  161. break
  162. }
  163. },
  164. //重写分享方法
  165. overShare: function () {
  166. //监听路由切换
  167. //间接实现全局设置分享内容
  168. wx.onAppRoute(function (res) {
  169. //获取加载的页面
  170. let pages = getCurrentPages(),
  171. //获取当前页面的对象
  172. view = pages[pages.length - 1],
  173. data;
  174. if (view) {
  175. data = view.data;
  176. if (!data.isOverShare) {
  177. data.isOverShare = true;
  178. view.onShareAppMessage = function () {
  179. //你的分享配置
  180. return {
  181. title: '标题',
  182. path: '/pages/nearby/index'
  183. };
  184. }
  185. }
  186. }
  187. })
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="scss">
  193. .share{
  194. background-color: #F8F8F8;
  195. text-align: center;
  196. .h3{
  197. font-size: 30rpx;
  198. color: #333333;
  199. line-height: 42rpx;
  200. padding: 30rpx 0;
  201. border-bottom: 2px solid #F0F0F0;
  202. display: block;
  203. }
  204. .share-list{
  205. padding: 40rpx 0 54rpx;
  206. .ul{
  207. display: flex;
  208. justify-content: space-around;
  209. .li{
  210. &::after {
  211. border: none;
  212. }
  213. .icon{
  214. display: block;
  215. width: 92rpx;
  216. height: 92rpx;
  217. }
  218. .label{
  219. padding-top: 22rpx;
  220. font-size: 24rpx;
  221. line-height: 34rpx;
  222. color: #333333;
  223. display: block;
  224. }
  225. }
  226. }
  227. }
  228. .btn-close{
  229. background-color: #fff;
  230. padding: 30rpx 0;
  231. font-size: 26rpx;
  232. color: #333;
  233. }
  234. }
  235. .share-h5{
  236. padding:0 20rpx;
  237. display: flex;
  238. justify-content: center;
  239. .text{
  240. line-height: 100rpx;
  241. font-size: 30px;
  242. .icon{
  243. background-color: #333;
  244. border-radius: 50%;
  245. display: inline-block;
  246. width: 40rpx;
  247. height: 40rpx;
  248. text-align: center;
  249. line-height: 40rpx;
  250. margin: 0 10rpx;
  251. }
  252. }
  253. }
  254. .share-button::after {
  255. border: none;
  256. }
  257. </style>