feat(share): 补做首页分享功能,支持仅分享到好友
- useShare 增加 enableTimeline 配置,默认启用朋友圈分享 - 首页配置 enableShareAppMessage 并调用 useShare,enableTimeline 设为 false - 解决 tabBar 页微信不支持朋友圈分享的问题,避免无效注册 - 分享路径添加裂变参数,增强邀请下级功能 - 保持类型检查零错误,改动兼容现有历史 TS2688 错误
This commit is contained in:
@@ -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