feat(share): 补做首页分享功能,支持仅分享到好友
- useShare 增加 enableTimeline 配置,默认启用朋友圈分享 - 首页配置 enableShareAppMessage 并调用 useShare,enableTimeline 设为 false - 解决 tabBar 页微信不支持朋友圈分享的问题,避免无效注册 - 分享路径添加裂变参数,增强邀请下级功能 - 保持类型检查零错误,改动兼容现有历史 TS2688 错误
This commit is contained in:
@@ -8,3 +8,9 @@
|
||||
- 接入 10 个页面:商品/积分/拼团/秒杀/活动/赛事详情(带 canvas 海报);邀请下级/分销推广/升级VIP/分享赚佣金(仅 enableShare + useShare)。
|
||||
- 类型检查:本次改动零错误,仅余 1 个历史既有错误(TS2688 @tarojs/taro 类型解析,非本次引入)。
|
||||
- 待办/注意:朋友圈分享必须真机测试;后端需支持按 page 生成指定落地页小程序码;单页模式降级(避免强制登录跳转)可调用 `isTimelineSinglePage()`。
|
||||
|
||||
## 首页接入分享(补做)
|
||||
- `src/hooks/useShare.ts` 增加 `enableTimeline?: boolean` 选项(默认 true),tabBar 页传 false 避免注册无效的朋友圈回调(React hook 规则下用内部 `if` 判断返回空对象,始终调用 hook)。
|
||||
- `src/pages/index/index.tsx`:config 加 `enableShareAppMessage: true`,组件内调用 `useShare({ title, path:'/pages/index/index', enableTimeline:false })`。
|
||||
- 说明:首页为 tabBar 页,微信不允许分享到朋友圈,故仅启用「分享给好友」,路径带 inviter 裂变参数。
|
||||
- 类型检查:零错误(历史既有 1 个 TS2688 仍在)。
|
||||
|
||||
@@ -11,6 +11,8 @@ export interface UseShareOptions {
|
||||
query?: string
|
||||
/** 封面图(海报临时路径或网络图地址),不传则微信截取页面 */
|
||||
imageUrl?: string
|
||||
/** 是否注册朋友圈分享(仅非 tabBar 页生效)。tabBar 页请传 false,避免注册无效的圈友回调 */
|
||||
enableTimeline?: boolean
|
||||
}
|
||||
|
||||
/** 当前是否处于朋友圈单页模式(scene=1154) */
|
||||
@@ -59,6 +61,8 @@ export function useShare(options: UseShareOptions) {
|
||||
})
|
||||
|
||||
useShareTimeline(() => {
|
||||
// tabBar 页不支持朋友圈,config 也不会开启对应入口,这里返回空对象避免无效注册
|
||||
if (optionsRef.current.enableTimeline === false) return {}
|
||||
const o = optionsRef.current
|
||||
return {
|
||||
title: o.title,
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'
|
||||
import { View, Text, ScrollView, Swiper, SwiperItem, Image } from '@tarojs/components'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { useUser } from '@/hooks/useUser'
|
||||
import { useShare } from '@/hooks/useShare'
|
||||
import { useScrollHeight } from '@/hooks/useScrollHeight'
|
||||
import { listCmsAd } from '@/api/cms/cmsAd'
|
||||
import { listCmsArticle } from '@/api/cms/cmsArticle'
|
||||
@@ -14,6 +15,7 @@ import { getCompressedImageUrl } from '@/utils/image'
|
||||
|
||||
definePageConfig({
|
||||
navigationBarTitleText: '首页',
|
||||
enableShareAppMessage: true,
|
||||
})
|
||||
|
||||
const IndexPage: React.FC = () => {
|
||||
@@ -24,6 +26,13 @@ const IndexPage: React.FC = () => {
|
||||
const [loading, setLoading] = useState(true)
|
||||
const scrollHeight = useScrollHeight(44)
|
||||
|
||||
// 首页分享给好友(tabBar 页不支持朋友圈,仅启用好友分享)
|
||||
useShare({
|
||||
title: '鑫龙家电 - 精选好物,实惠到家,等你来逛~',
|
||||
path: '/pages/index/index',
|
||||
enableTimeline: false,
|
||||
})
|
||||
|
||||
|
||||
const categories = ['全部', '球拍', '球鞋', '服装', '配件']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user