|
|
@@ -7,11 +7,10 @@ import CategorySidebarItem from '@/components/category/CategorySidebarItem';
|
|
|
import CategoryTabbar, { TabItem } from '@/components/category/CategoryTabbar';
|
|
|
import { Image } from '@/components/ui/image';
|
|
|
import TDesignToast from '@/components/tdesign/toast';
|
|
|
-import { navigateTo,useShareAppMessage } from '@tarojs/taro';
|
|
|
+import Taro,{ useRouter, navigateTo,useShareAppMessage,useShareTimeline } from '@tarojs/taro';
|
|
|
import { InferResponseType } from 'hono';
|
|
|
import { TabBarLayout } from '@/layouts/tab-bar-layout';
|
|
|
import { Navbar } from '@/components/ui/navbar';
|
|
|
-import Taro from '@tarojs/taro';
|
|
|
import TDesignIcon from '@/components/tdesign/icon';
|
|
|
import './index.css';
|
|
|
|
|
|
@@ -27,6 +26,13 @@ const CategoryPage: React.FC = () => {
|
|
|
const [toastVisible, setToastVisible] = useState<boolean>(false);
|
|
|
const [toastMessage, setToastMessage] = useState<string>('');
|
|
|
|
|
|
+
|
|
|
+ // 使用useRouter钩子获取路由参数
|
|
|
+ const router = useRouter()
|
|
|
+ const params = router.params
|
|
|
+ const goodsId = params?.id ? parseInt(params.id) : 0
|
|
|
+ const fromPage = params?.from || ''
|
|
|
+
|
|
|
// 动态设置导航栏和tabbar高度
|
|
|
useEffect(() => {
|
|
|
const setDynamicHeights = () => {
|
|
|
@@ -61,20 +67,33 @@ const CategoryPage: React.FC = () => {
|
|
|
setDynamicHeights();
|
|
|
}, []);
|
|
|
|
|
|
- // 分享功能
|
|
|
- useShareAppMessage(() => {
|
|
|
- // 如果有当前选中的分类,使用分类图片作为分享图片
|
|
|
- // 如果没有,使用默认图片或空字符串
|
|
|
- const shareImageUrl = currentCategory?.imageFile?.fullUrl ||
|
|
|
- subCategories?.[0]?.imageFile?.fullUrl ||
|
|
|
- '';
|
|
|
-
|
|
|
- return {
|
|
|
- title: currentCategory ? `${currentCategory.name} - 发现好物` : '商品分类 - 发现好物',
|
|
|
- path: `/pages/category/index?from=share`,
|
|
|
- imageUrl: shareImageUrl
|
|
|
- }
|
|
|
- })
|
|
|
+ // 分享功能
|
|
|
+ useShareAppMessage(() => {
|
|
|
+ // 如果有当前选中的分类,使用分类图片作为分享图片
|
|
|
+ // 如果没有,使用默认图片或空字符串
|
|
|
+ const shareImageUrl = currentCategory?.imageFile?.fullUrl ||
|
|
|
+ subCategories?.[0]?.imageFile?.fullUrl ||
|
|
|
+ '';
|
|
|
+
|
|
|
+ return {
|
|
|
+ title: currentCategory ? `${currentCategory.name} - 发现好物` : '商品分类 - 发现好物',
|
|
|
+ path: `/pages/category/index?from=share`,
|
|
|
+ imageUrl: shareImageUrl
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 分享到朋友圈功能
|
|
|
+ useShareTimeline(() => {
|
|
|
+ const shareImageUrl = currentCategory?.imageFile?.fullUrl ||
|
|
|
+ subCategories?.[0]?.imageFile?.fullUrl ||
|
|
|
+ '';
|
|
|
+
|
|
|
+ return {
|
|
|
+ title: currentCategory ? `${currentCategory.name} - 发现好物` : '商品分类 - 发现好物',
|
|
|
+ path: `/pages/category/index?from=share`,
|
|
|
+ imageUrl: shareImageUrl
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
// 获取分类数据
|
|
|
const { data: categoryData, isLoading, error } = useQuery({
|
|
|
@@ -189,7 +208,18 @@ const CategoryPage: React.FC = () => {
|
|
|
<Navbar
|
|
|
title="商品分类"
|
|
|
leftIcon=""
|
|
|
- onClickLeft={() => Taro.navigateBack()}
|
|
|
+ onClickLeft={() => {
|
|
|
+ // 根据来源页面决定返回逻辑
|
|
|
+ // 分享,返回首页
|
|
|
+ if (fromPage === 'share') {
|
|
|
+ Taro.switchTab({
|
|
|
+ url: `/pages/index/index`
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 从其他页面来的
|
|
|
+ Taro.navigateBack()
|
|
|
+ }
|
|
|
+ }}
|
|
|
rightIcon=""
|
|
|
onClickRight={() => {}}
|
|
|
/>
|