index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: [
  58. "thumbnail",
  59. "goodsName",
  60. "type",
  61. "goodsId",
  62. "link",
  63. ],
  64. // #ifdef MP-WEIXIN
  65. onShareAppMessage(res) {
  66. return {
  67. imageUrl: this.thumbnail || require("@/static/logo.png"),
  68. };
  69. },
  70. // #endif
  71. methods: {
  72. close() {
  73. this.$emit("close");
  74. },
  75. // h5复制链接
  76. // #ifdef H5
  77. copyLink() {
  78. let content =
  79. this.configs.downloadLink +
  80. getCurrentPages()[getCurrentPages().length - 1].__page__.fullPath;
  81. if (content === null || content === undefined) {
  82. content = "";
  83. } else content = content + "";
  84. const result = h5Copy(content);
  85. if (result === false) {
  86. uni.showToast({
  87. title: "不支持",
  88. });
  89. } else {
  90. uni.showToast({
  91. title: "复制成功",
  92. icon: "none",
  93. });
  94. }
  95. },
  96. // #endif
  97. // #ifdef APP-PLUS
  98. handleShare(val) {
  99. if (val.type <= 1) {
  100. let shareTitle;
  101. if (this.type == "goods") {
  102. shareTitle = `我发现了一个${this.goodsName}商品快来跟我一起看看吧`;
  103. } else if (this.type == "shops") {
  104. shareTitle = `我发现了一个${this.goodsName}店铺快来跟我一起看看吧`;
  105. } else if (this.type == "pintuan") {
  106. shareTitle = `我拼了一个${this.goodsName}快来跟我一起抢购吧!`;
  107. }
  108. let scene; // "WXSenceTimeline 朋友圈 WXSceneSession 微信好友"
  109. val.type == 1
  110. ? (scene = "WXSenceTimeline")
  111. : (scene = "WXSceneSession");
  112. uni.share({
  113. provider: "weixin",
  114. scene: scene,
  115. href: configs.downloadLink + this.link,
  116. imageUrl: this.thumbnail,
  117. type: 0,
  118. summary: this.goodsName,
  119. title: shareTitle,
  120. success: function (res) {
  121. uni.showToast({
  122. title: "分享成功!",
  123. duration: 2000,
  124. icon: "none",
  125. });
  126. this.$emit("close");
  127. },
  128. fail: function (err) {
  129. uni.showToast({
  130. title: "分享失败!",
  131. duration: 2000,
  132. icon: "none",
  133. });
  134. this.$emit("close");
  135. },
  136. });
  137. }
  138. },
  139. // #endif
  140. },
  141. };
  142. </script>
  143. <style lang="scss" scoped>
  144. @import "./mp-share.scss";
  145. .share-title {
  146. position: relative;
  147. height: 90rpx;
  148. font-size: 32rpx;
  149. line-height: 90rpx;
  150. text-align: center;
  151. > .share-close {
  152. position: absolute;
  153. right: 0;
  154. right: 20rpx;
  155. top: 30rpx;
  156. }
  157. }
  158. button:after {
  159. border: none;
  160. }
  161. .share-list {
  162. padding: 0 32rpx;
  163. display: flex;
  164. text-align: center;
  165. align-items: center;
  166. > .share-item {
  167. width: 25%;
  168. font-size: 24rpx;
  169. color: #666;
  170. > * {
  171. margin: 8rpx 0;
  172. }
  173. }
  174. }
  175. </style>