refactor(share): 优化首页分享功能并移除商品页分享
- 在 BestSellers 组件中移除商品分享逻辑,避免与首页分享冲突 - 在首页 index.tsx 中添加分享成功和失败的提示 - 更新 invite.ts 中的邀请信息解析逻辑,支持处理首页分享链接
This commit is contained in:
@@ -51,30 +51,8 @@ const BestSellers = () => {
|
|||||||
reload()
|
reload()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// 分享给好友
|
// 注意:不在这里配置分享,避免与首页分享冲突
|
||||||
useShareAppMessage(() => {
|
// 商品分享应该在商品详情页处理,首页分享应该分享首页本身
|
||||||
return {
|
|
||||||
title: goods?.name || '精选商品',
|
|
||||||
path: `/shop/goodsDetail/index?id=${goods?.goodsId}`,
|
|
||||||
imageUrl: goods?.image, // 分享图片
|
|
||||||
success: function (res: any) {
|
|
||||||
console.log('分享成功', res);
|
|
||||||
Taro.showToast({
|
|
||||||
title: '分享成功',
|
|
||||||
icon: 'success',
|
|
||||||
duration: 2000
|
|
||||||
});
|
|
||||||
},
|
|
||||||
fail: function (res: any) {
|
|
||||||
console.log('分享失败', res);
|
|
||||||
Taro.showToast({
|
|
||||||
title: '分享失败',
|
|
||||||
icon: 'none',
|
|
||||||
duration: 2000
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -17,14 +17,27 @@ function Home() {
|
|||||||
const [stickyStatus, setStickyStatus] = useState<boolean>(false)
|
const [stickyStatus, setStickyStatus] = useState<boolean>(false)
|
||||||
|
|
||||||
useShareAppMessage(() => {
|
useShareAppMessage(() => {
|
||||||
|
// 获取当前用户ID,用于生成邀请链接
|
||||||
|
const userId = Taro.getStorageSync('UserId');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: '网宿小店 - 网宿软件',
|
title: '网宿小店 - 网宿软件',
|
||||||
path: `/pages/index/index`,
|
path: userId ? `/pages/index/index?inviter=${userId}&source=share&t=${Date.now()}` : `/pages/index/index`,
|
||||||
success: function () {
|
success: function () {
|
||||||
console.log('分享成功');
|
console.log('首页分享成功');
|
||||||
|
Taro.showToast({
|
||||||
|
title: '分享成功',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
},
|
},
|
||||||
fail: function () {
|
fail: function () {
|
||||||
console.log('分享失败');
|
console.log('首页分享失败');
|
||||||
|
Taro.showToast({
|
||||||
|
title: '分享失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -65,13 +65,25 @@ export function parseInviteParams(options: any): InviteParams | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 query 参数中解析邀请信息(兼容旧版本)
|
// 从 query 参数中解析邀请信息(处理首页分享链接)
|
||||||
if (options.referrer) {
|
if (options.query) {
|
||||||
|
const query = options.query
|
||||||
|
if (query.inviter) {
|
||||||
return {
|
return {
|
||||||
inviter: options.referrer,
|
inviter: query.inviter,
|
||||||
|
source: query.source || 'share',
|
||||||
|
t: query.t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兼容旧版本
|
||||||
|
if (query.referrer) {
|
||||||
|
return {
|
||||||
|
inviter: query.referrer,
|
||||||
source: 'link'
|
source: 'link'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user