From a4da36ec08cade8d7f7ec97c43254a31f6e23045 Mon Sep 17 00:00:00 2001 From: xianyi Date: Fri, 26 Dec 2025 15:53:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E7=99=BB=E5=BD=95=E8=B0=83=E5=BC=B9?= =?UTF-8?q?=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/home/HomeSection.tsx | 25 +++++++++++++++++++++++++ src/components/modals/LoginModal.tsx | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/home/HomeSection.tsx b/src/components/home/HomeSection.tsx index 994bcc5..85445db 100644 --- a/src/components/home/HomeSection.tsx +++ b/src/components/home/HomeSection.tsx @@ -3,6 +3,7 @@ import { getRevenueStatistics, getTodayExamStatistics, getUserOwnedMenus, getB1S import type { OutputB1ServiceBoard, OutputNorth3ServiceBoard } from '../../api/types'; import { Card, CardContent, CardHeader, InfoCard } from '../ui'; import { cleanLocalStorageIfNeeded } from '../../utils/clean'; +import { LoginModal } from '../modals/LoginModal'; const APP_ID = 'b2b49e91d21446aeb14579930f732985'; @@ -30,6 +31,7 @@ export const HomeSection = () => { const [b1Loading, setB1Loading] = useState(false); const [north3Data, setNorth3Data] = useState(null); const [north3Loading, setNorth3Loading] = useState(false); + const [showLoginModal, setShowLoginModal] = useState(false); const currencyFormatter = useMemo(() => new Intl.NumberFormat('zh-CN', { style: 'currency', @@ -38,6 +40,14 @@ export const HomeSection = () => { maximumFractionDigits: 0, }), []); + // 检查登录状态 + useEffect(() => { + const accessToken = localStorage.getItem('accessToken'); + if (!accessToken) { + setShowLoginModal(true); + } + }, []); + useEffect(() => { // 清理本地存储 @@ -259,6 +269,21 @@ export const HomeSection = () => { + + {showLoginModal && ( + setShowLoginModal(false)} + onLoginSuccess={(payload) => { + // 保存登录信息 + localStorage.setItem('accessToken', payload.accessToken); + localStorage.setItem('refreshToken', payload.refreshToken); + localStorage.setItem('operatorId', payload.userId); + localStorage.setItem('operatorName', payload.userName || payload.username); + localStorage.setItem('operatorUsername', payload.username); + setShowLoginModal(false); + }} + /> + )} ); }; diff --git a/src/components/modals/LoginModal.tsx b/src/components/modals/LoginModal.tsx index 33fda7b..0faf954 100644 --- a/src/components/modals/LoginModal.tsx +++ b/src/components/modals/LoginModal.tsx @@ -107,7 +107,7 @@ export const LoginModal = ({ onClose, onLoginSuccess }: LoginModalProps) => { const canLogin = !!(username && password && imgCode && imgCodeKey && !loading); return ( -
+
e.stopPropagation()}