This commit is contained in:
张成
2025-11-14 22:54:36 +08:00
parent 6b560da897
commit 0adab95d34
16 changed files with 171 additions and 42 deletions

View File

@@ -1,8 +1,9 @@
.back-navbar {
position: sticky;
position: fixed;
top: 0;
left: 0;
z-index: 100;
background: #ffffff;
background: transparent;
width: 100%;
box-sizing: border-box;

View File

@@ -40,7 +40,7 @@ const BackNavbar: React.FC<BackNavbarProps> = ({
style={{
paddingTop: `${statusBarHeight}px`,
height: `${totalHeight}px`,
backgroundColor: backgroundColor || "#fafafa"
backgroundColor: backgroundColor || "transparent"
}}
>
<View

View File

@@ -5,6 +5,6 @@
overflow: hidden;
z-index: 99;
width: 100%;
// 背景颜色通过 style 动态设置,默认透明
// 背景颜色通过 style 动态设置,默认 #FAFAFA
box-shadow: none;
}

View File

@@ -16,9 +16,9 @@ const CustomNavbar = (props: IProps) => {
<View
className={styles.customerNavbar}
style={{
height: `${navBarHeight}px`,
height: `${statusBarHeight + navBarHeight}px`,
paddingTop: `${statusBarHeight}px`,
backgroundColor: backgroundColor || '#fafafa'
backgroundColor: backgroundColor || 'transparent'
}}
>
{children}

View File

@@ -19,7 +19,8 @@
.leftSection {
display: flex;
align-items: center;
min-width: 60px;
gap: 8px;
flex: 1;
}
.centerSection {
@@ -27,6 +28,10 @@
display: flex;
justify-content: center;
align-items: center;
position: absolute;
left: 0;
right: 0;
pointer-events: none;
}
.rightSection {
@@ -39,7 +44,8 @@
font-size: 18px;
font-weight: 600;
color: #333;
text-align: center;
text-align: left;
pointer-events: auto;
}
.backIcon {

View File

@@ -15,6 +15,7 @@ interface GeneralNavbarProps {
showLeft?: boolean
onBack?: () => void
className?: string
titlePosition?: 'left' | 'center' // 标题位置:左侧或居中
}
const GeneralNavbar: React.FC<GeneralNavbarProps> = ({
@@ -22,11 +23,12 @@ const GeneralNavbar: React.FC<GeneralNavbarProps> = ({
titleStyle,
titleClassName = '',
leftContent,
backgroundColor = '#FAFAFA',
backgroundColor = 'transparent',
showBack = true,
showLeft = true,
onBack,
className = ''
className = '',
titlePosition = 'left' // 默认标题在左侧
}) => {
const { statusNavbarHeightInfo } = useGlobalState() || {}
const { statusBarHeight = 0, navBarHeight = 44, totalHeight = 98 } = statusNavbarHeightInfo || {}
@@ -35,7 +37,7 @@ const GeneralNavbar: React.FC<GeneralNavbarProps> = ({
if (onBack) {
onBack()
} else {
Taro.navigateBack()
(Taro as any).navigateBack()
}
}
@@ -82,20 +84,23 @@ const GeneralNavbar: React.FC<GeneralNavbarProps> = ({
style={{
height: `${totalHeight}px`,
paddingTop: `${statusBarHeight}px`,
backgroundColor: backgroundColor || '#FAFAFA'
backgroundColor: backgroundColor || 'transparent'
}}
>
<View className={styles.navbarContent} style={{ height: `${navBarHeight}px` }}>
<View className={styles.leftSection}>
{renderLeftContent()}
{titlePosition === 'left' && renderTitle()}
</View>
{titlePosition === 'center' && (
<View className={styles.centerSection}>
{renderTitle()}
</View>
)}
<View className={styles.rightSection}>
{/* 右侧占位,保持标题居中 */}
{/* 右侧占位 */}
</View>
</View>
</View>

View File

@@ -1,7 +1,6 @@
import React, { useState } from "react";
import { View, Text, Image } from "@tarojs/components";
import { View, Text } from "@tarojs/components";
import Taro from "@tarojs/taro";
import img from "@/config/images";
import { redirectTo } from "@/utils/navigation";
import "./index.scss";
import PublishMenu from "../PublishMenu";
export type currentPageType = "games" | "message" | "personal";
@@ -24,12 +23,6 @@ const GuideBar = (props) => {
},
];
const handlePublish = () => {
Taro.navigateTo({
url: "/publish_pages/publishBall/index",
});
};
const handlePageChange = (code: string) => {
if (code === currentPage) {
return;
@@ -52,7 +45,7 @@ const GuideBar = (props) => {
if (code === "list") {
url = "/game_pages/list/index"
}
Taro.redirectTo({
redirectTo({
url: url,
}).then(() => {
(Taro as any).pageScrollTo({

View File

@@ -4,6 +4,7 @@ import { useMemo } from "react";
import img from "../../config/images";
import { ListCardProps } from "../../../types/list/types";
import { formatGameTime, calculateDuration } from "@/utils/timeUtils";
import { navigateTo } from "@/utils/navigation";
import images from '@/config/images'
import "./index.scss";
@@ -50,7 +51,7 @@ const ListCard: React.FC<ListCardProps> = ({
};
const handleViewDetail = () => {
Taro.navigateTo({
navigateTo({
url: `/game_pages/detail/index?id=${id || 1}&from=list`,
});
};

View File

@@ -7,6 +7,7 @@ import {
EvaluateCallback,
EvaluateScene,
} from "@/store/evaluateStore";
import { navigateTo, redirectTo, navigateBack } from "@/utils/navigation";
import styles from "./index.module.scss";
import images from "@/config/images";
import AiImportPopup from "@/publish_pages/publishBall/components/AiImportPopup";
@@ -46,7 +47,7 @@ const PublishMenu: React.FC<PublishMenuProps> = (props) => {
setAiImportVisible(true);
return;
}
Taro.navigateTo({
navigateTo({
url: `/publish_pages/publishBall/index?type=${type}`,
});
};
@@ -58,16 +59,16 @@ const PublishMenu: React.FC<PublishMenuProps> = (props) => {
if (flag) {
handleMenuClick(type);
} else if (type === "ai") {
Taro.navigateBack();
navigateBack();
setAiImportVisible(true);
} else {
Taro.redirectTo({
redirectTo({
url: `/publish_pages/publishBall/index?type=${type}`,
});
}
},
onCancel: () => {
Taro.navigateBack();
navigateBack();
},
});
setIsVisible(false);
@@ -81,7 +82,7 @@ const PublishMenu: React.FC<PublishMenuProps> = (props) => {
};
const handleManualPublish = () => {
Taro.navigateTo({
navigateTo({
url: "/publish_pages/publishBall/index?type=individual",
});
};

View File

@@ -267,7 +267,8 @@ const OrderList = () => {
>
<GeneralNavbar
title="订单列表"
backgroundColor="transparent"
backgroundColor="#FAFAFA"
titlePosition="left"
titleClassName={styles.titleClassName}
className={styles.navbar}
/>

View File

@@ -11,7 +11,7 @@ import DistanceQuickFilter from "@/components/DistanceQuickFilter";
import { updateUserLocation } from "@/services/userService";
import { useUserActions } from "@/store/userStore";
import { useDictionaryStore } from "@/store/dictionaryStore";
import { saveImage } from "@/utils";
import { saveImage, navigateTo } from "@/utils";
export interface ListPageContentProps {
onNavStateChange?: (state: {
@@ -246,7 +246,7 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
};
const handleSearchClick = () => {
(Taro as any).navigateTo({
navigateTo({
url: "/game_pages/search/index",
});
};

View File

@@ -5,6 +5,7 @@ import noticeService from "@/services/noticeService";
import { formatRelativeTime } from "@/utils/timeUtils";
import Taro from "@tarojs/taro";
import { useGlobalState } from "@/store/global";
import { navigateTo } from "@/utils/navigation";
import "@/other_pages/message/index.scss";
interface MessageItem {
@@ -59,14 +60,14 @@ const MessagePageContent = () => {
const handleTabClick = (tab: MessageCategory) => {
if (tab === "comment") {
(Taro as any).navigateTo({
navigateTo({
url: "/other_pages/comment_reply/index",
});
return;
}
if (tab === "follow") {
(Taro as any).navigateTo({
navigateTo({
url: "/other_pages/new_follow/index",
});
return;
@@ -81,7 +82,7 @@ const MessagePageContent = () => {
return;
}
(Taro as any).navigateTo({
navigateTo({
url: message.jump_url,
}).catch(() => {
(Taro as any).showToast({

View File

@@ -21,15 +21,19 @@
top: 0;
left: 0;
opacity: 0;
transform: translateX(100%);
transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
transform: scale(0.98);
transition: opacity 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94),
transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
overflow-y: auto;
-webkit-overflow-scrolling: touch;
pointer-events: none;
will-change: opacity, transform;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
&.active {
opacity: 1;
transform: translateX(0);
transform: scale(1);
z-index: 1;
pointer-events: auto;
}

View File

@@ -235,7 +235,7 @@ const FollowPage: React.FC = () => {
return (
<View className="follow_page">
{/* 自定义导航栏 */}
<CustomNavbar>
<CustomNavbar backgroundColor="#FAFAFA">
<View className="navbar_content">
<View className="navbar_back" onClick={() => Taro.navigateBack()}>
<View className="back_icon" />

View File

@@ -10,3 +10,4 @@ export * from './routeUtil';
export * from './share'
export * from './genPoster'
export * from './wx_helper'
export * from './navigation';

115
src/utils/navigation.ts Normal file
View File

@@ -0,0 +1,115 @@
import Taro from "@tarojs/taro";
/**
* 导航工具函数 - 封装页面跳转,提供流畅的过渡效果
*/
interface NavigateOptions {
url: string;
success?: (res: any) => void;
fail?: (err: any) => void;
complete?: (res: any) => void;
}
/**
* 导航到新页面(带过渡动画)
* 使用 Taro.navigateTo系统会自动提供过渡动画
*/
export const navigateTo = (options: NavigateOptions): Promise<TaroGeneral.NavigateToSuccessCallbackResult> => {
return new Promise((resolve, reject) => {
(Taro as any).navigateTo({
...options,
success: (res: any) => {
options.success?.(res);
resolve(res);
},
fail: (err: any) => {
options.fail?.(err);
reject(err);
},
complete: (res: any) => {
options.complete?.(res);
},
});
});
};
/**
* 重定向到新页面(带过渡动画)
* 使用 Taro.redirectTo系统会自动提供过渡动画
*/
export const redirectTo = (options: NavigateOptions): Promise<TaroGeneral.NavigateToSuccessCallbackResult> => {
return new Promise((resolve, reject) => {
(Taro as any).redirectTo({
...options,
success: (res: any) => {
options.success?.(res);
resolve(res);
},
fail: (err: any) => {
options.fail?.(err);
reject(err);
},
complete: (res: any) => {
options.complete?.(res);
},
});
});
};
/**
* 返回上一页(带过渡动画)
*/
export const navigateBack = (options?: { delta?: number }): Promise<TaroGeneral.NavigateBackSuccessCallbackResult> => {
return new Promise((resolve, reject) => {
(Taro as any).navigateBack({
delta: options?.delta || 1,
success: (res: any) => {
resolve(res);
},
fail: (err: any) => {
reject(err);
},
});
});
};
/**
* 切换到 tabBar 页面(无过渡动画,这是 tabBar 的特性)
*/
export const switchTab = (options: { url: string }): Promise<TaroGeneral.SwitchTabSuccessCallbackResult> => {
return new Promise((resolve, reject) => {
Taro.switchTab({
...options,
success: (res: any) => {
resolve(res);
},
fail: (err: any) => {
reject(err);
},
});
});
};
/**
* 重新加载当前页面
*/
export const reLaunch = (options: NavigateOptions): Promise<TaroGeneral.ReLaunchSuccessCallbackResult> => {
return new Promise((resolve, reject) => {
(Taro as any).reLaunch({
...options,
success: (res: any) => {
options.success?.(res);
resolve(res);
},
fail: (err: any) => {
options.fail?.(err);
reject(err);
},
complete: (res: any) => {
options.complete?.(res);
},
});
});
};