生产管理系统 loading页面美化
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
import "@/styles/globals.css"
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { AuthProvider } from '@/components/auth/AuthContext';
|
import { AuthProvider } from '@/components/auth/AuthContext';
|
||||||
import { ClientAuthInterceptor } from '@/components/auth/ClientAuthInterceptor';
|
import { ClientAuthInterceptor } from '@/components/auth/ClientAuthInterceptor';
|
||||||
|
|||||||
@@ -1,30 +1,10 @@
|
|||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useAuth } from '@/components/auth/AuthContext';
|
|
||||||
import { LoadingScreen } from '@/components/auth/LoadingScreen';
|
|
||||||
import { redirect } from 'next/navigation';
|
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
const { user, loading, isAuthenticated } = useAuth();
|
|
||||||
|
|
||||||
// 如果正在加载,显示加载屏幕
|
|
||||||
if (loading) {
|
|
||||||
return <LoadingScreen />;
|
|
||||||
}
|
|
||||||
console.log('isAuthenticated:',isAuthenticated)
|
|
||||||
// 如果未认证,重定向到登录页
|
|
||||||
if (!isAuthenticated) {
|
|
||||||
redirect('/login');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果已认证,重定向到个人中心
|
|
||||||
if (isAuthenticated) {
|
|
||||||
redirect('/central-config/personal-center/personal-info');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 兜底显示(一般不会执行到这里)
|
|
||||||
return (
|
return (
|
||||||
<div></div>
|
<div>
|
||||||
|
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { useAuth } from './AuthContext';
|
import { useAuth } from './AuthContext';
|
||||||
|
import { LoadingScreen } from './loadingScreen';
|
||||||
|
|
||||||
interface ClientAuthInterceptorProps {
|
interface ClientAuthInterceptorProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -43,14 +44,7 @@ export function ClientAuthInterceptor({ children }: ClientAuthInterceptorProps)
|
|||||||
|
|
||||||
// 如果正在加载,显示加载状态
|
// 如果正在加载,显示加载状态
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return <LoadingScreen variant="auth" />;
|
||||||
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
|
||||||
<div className="text-center">
|
|
||||||
<div className="w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full animate-spin mb-4"></div>
|
|
||||||
<p className="text-gray-600">验证用户身份中...</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果在认证页面(包括 /login 开头的所有路径),直接渲染子组件,不需要认证检查
|
// 如果在认证页面(包括 /login 开头的所有路径),直接渲染子组件,不需要认证检查
|
||||||
@@ -60,14 +54,7 @@ export function ClientAuthInterceptor({ children }: ClientAuthInterceptorProps)
|
|||||||
|
|
||||||
// 如果未认证且不在认证页面,显示跳转状态
|
// 如果未认证且不在认证页面,显示跳转状态
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
return (
|
return <LoadingScreen variant="redirect" />;
|
||||||
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
|
||||||
<div className="text-center">
|
|
||||||
<div className="w-8 h-8 border-2 border-orange-500 border-t-transparent rounded-full animate-spin mb-4"></div>
|
|
||||||
<p className="text-gray-600">正在跳转到登录页...</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 认证通过,渲染子组件
|
// 认证通过,渲染子组件
|
||||||
|
|||||||
@@ -2,29 +2,49 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Loader2 } from 'lucide-react';
|
import { Loader2 } from 'lucide-react';
|
||||||
|
import { SmartFieldBackground } from './SmartFieldBackground';
|
||||||
|
|
||||||
interface LoadingScreenProps {
|
interface LoadingScreenProps {
|
||||||
message?: string;
|
message?: string;
|
||||||
|
subMessage?: string;
|
||||||
|
variant?: 'default' | 'auth' | 'redirect';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LoadingScreen({ message = '正在验证用户身份...' }: LoadingScreenProps) {
|
export function LoadingScreen({
|
||||||
|
message,
|
||||||
|
subMessage,
|
||||||
|
variant = 'default'
|
||||||
|
}: LoadingScreenProps) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
<div className="min-h-screen flex items-center justify-center relative overflow-hidden">
|
||||||
<div className="text-center">
|
{/* 智慧大田动态背景 - 使用登录页面相同的背景效果 */}
|
||||||
<div className="inline-flex items-center justify-center w-16 h-16 bg-green-100 rounded-full mb-4">
|
<SmartFieldBackground />
|
||||||
<Loader2 className="w-8 h-8 text-green-600 animate-spin" />
|
|
||||||
</div>
|
|
||||||
<h2 className="text-xl font-semibold text-gray-900 mb-2">智慧农业生产管理系统</h2>
|
|
||||||
<p className="text-gray-600">{message}</p>
|
|
||||||
|
|
||||||
{/* 加载进度条 */}
|
{/* 主要内容 */}
|
||||||
<div className="mt-6 w-64 h-2 bg-gray-200 rounded-full overflow-hidden">
|
<div className="relative z-10 text-center">
|
||||||
<div className="h-full bg-green-600 rounded-full animate-pulse" style={{ width: '60%' }}></div>
|
{/* 大型加载器 */}
|
||||||
|
<div className="relative inline-block">
|
||||||
|
{/* 外圈 */}
|
||||||
|
<div className="w-32 h-32 border-4 border-green-400/20 rounded-full animate-pulse"></div>
|
||||||
|
{/* 中圈 */}
|
||||||
|
<div className="absolute top-0 left-0 w-32 h-32 border-4 border-green-400/40 rounded-full animate-spin border-t-transparent border-r-transparent"></div>
|
||||||
|
{/* 内圈 */}
|
||||||
|
<div className="absolute top-4 left-4 w-24 h-24 border-4 border-green-400/60 rounded-full animate-spin border-t-transparent border-l-transparent" style={{ animationDirection: 'reverse' }}></div>
|
||||||
|
{/* 中心 */}
|
||||||
|
<div className="absolute top-12 left-12 w-8 h-8 bg-gradient-to-br from-green-400 to-emerald-400 rounded-full animate-pulse shadow-lg shadow-green-500/50">
|
||||||
|
<div className="w-full h-full bg-white rounded-full animate-ping opacity-30"></div>
|
||||||
|
</div>
|
||||||
|
{/* Loader2 */}
|
||||||
|
<div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
|
||||||
|
<Loader2 className="w-12 h-12 text-white/80 animate-spin" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 提示信息 */}
|
{/* 加载标题 */}
|
||||||
<div className="mt-8 text-sm text-gray-500 max-w-md">
|
<div className="mt-16">
|
||||||
<p>正在验证您的身份信息,请稍候...</p>
|
<p className="text-white/90 text-xl font-medium tracking-wide drop-shadow-lg">
|
||||||
|
正在加载智慧农业生产管理系统
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user