未登录调弹窗
This commit is contained in:
@@ -3,6 +3,7 @@ import { getRevenueStatistics, getTodayExamStatistics, getUserOwnedMenus, getB1S
|
|||||||
import type { OutputB1ServiceBoard, OutputNorth3ServiceBoard } from '../../api/types';
|
import type { OutputB1ServiceBoard, OutputNorth3ServiceBoard } from '../../api/types';
|
||||||
import { Card, CardContent, CardHeader, InfoCard } from '../ui';
|
import { Card, CardContent, CardHeader, InfoCard } from '../ui';
|
||||||
import { cleanLocalStorageIfNeeded } from '../../utils/clean';
|
import { cleanLocalStorageIfNeeded } from '../../utils/clean';
|
||||||
|
import { LoginModal } from '../modals/LoginModal';
|
||||||
|
|
||||||
const APP_ID = 'b2b49e91d21446aeb14579930f732985';
|
const APP_ID = 'b2b49e91d21446aeb14579930f732985';
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ export const HomeSection = () => {
|
|||||||
const [b1Loading, setB1Loading] = useState(false);
|
const [b1Loading, setB1Loading] = useState(false);
|
||||||
const [north3Data, setNorth3Data] = useState<OutputNorth3ServiceBoard | null>(null);
|
const [north3Data, setNorth3Data] = useState<OutputNorth3ServiceBoard | null>(null);
|
||||||
const [north3Loading, setNorth3Loading] = useState(false);
|
const [north3Loading, setNorth3Loading] = useState(false);
|
||||||
|
const [showLoginModal, setShowLoginModal] = useState(false);
|
||||||
|
|
||||||
const currencyFormatter = useMemo(() => new Intl.NumberFormat('zh-CN', {
|
const currencyFormatter = useMemo(() => new Intl.NumberFormat('zh-CN', {
|
||||||
style: 'currency',
|
style: 'currency',
|
||||||
@@ -38,6 +40,14 @@ export const HomeSection = () => {
|
|||||||
maximumFractionDigits: 0,
|
maximumFractionDigits: 0,
|
||||||
}), []);
|
}), []);
|
||||||
|
|
||||||
|
// 检查登录状态
|
||||||
|
useEffect(() => {
|
||||||
|
const accessToken = localStorage.getItem('accessToken');
|
||||||
|
if (!accessToken) {
|
||||||
|
setShowLoginModal(true);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
// 清理本地存储
|
// 清理本地存储
|
||||||
@@ -259,6 +269,21 @@ export const HomeSection = () => {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export const LoginModal = ({ onClose, onLoginSuccess }: LoginModalProps) => {
|
|||||||
const canLogin = !!(username && password && imgCode && imgCodeKey && !loading);
|
const canLogin = !!(username && password && imgCode && imgCodeKey && !loading);
|
||||||
|
|
||||||
return (
|
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
|
<div
|
||||||
className='w-[480px] max-w-[95vw] bg-white rounded-3xl shadow-xl overflow-hidden text-sm'
|
className='w-[480px] max-w-[95vw] bg-white rounded-3xl shadow-xl overflow-hidden text-sm'
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
|||||||
Reference in New Issue
Block a user