tab回显页面 不显示动画效果

This commit is contained in:
ylj20011123 2025-09-11 10:47:33 +08:00
parent ea27a3213f
commit eae1bd2c18
2 changed files with 69 additions and 15 deletions

View File

@ -42,12 +42,28 @@ const PageTransition: React.FC<PageTransitionProps> = ({
}; };
// 简化版本 - 仅使用CSS动画 // 简化版本 - 仅使用CSS动画
export const SimplePageTransition: React.FC<{ children: React.ReactNode; className?: string }> = ({ export const SimplePageTransition: React.FC<{
children: React.ReactNode;
className?: string;
enableAnimation?: boolean;
onAnimationEnd?: () => void;
}> = ({
children, children,
className = '', className = '',
enableAnimation = true,
onAnimationEnd,
}) => { }) => {
const handleAnimationEnd = () => {
if (enableAnimation && onAnimationEnd) {
onAnimationEnd();
}
};
return ( return (
<div className={`simple-page-transition ${className}`}> <div
className={`${enableAnimation ? 'simple-page-transition' : ''} ${className}`}
onAnimationEnd={handleAnimationEnd}
>
{children} {children}
</div> </div>
); );

View File

@ -93,6 +93,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
const [activeKey, setActiveKey] = useState<string>(location?.pathname || '/') const [activeKey, setActiveKey] = useState<string>(location?.pathname || '/')
const [animatedPages, setAnimatedPages] = useState<Set<string>>(new Set());
const menuDataRef = useRef<MenuDataItem[]>([]); const menuDataRef = useRef<MenuDataItem[]>([]);
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
@ -141,6 +142,13 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
// 改变panes // 改变panes
const handleTabsPanes = (payload: any): void => { const handleTabsPanes = (payload: any): void => {
if (dispatch) { if (dispatch) {
// 检查是否为新页面
const isNewPage = !tabsPanes.some(tab => tab.path === payload.path);
if (isNewPage) {
// 标记新页面需要播放动画
setAnimatedPages(prev => new Set(prev).add(payload.path));
}
dispatch({ dispatch({
type: 'global/changeTabsRoutes', type: 'global/changeTabsRoutes',
payload: { data: payload, action: 'add' }, payload: { data: payload, action: 'add' },
@ -161,6 +169,13 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
history.push(nextkey || '/') history.push(nextkey || '/')
setActiveKey(nextkey) setActiveKey(nextkey)
// 从动画记录中移除关闭的页面
setAnimatedPages(prev => {
const newSet = new Set(prev);
newSet.delete(targetKey as string);
return newSet;
});
// 缓存路由栈数据 // 缓存路由栈数据
dispatch({ dispatch({
type: 'global/changeTabsRoutes', type: 'global/changeTabsRoutes',
@ -1007,6 +1022,13 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
break; break;
} }
// 从动画记录中移除关闭的页面
setAnimatedPages(prev => {
const newSet = new Set(prev);
closeTabKeys.forEach(key => newSet.delete(key));
return newSet;
});
dispatch({ dispatch({
type: 'global/changeTabsRoutes', type: 'global/changeTabsRoutes',
payload: { data: closeTabKeys, action: 'remove' }, payload: { data: closeTabKeys, action: 'remove' },
@ -1036,19 +1058,35 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
} }
moreIcon={<DoubleRightOutlined style={{ color: "#7b828c" }} />} moreIcon={<DoubleRightOutlined style={{ color: "#7b828c" }} />}
> >
{tabsPanes && tabsPanes.map((item: tabsRoute) => {tabsPanes && tabsPanes.map((item: tabsRoute) => {
const shouldAnimate = animatedPages.has(item.path);
return (
<TabPane <TabPane
tab={item.title} key={item?.path} tab={item.title}
style={{ padding: 24, paddingTop: 0 }}> key={item?.path}
<SimplePageTransition> style={{ padding: 24, paddingTop: 0 }}
>
<SimplePageTransition
enableAnimation={shouldAnimate}
onAnimationEnd={() => {
// 动画播放完成后,移除动画标记
setAnimatedPages(prev => {
const newSet = new Set(prev);
newSet.delete(item.path);
return newSet;
});
}}
>
<Suspense fallback={null}> <Suspense fallback={null}>
<Authorized authority={authorized!.authority} noMatch={noMatch}> <Authorized authority={authorized!.authority} noMatch={noMatch}>
{item.children} {item.children}
</Authorized> </Authorized>
</Suspense> </Suspense>
</SimplePageTransition> </SimplePageTransition>
</TabPane>) </TabPane>
} );
})}
</Tabs> </Tabs>
{/* 不要标签栏删除tabs的代码使用下方的代码就可以 */} {/* 不要标签栏删除tabs的代码使用下方的代码就可以 */}
{/* <Authorized authority={authorized!.authority} noMatch={noMatch}> {/* <Authorized authority={authorized!.authority} noMatch={noMatch}>