import React, { useEffect, useState } from "react"; import { Dropdown } from "antd"; import type { MenuProps } from "antd"; import { DownOutlined } from "@ant-design/icons"; import { history } from "@umijs/max"; import logoPng from "@/assets/image/logo.ico"; import logoKailin from "@/assets/image/logo_i.png"; import { products } from "./utils/utils"; const scrollToHash = (hash: string) => { if (typeof window === "undefined") return; const id = hash.replace(/^#/, ""); requestAnimationFrame(() => { const el = document.getElementById(id); el?.scrollIntoView({ behavior: "smooth", block: "start" }); }); }; const AppRoot: React.FC = (props) => { const [pathname, setPathname] = useState(() => history.location.pathname); useEffect(() => { const toAbsoluteUrl = (url: string) => { if (/^https?:\/\//.test(url)) return url; const origin = window.location.origin.replace(/\/+$/, ""); const p = url.startsWith("/") ? url : `/${url}`; return `${origin}${p}`; }; const ensureMetaProperty = (property: string) => { let meta = document.querySelector( `meta[property="${property}"]`, ) as HTMLMetaElement | null; if (!meta) { meta = document.createElement("meta"); meta.setAttribute("property", property); document.head.appendChild(meta); } return meta; }; ensureMetaProperty("og:type").content = "website"; ensureMetaProperty("og:url").content = window.location.href; ensureMetaProperty("og:image").content = toAbsoluteUrl(logoPng); let faviconLink = document.querySelector( 'link[rel~="icon"]', ) as HTMLLinkElement | null; if (!faviconLink) { faviconLink = document.createElement("link"); faviconLink.rel = "icon"; document.head.appendChild(faviconLink); } faviconLink.type = "image/png"; faviconLink.href = logoPng; let appleTouchIconLink = document.querySelector( 'link[rel="apple-touch-icon"]', ) as HTMLLinkElement | null; if (!appleTouchIconLink) { appleTouchIconLink = document.createElement("link"); appleTouchIconLink.rel = "apple-touch-icon"; document.head.appendChild(appleTouchIconLink); } appleTouchIconLink.href = logoPng; }, []); useEffect(() => { const unlisten = history.listen(({ location }) => { setPathname(location.pathname); }); return unlisten; }, []); useEffect(() => { const { hash } = window.location; if (hash && hash.length > 1) { scrollToHash(hash); } }, [pathname]); const hideHeader = pathname === "/privacy" || pathname === "/agreement"; const headerHeight = hideHeader ? 0 : 72; const productMenuItems: MenuProps["items"] = products.map((product) => ({ key: product.name, label: ( {product.name} ), })); const header = hideHeader ? null : (
history.push("/home")} > 开邻智数 {/* 开邻智数 Kirin Intelligent Data */}
); return ( <> {header}
{props.children}
); }; export function rootContainer(container: React.ReactNode) { return {container}; }