未登录调弹窗

This commit is contained in:
xianyi
2025-12-26 15:53:27 +08:00
parent 9356eda863
commit a4da36ec08
2 changed files with 26 additions and 1 deletions

View File

@@ -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<OutputNorth3ServiceBoard | null>(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 = () => {
</CardContent>
</Card>
</div>
{showLoginModal && (
<LoginModal
onClose={() => 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);
}}
/>
)}
</div>
);
};

View File

@@ -107,7 +107,7 @@ export const LoginModal = ({ onClose, onLoginSuccess }: LoginModalProps) => {
const canLogin = !!(username && password && imgCode && imgCodeKey && !loading);
return (
<div className='fixed inset-0 z-50 flex items-center justify-center bg-black/30' onClick={onClose}>
<div style={{ marginTop: '0' }} className='fixed inset-0 z-50 flex items-center justify-center bg-black/30 h-screen' onClick={onClose}>
<div
className='w-[480px] max-w-[95vw] bg-white rounded-3xl shadow-xl overflow-hidden text-sm'
onClick={(e) => e.stopPropagation()}