优化 全屏功能
This commit is contained in:
@@ -7,7 +7,9 @@ import zhCN from 'antd/locale/zh_CN';
|
||||
import {
|
||||
DashboardOutlined, ExperimentOutlined, VideoCameraOutlined,
|
||||
BellOutlined, UserOutlined, LogoutOutlined,
|
||||
AppstoreOutlined, SettingOutlined, MenuUnfoldOutlined, MenuFoldOutlined
|
||||
AppstoreOutlined, SettingOutlined, MenuUnfoldOutlined, MenuFoldOutlined,
|
||||
CompressOutlined,
|
||||
ExpandOutlined
|
||||
} from '@ant-design/icons';
|
||||
import logo from '../assets/logo.png';
|
||||
import { useSelector } from 'react-redux';
|
||||
@@ -25,6 +27,8 @@ export default function AppLayout() {
|
||||
const [time, setTime] = useState(new Date().toLocaleString());
|
||||
const [menuList, setMenuList] = useState([]);
|
||||
const [stationList, setStationList] = useState([]);
|
||||
const [isFullScreen, setIsFullScreen] = useState(false); // 新增全屏标识
|
||||
|
||||
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
@@ -49,6 +53,17 @@ export default function AppLayout() {
|
||||
}
|
||||
});
|
||||
};
|
||||
const toggleFullScreen = () => {
|
||||
if (!document.fullscreenElement) {
|
||||
document.documentElement.requestFullscreen();
|
||||
setIsFullScreen(true);
|
||||
} else {
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
setIsFullScreen(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleStationChange = (id: number) => {
|
||||
const station = stationList.find(s => s.id === id);
|
||||
@@ -98,6 +113,14 @@ export default function AppLayout() {
|
||||
return () => clearInterval(timer);
|
||||
}, [userInfo]);
|
||||
|
||||
useEffect(() => {
|
||||
const fullscreenChange = () => {
|
||||
setIsFullScreen(!!document.fullscreenElement);
|
||||
};
|
||||
document.addEventListener('fullscreenchange', fullscreenChange);
|
||||
return () => document.removeEventListener('fullscreenchange', fullscreenChange);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ConfigProvider
|
||||
locale={zhCN}
|
||||
@@ -182,6 +205,14 @@ export default function AppLayout() {
|
||||
</Space>
|
||||
|
||||
<Space size="middle" style={{ flexWrap: 'wrap' }}>
|
||||
<Button
|
||||
type="text"
|
||||
icon={isFullScreen ? <CompressOutlined /> : <ExpandOutlined />}
|
||||
onClick={toggleFullScreen}
|
||||
style={{ color: '#fff', fontSize: 'clamp(12px, 1vw, 14px)' }}
|
||||
>
|
||||
{isFullScreen ? '退出全屏' : '全屏'}
|
||||
</Button>
|
||||
<span style={{ fontSize: 'clamp(12px, 1vw, 13px)' }}>{time}</span>
|
||||
<Space
|
||||
style={{ cursor: 'pointer', padding: '0 4px' }}
|
||||
|
||||
Reference in New Issue
Block a user