feat: 登陆注册UI调整,用户协议和隐私政策跳转调整

This commit is contained in:
zdl
2025-10-15 11:03:00 +08:00
parent 29816de72b
commit 4e9acd12c2
18 changed files with 3068 additions and 49 deletions

View File

@@ -1,11 +1,22 @@
// src/components/ProtectedRoute.js - Session版本
import React from 'react';
import { Navigate } from 'react-router-dom';
// src/components/ProtectedRoute.js - 弹窗拦截版本
import React, { useEffect } from 'react';
import { Box, VStack, Spinner, Text } from '@chakra-ui/react';
import { useAuth } from '../contexts/AuthContext';
import { useAuthModal } from '../contexts/AuthModalContext';
const ProtectedRoute = ({ children }) => {
const { isAuthenticated, isLoading, user } = useAuth();
const { openAuthModal, isAuthModalOpen } = useAuthModal();
// 记录当前路径,登录成功后可以跳转回来
const currentPath = window.location.pathname + window.location.search;
// 未登录时自动弹出认证窗口
useEffect(() => {
if (!isLoading && !isAuthenticated && !user && !isAuthModalOpen) {
openAuthModal(currentPath);
}
}, [isAuthenticated, user, isLoading, isAuthModalOpen, currentPath, openAuthModal]);
// 显示加载状态
if (isLoading) {
@@ -25,26 +36,26 @@ const ProtectedRoute = ({ children }) => {
);
}
// 记录当前路径,登录后可以回到这里
let currentPath = window.location.pathname + window.location.search;
let redirectUrl = `/auth/signin?redirect=${encodeURIComponent(currentPath)}`;
// 检查是否已登录
// 未登录时显示占位符(弹窗会自动打开)
if (!isAuthenticated || !user) {
return <Navigate to={redirectUrl} replace />;
return (
<Box
height="100vh"
display="flex"
alignItems="center"
justifyContent="center"
bg="gray.50"
>
<VStack spacing={4}>
<Spinner size="xl" color="blue.500" thickness="4px" />
<Text fontSize="lg" color="gray.600">请先登录...</Text>
</VStack>
</Box>
);
}
// 已登录,渲染子组件
// return children;
// 更新逻辑 如果 currentPath 是首页 登陆成功后跳转到个人中心
if (currentPath === '/' || currentPath === '/home') {
currentPath = '/profile';
redirectUrl = `/auth/signin?redirect=${encodeURIComponent(currentPath)}`;
return <Navigate to={redirectUrl} replace />;
} else { // 否则正常渲染
return children;
}
return children;
};
export default ProtectedRoute;
export default ProtectedRoute;