refactor(frontend): 重构状态管理使用Zustand替代Context API
feat(auth): 添加账户锁定功能及自动解锁机制 feat(user): 在用户模型中添加lockedUntil字段 feat(api): 实现账户锁定逻辑和剩余尝试次数提示 perf(3d): 优化3D场景状态管理性能 perf(floorplan): 优化平面图状态管理性能 chore(deps): 添加zustand依赖 chore(config): 更新安全配置锁定时间为3分钟 docs: 更新部分组件注释 style: 调整登录页面样式
This commit is contained in:
@@ -10,7 +10,7 @@ import { Canvas, useFrame, useThree } from '@react-three/fiber';
|
||||
import { OrbitControls, PerspectiveCamera, Environment } from '@react-three/drei';
|
||||
const envMapUrl = '/assets/3d/env.hdr';
|
||||
import RackModel from './RackModel';
|
||||
import { useScene3D } from '../../context/Scene3DContext';
|
||||
import { useScene3D } from '../../hooks/useScene3D';
|
||||
import * as THREE from 'three';
|
||||
import ErrorBoundary from '../ErrorBoundary';
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Zustand Store 初始化组件
|
||||
* 确保所有必要的 Store 在应用渲染前完成初始化
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
import { useConfigStore } from '../stores/configStore';
|
||||
import Spin from 'antd/es/spin';
|
||||
|
||||
const AuthInitializer = ({ children }) => {
|
||||
const [allInitialized, setAllInitialized] = useState(false);
|
||||
|
||||
const { initialize: initializeAuth, initialized: authInitialized } = useAuthStore();
|
||||
const { loadConfig, loading: configLoading } = useConfigStore();
|
||||
|
||||
useEffect(() => {
|
||||
const initStores = async () => {
|
||||
await initializeAuth();
|
||||
await loadConfig();
|
||||
};
|
||||
|
||||
initStores().then(() => {
|
||||
setAllInitialized(true);
|
||||
});
|
||||
}, [initializeAuth, loadConfig]);
|
||||
|
||||
if (!allInitialized) {
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
height: '100vh'
|
||||
}}>
|
||||
<Spin size="large" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
export default AuthInitializer;
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Navigate, useLocation } from 'react-router-dom';
|
||||
import { Spin } from 'antd';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { useAuth } from '../hooks/useAuth';
|
||||
|
||||
const ProtectedRoute = ({ children, requiredPermission }) => {
|
||||
const { user, token, loading, initialized } = useAuth();
|
||||
|
||||
Reference in New Issue
Block a user