From d2fe3a3bd81ce560f14649752f6ae99781313694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Mon, 1 Sep 2025 20:51:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(share):=20=E4=BC=98=E5=8C=96=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E5=88=86=E4=BA=AB=E5=8A=9F=E8=83=BD=E5=B9=B6=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=95=86=E5=93=81=E9=A1=B5=E5=88=86=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BestSellers 组件中移除商品分享逻辑,避免与首页分享冲突 - 在首页 index.tsx 中添加分享成功和失败的提示 - 更新 invite.ts 中的邀请信息解析逻辑,支持处理首页分享链接 --- src/pages/index/BestSellers.tsx | 26 ++------------------------ src/pages/index/index.tsx | 19 ++++++++++++++++--- src/utils/invite.ts | 22 +++++++++++++++++----- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/pages/index/BestSellers.tsx b/src/pages/index/BestSellers.tsx index a9c9322..b10a93f 100644 --- a/src/pages/index/BestSellers.tsx +++ b/src/pages/index/BestSellers.tsx @@ -51,30 +51,8 @@ const BestSellers = () => { 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 ( <> diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index cd2d9f3..3aee534 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -17,14 +17,27 @@ function Home() { const [stickyStatus, setStickyStatus] = useState(false) useShareAppMessage(() => { + // 获取当前用户ID,用于生成邀请链接 + const userId = Taro.getStorageSync('UserId'); + return { title: '网宿小店 - 网宿软件', - path: `/pages/index/index`, + path: userId ? `/pages/index/index?inviter=${userId}&source=share&t=${Date.now()}` : `/pages/index/index`, success: function () { - console.log('分享成功'); + console.log('首页分享成功'); + Taro.showToast({ + title: '分享成功', + icon: 'success', + duration: 2000 + }); }, fail: function () { - console.log('分享失败'); + console.log('首页分享失败'); + Taro.showToast({ + title: '分享失败', + icon: 'none', + duration: 2000 + }); } }; }); diff --git a/src/utils/invite.ts b/src/utils/invite.ts index bfb96e1..34975d6 100644 --- a/src/utils/invite.ts +++ b/src/utils/invite.ts @@ -65,11 +65,23 @@ export function parseInviteParams(options: any): InviteParams | null { } } - // 从 query 参数中解析邀请信息(兼容旧版本) - if (options.referrer) { - return { - inviter: options.referrer, - source: 'link' + // 从 query 参数中解析邀请信息(处理首页分享链接) + if (options.query) { + const query = options.query + if (query.inviter) { + return { + inviter: query.inviter, + source: query.source || 'share', + t: query.t + } + } + + // 兼容旧版本 + if (query.referrer) { + return { + inviter: query.referrer, + source: 'link' + } } }