2021-05-13 11:03:32 +08:00
|
|
|
|
<template>
|
|
|
|
|
<!-- 遮罩层 -->
|
|
|
|
|
<u-popup @close="close" v-model="show" mode="bottom" border-radius="30" height="260rpx">
|
|
|
|
|
|
|
|
|
|
<view class="share-title">
|
|
|
|
|
<span>分享至</span>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="share-list">
|
|
|
|
|
<!-- #ifdef MP-WEIXIN -->
|
|
|
|
|
<view class="share-item">
|
2022-08-25 18:25:45 +08:00
|
|
|
|
<button class="share-btn" @click="weChatShare" open-type="share">
|
2021-05-13 11:03:32 +08:00
|
|
|
|
<u-icon color="#04BE02" size="80" name="weixin-fill"></u-icon>微信好友
|
|
|
|
|
</button>
|
|
|
|
|
</view>
|
|
|
|
|
<!-- #endif -->
|
|
|
|
|
<!-- #ifdef APP-PLUS -->
|
|
|
|
|
<view class="share-item" @click="handleShare(item)" v-for="(item, index) in list" :key="index">
|
|
|
|
|
<u-icon :color="item.color" size="80" :name="item.icon"></u-icon>
|
|
|
|
|
<view>{{ item.title }}</view>
|
|
|
|
|
</view>
|
|
|
|
|
<!-- #endif -->
|
2022-08-25 18:25:45 +08:00
|
|
|
|
<!-- #ifdef H5 -->
|
2021-05-13 11:03:32 +08:00
|
|
|
|
<view class="share-item" @click="copyLink()">
|
|
|
|
|
<u-icon color="#b4aee8" size="80" name="share-fill"></u-icon>
|
|
|
|
|
<view>{{ '复制链接' }}</view>
|
|
|
|
|
</view>
|
|
|
|
|
<!-- #endif -->
|
|
|
|
|
</view>
|
|
|
|
|
</u-popup>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
2021-05-18 16:29:34 +08:00
|
|
|
|
import { h5Copy } from "@/js_sdk/h5-copy/h5-copy.js";
|
2021-05-13 11:03:32 +08:00
|
|
|
|
import configs from "@/config/config";
|
|
|
|
|
import mpShare from "uview-ui/libs/mixin/mpShare.js";
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
mixins: [mpShare],
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
configs,
|
|
|
|
|
show: true,
|
|
|
|
|
list: [
|
|
|
|
|
{
|
|
|
|
|
color: "#04BE02",
|
|
|
|
|
title: "微信好友",
|
|
|
|
|
icon: "weixin-fill",
|
|
|
|
|
type: 0,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
color: "#04BE02",
|
|
|
|
|
title: "朋友圈",
|
|
|
|
|
icon: "weixin-circle-fill",
|
|
|
|
|
type: 1,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
// 图片缩略图、 商品名称 、 type(goods,shop,pintuan) 拼团商品分享以及店铺分享
|
|
|
|
|
|
2021-05-18 16:29:34 +08:00
|
|
|
|
props: ["thumbnail", "goodsName", "type", "goodsId", "link"],
|
2021-05-13 11:03:32 +08:00
|
|
|
|
methods: {
|
|
|
|
|
close() {
|
|
|
|
|
this.$emit("close");
|
|
|
|
|
},
|
2022-08-25 18:25:45 +08:00
|
|
|
|
weChatShare(){
|
|
|
|
|
this.$u.mpShare = {
|
|
|
|
|
title: this.shareTitle(), // 默认为小程序名称,可自定义
|
|
|
|
|
path: '', // 默认为当前页面路径,一般无需修改,QQ小程序不支持
|
|
|
|
|
// 分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径。
|
|
|
|
|
// 支持PNG及JPG,默认为当前页面的截图
|
|
|
|
|
imageUrl: this.thumbnail ||''
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2021-05-13 11:03:32 +08:00
|
|
|
|
// h5复制链接
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
copyLink() {
|
2021-07-15 15:10:27 +08:00
|
|
|
|
let content;
|
|
|
|
|
if (this.link) {
|
|
|
|
|
content = this.configs.shareLink + this.link;
|
|
|
|
|
} else {
|
|
|
|
|
content =
|
|
|
|
|
this.configs.shareLink +
|
|
|
|
|
getCurrentPages()[getCurrentPages().length - 1].__page__.fullPath;
|
|
|
|
|
}
|
2023-01-29 18:14:53 +08:00
|
|
|
|
this.$options.filters.setClipboard(content)
|
2021-05-13 11:03:32 +08:00
|
|
|
|
},
|
|
|
|
|
// #endif
|
|
|
|
|
|
2021-08-27 17:54:52 +08:00
|
|
|
|
shareTitle() {
|
|
|
|
|
let shareTitle;
|
|
|
|
|
if (this.type == "goods") {
|
2022-08-25 18:25:45 +08:00
|
|
|
|
shareTitle = `[好友推荐]${this.goodsName}快来跟我一起看看吧`;
|
2021-08-27 17:54:52 +08:00
|
|
|
|
} else if (this.type == "shops") {
|
2022-08-25 18:25:45 +08:00
|
|
|
|
shareTitle = `[好友发现]${this.goodsName}快来跟我一起看看吧`;
|
2021-08-27 17:54:52 +08:00
|
|
|
|
} else if (this.type == "pintuan") {
|
2022-08-25 18:25:45 +08:00
|
|
|
|
shareTitle = `[好友邀请]${this.goodsName}快来跟我一起抢购吧!`;
|
2021-08-27 17:54:52 +08:00
|
|
|
|
} else if (this.type == "kanjia") {
|
2022-08-25 18:25:45 +08:00
|
|
|
|
shareTitle = `[好友邀请]请快来帮我砍一刀${this.goodsName}`;
|
2021-08-27 17:54:52 +08:00
|
|
|
|
}
|
|
|
|
|
return shareTitle;
|
|
|
|
|
},
|
|
|
|
|
|
2021-05-13 11:03:32 +08:00
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
handleShare(val) {
|
2021-08-27 17:54:52 +08:00
|
|
|
|
console.log("12312312")
|
2021-05-13 11:03:32 +08:00
|
|
|
|
if (val.type <= 1) {
|
|
|
|
|
let scene; // "WXSenceTimeline 朋友圈 WXSceneSession 微信好友"
|
|
|
|
|
val.type == 1
|
|
|
|
|
? (scene = "WXSenceTimeline")
|
|
|
|
|
: (scene = "WXSceneSession");
|
|
|
|
|
uni.share({
|
|
|
|
|
provider: "weixin",
|
|
|
|
|
scene: scene,
|
2021-06-18 16:04:43 +08:00
|
|
|
|
href: configs.shareLink + this.link,
|
2021-05-13 11:03:32 +08:00
|
|
|
|
imageUrl: this.thumbnail,
|
|
|
|
|
type: 0,
|
|
|
|
|
summary: this.goodsName,
|
2021-08-27 17:54:52 +08:00
|
|
|
|
title: this.shareTitle(),
|
2021-05-13 11:03:32 +08:00
|
|
|
|
success: function (res) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "分享成功!",
|
|
|
|
|
duration: 2000,
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
this.$emit("close");
|
|
|
|
|
},
|
|
|
|
|
fail: function (err) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "分享失败!",
|
|
|
|
|
duration: 2000,
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
this.$emit("close");
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// #endif
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
@import "./mp-share.scss";
|
|
|
|
|
.share-title {
|
|
|
|
|
position: relative;
|
|
|
|
|
height: 90rpx;
|
|
|
|
|
font-size: 32rpx;
|
|
|
|
|
line-height: 90rpx;
|
|
|
|
|
text-align: center;
|
|
|
|
|
> .share-close {
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: 0;
|
|
|
|
|
right: 20rpx;
|
|
|
|
|
top: 30rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
button:after {
|
|
|
|
|
border: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.share-list {
|
|
|
|
|
padding: 0 32rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
text-align: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
> .share-item {
|
|
|
|
|
width: 25%;
|
|
|
|
|
font-size: 24rpx;
|
|
|
|
|
color: #666;
|
|
|
|
|
> * {
|
|
|
|
|
margin: 8rpx 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|