From 9791e76d17814af1ae8fe969b56b9c2024aeac82 Mon Sep 17 00:00:00 2001 From: peng Date: Mon, 3 Nov 2025 10:55:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E7=AE=A1=E7=90=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=20loading=E9=A1=B5=E9=9D=A2=E7=BE=8E=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crop-x/src/app/layout.tsx | 2 +- crop-x/src/app/page.tsx | 26 ++-------- .../components/auth/ClientAuthInterceptor.tsx | 19 ++------ crop-x/src/components/auth/LoadingScreen.tsx | 48 +++++++++++++------ 4 files changed, 41 insertions(+), 54 deletions(-) diff --git a/crop-x/src/app/layout.tsx b/crop-x/src/app/layout.tsx index d950d9e..c243284 100644 --- a/crop-x/src/app/layout.tsx +++ b/crop-x/src/app/layout.tsx @@ -1,5 +1,5 @@ 'use client'; - +import "@/styles/globals.css" import { useEffect } from 'react'; import { AuthProvider } from '@/components/auth/AuthContext'; import { ClientAuthInterceptor } from '@/components/auth/ClientAuthInterceptor'; diff --git a/crop-x/src/app/page.tsx b/crop-x/src/app/page.tsx index cd1c42b..3b1eca7 100644 --- a/crop-x/src/app/page.tsx +++ b/crop-x/src/app/page.tsx @@ -1,30 +1,10 @@ 'use client'; -import { useAuth } from '@/components/auth/AuthContext'; -import { LoadingScreen } from '@/components/auth/LoadingScreen'; -import { redirect } from 'next/navigation'; - export default function HomePage() { - const { user, loading, isAuthenticated } = useAuth(); - - // 如果正在加载,显示加载屏幕 - if (loading) { - return ; - } - console.log('isAuthenticated:',isAuthenticated) - // 如果未认证,重定向到登录页 - if (!isAuthenticated) { - redirect('/login'); - } - - // 如果已认证,重定向到个人中心 - if (isAuthenticated) { - redirect('/central-config/personal-center/personal-info'); - } - - // 兜底显示(一般不会执行到这里) return ( -
+
+ +
); } \ No newline at end of file diff --git a/crop-x/src/components/auth/ClientAuthInterceptor.tsx b/crop-x/src/components/auth/ClientAuthInterceptor.tsx index c7a057b..47f27f5 100644 --- a/crop-x/src/components/auth/ClientAuthInterceptor.tsx +++ b/crop-x/src/components/auth/ClientAuthInterceptor.tsx @@ -3,6 +3,7 @@ import { useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { useAuth } from './AuthContext'; +import { LoadingScreen } from './loadingScreen'; interface ClientAuthInterceptorProps { children: React.ReactNode; @@ -43,14 +44,7 @@ export function ClientAuthInterceptor({ children }: ClientAuthInterceptorProps) // 如果正在加载,显示加载状态 if (loading) { - return ( -
-
-
-

验证用户身份中...

-
-
- ); + return ; } // 如果在认证页面(包括 /login 开头的所有路径),直接渲染子组件,不需要认证检查 @@ -60,14 +54,7 @@ export function ClientAuthInterceptor({ children }: ClientAuthInterceptorProps) // 如果未认证且不在认证页面,显示跳转状态 if (!isAuthenticated) { - return ( -
-
-
-

正在跳转到登录页...

-
-
- ); + return ; } // 认证通过,渲染子组件 diff --git a/crop-x/src/components/auth/LoadingScreen.tsx b/crop-x/src/components/auth/LoadingScreen.tsx index 2185478..ccf8787 100644 --- a/crop-x/src/components/auth/LoadingScreen.tsx +++ b/crop-x/src/components/auth/LoadingScreen.tsx @@ -2,29 +2,49 @@ import React from 'react'; import { Loader2 } from 'lucide-react'; +import { SmartFieldBackground } from './SmartFieldBackground'; interface LoadingScreenProps { message?: string; + subMessage?: string; + variant?: 'default' | 'auth' | 'redirect'; } -export function LoadingScreen({ message = '正在验证用户身份...' }: LoadingScreenProps) { +export function LoadingScreen({ + message, + subMessage, + variant = 'default' +}: LoadingScreenProps) { return ( -
-
-
- -
-

智慧农业生产管理系统

-

{message}

+
+ {/* 智慧大田动态背景 - 使用登录页面相同的背景效果 */} + - {/* 加载进度条 */} -
-
+ {/* 主要内容 */} +
+ {/* 大型加载器 */} +
+ {/* 外圈 */} +
+ {/* 中圈 */} +
+ {/* 内圈 */} +
+ {/* 中心 */} +
+
+
+ {/* Loader2 */} +
+ +
- {/* 提示信息 */} -
-

正在验证您的身份信息,请稍候...

+ {/* 加载标题 */} +
+

+ 正在加载智慧农业生产管理系统 +