|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useState } from 'react';
|
|
|
+import React, { useState, useEffect } from 'react';
|
|
|
import { View } from '@tarojs/components';
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
import { goodsCategoryClient, advertisementClient } from '@/api';
|
|
|
@@ -26,6 +26,40 @@ const CategoryPage: React.FC = () => {
|
|
|
const [toastVisible, setToastVisible] = useState<boolean>(false);
|
|
|
const [toastMessage, setToastMessage] = useState<string>('');
|
|
|
|
|
|
+ // 动态设置导航栏和tabbar高度
|
|
|
+ useEffect(() => {
|
|
|
+ const setDynamicHeights = () => {
|
|
|
+ try {
|
|
|
+ // 获取窗口信息
|
|
|
+ const windowInfo = Taro.getWindowInfo();
|
|
|
+
|
|
|
+ // 计算导航栏高度(状态栏高度 + 导航栏高度)
|
|
|
+ // 状态栏高度已经是rpx单位,导航栏高度通常为88rpx
|
|
|
+ const navbarHeightRpx = windowInfo.statusBarHeight + 88;
|
|
|
+
|
|
|
+ // 计算tabbar高度(通常为100rpx)
|
|
|
+ const tabbarHeightRpx = 100; // 标准tabbar高度
|
|
|
+
|
|
|
+ // 设置CSS变量
|
|
|
+ const rootElement = document.documentElement;
|
|
|
+ if (rootElement) {
|
|
|
+ rootElement.style.setProperty('--navbar-height', `${navbarHeightRpx}rpx`);
|
|
|
+ rootElement.style.setProperty('--tabbar-height', `${tabbarHeightRpx}rpx`);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('设置动态高度失败:', error);
|
|
|
+ // 使用默认值作为fallback
|
|
|
+ const rootElement = document.documentElement;
|
|
|
+ if (rootElement) {
|
|
|
+ rootElement.style.setProperty('--navbar-height', '96rpx');
|
|
|
+ rootElement.style.setProperty('--tabbar-height', '100rpx');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ setDynamicHeights();
|
|
|
+ }, []);
|
|
|
+
|
|
|
// 获取分类数据
|
|
|
const { data: categoryData, isLoading, error } = useQuery({
|
|
|
queryKey: ['goods-categories'],
|