import React, {useEffect, useState} from "react"; import less from "./HeadLayout.less"; import Flex from "../components/Flex"; import AppHelper from "@/utils/AppHelper"; const designWidth = 1280, designHeight = 720; /** * 获取头部高度 * @returns {number} */ export const getHeaderHeight = () => { return 60; }; export default ({children, location}) => { const [screen, setScreen] = useState({width: designWidth, height: designHeight}); const [scale, setScale] = useState(1); const [boxList, setBoxList] = useState([]); useEffect(() => { getList(); windowScale() }, []); ///////////////////////////////////////// 逻辑方法 const getList = () => { let tmpBoxList = [ {id: "/home", name: "首页"}, {id: "/vehicle", name: "智慧交通"}, ] setBoxList(tmpBoxList); }; /** * 屏幕比例适配 */ const windowScale = () => { let tmpWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; let tmpHeight = window.innerHeight || document.documentElement.clientWidth || document.body.clientHeight; let ratio = tmpWidth / designWidth; if (tmpWidth > tmpHeight) { setScreen({width: tmpWidth / ratio, height: tmpHeight / ratio}); } else { setScreen({width: designWidth, height: designHeight}); } setScale(ratio); }; window.onresize = windowScale; ///////////////////////////////////////// 页面渲染 return ( {boxList.map((it) => { return ( AppHelper.routerPush(it.id)} > {it.name} ); })} {children} ); };