diff --git a/src/components/PublishMenu/index.module.scss b/src/components/PublishMenu/index.module.scss index a003d6f..00e6b68 100644 --- a/src/components/PublishMenu/index.module.scss +++ b/src/components/PublishMenu/index.module.scss @@ -206,13 +206,12 @@ box-sizing: border-box; font-weight: bold; line-height: 1; transform: rotate(45deg); - + transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1); } &.rotated { .closeIcon{ transform: rotate(90deg); } - } } diff --git a/src/container/listCustomNavbar/index.tsx b/src/container/listCustomNavbar/index.tsx index d982524..345d81a 100644 --- a/src/container/listCustomNavbar/index.tsx +++ b/src/container/listCustomNavbar/index.tsx @@ -19,6 +19,7 @@ interface IProps { leftIconClick?: () => void; }; onCityPickerVisibleChange?: (visible: boolean) => void; // 城市选择器显示/隐藏回调 + onScrollToTop?: () => void; // 滚动到顶部回调 } function CityPicker(props) { @@ -50,7 +51,7 @@ function CityPicker(props) { } const ListHeader = (props: IProps) => { - const { config, onCityPickerVisibleChange } = props; + const { config, onCityPickerVisibleChange, onScrollToTop } = props; const { showInput = false, inputLeftIcon, leftIconClick } = config || {}; const { getLocationLoading, statusNavbarHeightInfo } = useGlobalState(); const { gamesNum, searchValue, cities, area, updateArea, getMatchesData, fetchGetGamesCount, refreshBothLists } = useListState(); @@ -89,10 +90,16 @@ const ListHeader = (props: IProps) => { const handleLogoClick = () => { // 如果当前在列表页,点击后页面回到顶部 if (getCurrentFullPath() === "/game_pages/list/index") { - Taro.pageScrollTo({ - scrollTop: 0, - duration: 300, - }); + // 使用父组件传递的滚动方法(适配 ScrollView) + if (onScrollToTop) { + onScrollToTop(); + } else { + // 降级方案:使用页面滚动(兼容旧版本) + Taro.pageScrollTo({ + scrollTop: 0, + duration: 300, + }); + } } Taro.redirectTo({ url: "game_pages/list/index", // 列表页 diff --git a/src/game_pages/list/index.tsx b/src/game_pages/list/index.tsx index e7a9c07..e8dadef 100644 --- a/src/game_pages/list/index.tsx +++ b/src/game_pages/list/index.tsx @@ -63,6 +63,7 @@ const ListPage = () => { // 滚动相关状态 const scrollContextRef = useRef(null); + const scrollViewRef = useRef(null); // ScrollView 的 ref const scrollTimeoutRef = useRef(null); const lastScrollTopRef = useRef(0); const scrollDirectionRef = useRef<'up' | 'down' | null>(null); @@ -70,6 +71,7 @@ const ListPage = () => { const loadingMoreRef = useRef(false); // 防止重复加载更多 const scrollStartPositionRef = useRef(0); // 记录开始滚动的位置 const [showSearchBar, setShowSearchBar] = useState(true); // 控制搜索框显示/隐藏(筛选始终显示) + const [scrollTop, setScrollTop] = useState(0); // 控制 ScrollView 滚动位置 // 动态控制 GuideBar 的 z-index const [guideBarZIndex, setGuideBarZIndex] = useState<'low' | 'high'>('high'); @@ -92,6 +94,12 @@ const ListPage = () => { setIsCityPickerVisible(visible); }, []); + // 滚动到顶部的方法 + const scrollToTop = useCallback(() => { + // 使用一个唯一值触发 scrollTop 更新,确保每次都能滚动到顶部 + setScrollTop(prev => prev === 0 ? 0.1 : 0); + }, []); + // 监听所有弹窗和菜单的状态,动态调整 GuideBar 的 z-index useEffect(() => { if (isPublishMenuVisible) { @@ -432,6 +440,7 @@ const ListPage = () => { showInput: isShowInputCustomerNavBar, }} onCityPickerVisibleChange={handleCityPickerVisibleChange} + onScrollToTop={scrollToTop} /> {area_city !== "上海" ? ( renderCityQrcode() @@ -485,7 +494,9 @@ const ListPage = () => { {/* 可滚动的列表内容 */}