|
@@ -38,11 +38,10 @@
|
|
|
default: '分享标题'
|
|
default: '分享标题'
|
|
|
},
|
|
},
|
|
|
// type=0: 图文分享(需要 title + summary + imageUrl)
|
|
// type=0: 图文分享(需要 title + summary + imageUrl)
|
|
|
- // type=1: 纯图片分享(只需要 imageUrl)
|
|
|
|
|
- // type=2: 链接分享(需要 title + summary + href + imageUrl)
|
|
|
|
|
|
|
+ // type=2: 纯图片分享(只需要 imageUrl)
|
|
|
type: {
|
|
type: {
|
|
|
- type: String,
|
|
|
|
|
- default: "0" // 0:图文
|
|
|
|
|
|
|
+ type: [String, Number],
|
|
|
|
|
+ default: 0 // 0:图文
|
|
|
},
|
|
},
|
|
|
// 分享描述
|
|
// 分享描述
|
|
|
desc: {
|
|
desc: {
|
|
@@ -95,15 +94,14 @@
|
|
|
|
|
|
|
|
// 分享到微信
|
|
// 分享到微信
|
|
|
const shareToWeChat = (scene) => {
|
|
const shareToWeChat = (scene) => {
|
|
|
- console.log('props.link',props.link);
|
|
|
|
|
- uni.share({
|
|
|
|
|
|
|
+ // 获取分享类型,确保是数字类型
|
|
|
|
|
+ const shareType = Number(props.type)
|
|
|
|
|
+
|
|
|
|
|
+ // 构建基础分享配置
|
|
|
|
|
+ const shareConfig = {
|
|
|
provider: 'weixin',
|
|
provider: 'weixin',
|
|
|
scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
|
|
scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
|
|
|
- type: Number(props.type),
|
|
|
|
|
- title: props.title,
|
|
|
|
|
- summary: props.desc,
|
|
|
|
|
- href: props.link,
|
|
|
|
|
- imageUrl: props.image || 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png',
|
|
|
|
|
|
|
+ type: shareType,
|
|
|
success: function(res) {
|
|
success: function(res) {
|
|
|
emit('success', {
|
|
emit('success', {
|
|
|
scene
|
|
scene
|
|
@@ -113,10 +111,47 @@
|
|
|
emit('error', err)
|
|
emit('error', err)
|
|
|
handleShareError(err)
|
|
handleShareError(err)
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ // 根据类型添加不同的参数
|
|
|
|
|
+ if (shareType == 2) {
|
|
|
|
|
+ // 纯图片分享
|
|
|
|
|
+ shareConfig.imageUrl = props.image
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 图文或链接分享(兼容原有逻辑)
|
|
|
|
|
+ shareConfig.title = props.title
|
|
|
|
|
+ shareConfig.summary = props.desc
|
|
|
|
|
+ shareConfig.imageUrl = props.image
|
|
|
|
|
+ shareConfig.href = props.link
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log('分享配置:', shareConfig)
|
|
|
|
|
+ uni.share(shareConfig)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ // const shareToWeChat = (scene) => {
|
|
|
|
|
+ // console.log('props.link',props.link);
|
|
|
|
|
+ // uni.share({
|
|
|
|
|
+ // provider: 'weixin',
|
|
|
|
|
+ // scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
|
|
|
|
|
+ // type: Number(props.type),
|
|
|
|
|
+ // title: props.title,
|
|
|
|
|
+ // summary: props.desc,
|
|
|
|
|
+ // href: props.link,
|
|
|
|
|
+ // imageUrl: props.image || 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png',
|
|
|
|
|
+ // success: function(res) {
|
|
|
|
|
+ // emit('success', {
|
|
|
|
|
+ // scene
|
|
|
|
|
+ // })
|
|
|
|
|
+ // },
|
|
|
|
|
+ // fail: function(err) {
|
|
|
|
|
+ // emit('error', err)
|
|
|
|
|
+ // handleShareError(err)
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// 错误处理
|
|
// 错误处理
|
|
|
const handleShareError = (error) => {
|
|
const handleShareError = (error) => {
|
|
|
console.error('分享失败:', error)
|
|
console.error('分享失败:', error)
|