|
|
@@ -1,7 +1,7 @@
|
|
|
import { View, ScrollView, Text } from '@tarojs/components'
|
|
|
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
|
import { useState } from 'react'
|
|
|
-import Taro, { usePullDownRefresh , useReachBottom, useRouter} from '@tarojs/taro'
|
|
|
+import Taro, { usePullDownRefresh , useReachBottom, useRouter,useShareAppMessage, useShareTimeline} from '@tarojs/taro'
|
|
|
import { goodsClient } from '@/api'
|
|
|
import { InferResponseType } from 'hono'
|
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
|
@@ -28,6 +28,7 @@ export default function GoodsListPage() {
|
|
|
{ id: 'new', name: '新品' },
|
|
|
]
|
|
|
|
|
|
+
|
|
|
const {
|
|
|
data,
|
|
|
isLoading,
|
|
|
@@ -71,6 +72,46 @@ export default function GoodsListPage() {
|
|
|
// 合并所有分页数据
|
|
|
const allGoods = data?.pages.flatMap(page => page.data) || []
|
|
|
|
|
|
+ // 分享功能 - 分享给好友
|
|
|
+ useShareAppMessage(() => {
|
|
|
+ // 如果有商品数据,使用第一个商品的图片作为分享图片
|
|
|
+ const shareImageUrl = allGoods.length > 0 ? allGoods[0]?.imageFile?.fullUrl || '' : '';
|
|
|
+
|
|
|
+ // 构建分享标题
|
|
|
+ let shareTitle = '商品分类 - 发现好物';
|
|
|
+ if (searchKeyword) {
|
|
|
+ shareTitle = `搜索"${searchKeyword}" - 发现好物`;
|
|
|
+ } else if (categoryId) {
|
|
|
+ shareTitle = `商品分类 - 发现好物`;
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ title: shareTitle,
|
|
|
+ path: `/pages/goods-list/index?cateId=${encodeURIComponent(categoryId)}&keyword=${encodeURIComponent(searchKeyword)}&from=share`,
|
|
|
+ imageUrl: shareImageUrl
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 分享到朋友圈功能
|
|
|
+ useShareTimeline(() => {
|
|
|
+ // 朋友圈分享需要图片,使用第一个商品的图片
|
|
|
+ const shareImageUrl = allGoods.length > 0 ? allGoods[0]?.imageFile?.fullUrl || '' : '';
|
|
|
+
|
|
|
+ // 朋友圈分享标题
|
|
|
+ let shareTitle = '发现好物,快来选购!';
|
|
|
+ if (searchKeyword) {
|
|
|
+ shareTitle = `搜索"${searchKeyword}"发现的好物`;
|
|
|
+ } else if (categoryId) {
|
|
|
+ shareTitle = `精选商品,等你来选`;
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ title: shareTitle,
|
|
|
+ imageUrl: shareImageUrl,
|
|
|
+ query: `cateId=${encodeURIComponent(categoryId)}&keyword=${encodeURIComponent(searchKeyword)}&from=timeline`
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
// 使用Taro全局钩子 - 触底加载更多
|
|
|
useReachBottom(() => {
|
|
|
if (hasNextPage && !isFetchingNextPage) {
|