import { useMemo, useEffect, useState, useCallback } from "react"; import { Outlet, NavLink } from "react-router-dom"; import { useSelector, useDispatch } from "react-redux"; import { Container, Nav, Navbar, NavDropdown } from "react-bootstrap"; import { fetchUserInfo, fetchUserAuthPages, changeBuilding, fetchSysMainSub } from "@STORE"; import Logo from "@ASSET/img/logo.png"; import { userAllAuthPages } from "@CON"; import AlarmOffcanvas from "@COM/app/AlarmOffcanvas"; import SystemOffcanvas from "@COM/app/SystemOffcanvas"; function App() { const dispatch = useDispatch(); // user const { userAuthPages, userInfo } = useSelector((state) => state.user); const TopMenu = useMemo(() => { let menu = [ userAllAuthPages.find((auth) => auth.name === "首頁"), ...userAuthPages?.map((page) => { if (userAllAuthPages.some((auth) => auth.name === page.subName)) { return { ...page, ...userAllAuthPages.find((auth) => auth.name === page.subName) }; } return page; }), ]; return menu; }, [userAuthPages]); // building const { buildingList, selectedBuiFullName, selectedBuiTag } = useSelector( (state) => state.buildingInfo, ); const updateBuilding = (building_tag, urn_3D) => { dispatch(changeBuilding({ building_tag, urn_3D })); }; // system const { mainSub } = useSelector((state) => state.system); const [systemMenuShow, setSystemMenuShow] = useState(false); const systemOffCanvasHandler = (e, name) => { if (name === "系統監控") { e.preventDefault(); setSystemMenuShow(!systemMenuShow); } }; useEffect(() => { // 取得使用者資料跟建築物資料(地區及棟別) dispatch(fetchUserAuthPages()); if (selectedBuiTag) { dispatch(fetchSysMainSub(selectedBuiTag)); } }, [selectedBuiTag]); // 離開頁面就清除所有 cookie //const removeAllCookie = useCallback(() => { // console.log("關閉分頁時,清除所有 cookie") // window.addEventListener("beforeunload",() => { // document.cookie.match(/[^ =;]+(?=\=)/g).forEach(key => { // document.cookie = `${key}=""; max-age=0`; // }) }) //}, []) return (