index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <!-- 遮罩层 -->
  3. <u-popup @close="close" v-model="show" mode="bottom" border-radius="30" height="260rpx">
  4. <view class="share-title">
  5. <span>分享至</span>
  6. </view>
  7. <view class="share-list">
  8. <!-- #ifdef MP-WEIXIN -->
  9. <view class="share-item">
  10. <button class="share-btn" open-type="share">
  11. <u-icon color="#04BE02" size="80" name="weixin-fill"></u-icon>微信好友
  12. </button>
  13. </view>
  14. <!-- #endif -->
  15. <!-- #ifdef APP-PLUS -->
  16. <view class="share-item" @click="handleShare(item)" v-for="(item, index) in list" :key="index">
  17. <u-icon :color="item.color" size="80" :name="item.icon"></u-icon>
  18. <view>{{ item.title }}</view>
  19. </view>
  20. <!-- #endif -->
  21. <!-- #ifdef H5 -->
  22. <view class="share-item" @click="copyLink()">
  23. <u-icon color="#b4aee8" size="80" name="share-fill"></u-icon>
  24. <view>{{ '复制链接' }}</view>
  25. </view>
  26. <!-- #endif -->
  27. </view>
  28. </u-popup>
  29. </template>
  30. <script>
  31. import { h5Copy } from "@/js_sdk/h5-copy/h5-copy.js";
  32. import configs from "@/config/config";
  33. import mpShare from "uview-ui/libs/mixin/mpShare.js";
  34. export default {
  35. mixins: [mpShare],
  36. data() {
  37. return {
  38. configs,
  39. show: true,
  40. list: [
  41. {
  42. color: "#04BE02",
  43. title: "微信好友",
  44. icon: "weixin-fill",
  45. type: 0,
  46. },
  47. {
  48. color: "#04BE02",
  49. title: "朋友圈",
  50. icon: "weixin-circle-fill",
  51. type: 1,
  52. },
  53. ],
  54. };
  55. },
  56. // 图片缩略图、 商品名称 、 type(goods,shop,pintuan) 拼团商品分享以及店铺分享
  57. props: ["thumbnail", "goodsName", "type", "goodsId", "link"],
  58. // #ifdef MP-WEIXIN
  59. onShareAppMessage(res) {
  60. return {
  61. imageUrl: this.thumbnail || require("@/static/logo.png"),
  62. };
  63. },
  64. // #endif
  65. methods: {
  66. close() {
  67. this.$emit("close");
  68. },
  69. // h5复制链接
  70. // #ifdef H5
  71. copyLink() {
  72. let content =
  73. this.configs.shareLink +
  74. getCurrentPages()[getCurrentPages().length - 1].__page__.fullPath;
  75. if (content === null || content === undefined) {
  76. content = "";
  77. } else content = content + "";
  78. const result = h5Copy(content);
  79. if (result === false) {
  80. uni.showToast({
  81. title: "不支持",
  82. });
  83. } else {
  84. uni.showToast({
  85. title: "复制成功",
  86. icon: "none",
  87. });
  88. }
  89. },
  90. // #endif
  91. // #ifdef APP-PLUS
  92. handleShare(val) {
  93. if (val.type <= 1) {
  94. let shareTitle;
  95. if (this.type == "goods") {
  96. shareTitle = `我发现了一个${this.goodsName}商品快来跟我一起看看吧`;
  97. } else if (this.type == "shops") {
  98. shareTitle = `我发现了一个${this.goodsName}店铺快来跟我一起看看吧`;
  99. } else if (this.type == "pintuan") {
  100. shareTitle = `我拼了一个${this.goodsName}快来跟我一起抢购吧!`;
  101. }
  102. let scene; // "WXSenceTimeline 朋友圈 WXSceneSession 微信好友"
  103. val.type == 1
  104. ? (scene = "WXSenceTimeline")
  105. : (scene = "WXSceneSession");
  106. uni.share({
  107. provider: "weixin",
  108. scene: scene,
  109. href: configs.shareLink + this.link,
  110. imageUrl: this.thumbnail,
  111. type: 0,
  112. summary: this.goodsName,
  113. title: shareTitle,
  114. success: function (res) {
  115. uni.showToast({
  116. title: "分享成功!",
  117. duration: 2000,
  118. icon: "none",
  119. });
  120. this.$emit("close");
  121. },
  122. fail: function (err) {
  123. uni.showToast({
  124. title: "分享失败!",
  125. duration: 2000,
  126. icon: "none",
  127. });
  128. this.$emit("close");
  129. },
  130. });
  131. }
  132. },
  133. // #endif
  134. },
  135. };
  136. </script>
  137. <style lang="scss" scoped>
  138. @import "./mp-share.scss";
  139. .share-title {
  140. position: relative;
  141. height: 90rpx;
  142. font-size: 32rpx;
  143. line-height: 90rpx;
  144. text-align: center;
  145. > .share-close {
  146. position: absolute;
  147. right: 0;
  148. right: 20rpx;
  149. top: 30rpx;
  150. }
  151. }
  152. button:after {
  153. border: none;
  154. }
  155. .share-list {
  156. padding: 0 32rpx;
  157. display: flex;
  158. text-align: center;
  159. align-items: center;
  160. > .share-item {
  161. width: 25%;
  162. font-size: 24rpx;
  163. color: #666;
  164. > * {
  165. margin: 8rpx 0;
  166. }
  167. }
  168. }
  169. </style>