2025-01-26 16:05:24 +08:00
|
|
|
import { Link, NavLink, useNavigate } from "react-router-dom";
|
2025-02-17 16:02:13 +08:00
|
|
|
import { memo, useEffect, useMemo } from "react";
|
2025-01-22 19:24:52 +08:00
|
|
|
import { SearchBar } from "./SearchBar";
|
2025-01-22 23:19:58 +08:00
|
|
|
import Navigation from "./navigation";
|
2025-01-23 23:59:49 +08:00
|
|
|
import { useAuth } from "@web/src/providers/auth-provider";
|
2025-02-17 09:26:30 +08:00
|
|
|
import { HomeOutlined, UserOutlined } from "@ant-design/icons";
|
2025-01-26 12:45:59 +08:00
|
|
|
import { UserMenu } from "../element/usermenu/usermenu";
|
2025-02-14 11:45:41 +08:00
|
|
|
import logo from "@web/src/assets/logo.png";
|
2025-01-26 21:01:45 +08:00
|
|
|
import { env } from "@web/src/env";
|
2025-01-26 21:04:02 +08:00
|
|
|
import { Button } from "antd";
|
2025-02-14 11:45:41 +08:00
|
|
|
import usePublicImage from "@web/src/hooks/usePublicImage";
|
2025-01-26 16:05:24 +08:00
|
|
|
export const Header = memo(function Header() {
|
2025-01-26 18:24:16 +08:00
|
|
|
const { isAuthenticated } = useAuth();
|
2025-02-14 11:45:41 +08:00
|
|
|
const navigate = useNavigate();
|
|
|
|
const { imageUrl } = usePublicImage("logo.png");
|
2025-02-17 16:02:13 +08:00
|
|
|
const userAgent = navigator.userAgent;
|
|
|
|
const previewMode = useMemo(() => {
|
|
|
|
return (
|
|
|
|
userAgent ===
|
|
|
|
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0"
|
|
|
|
);
|
|
|
|
}, [userAgent]);
|
|
|
|
|
2025-01-26 18:24:16 +08:00
|
|
|
return (
|
2025-02-14 11:45:41 +08:00
|
|
|
<header className="sticky top-0 z-50 shadow-lg bg-slate-50">
|
2025-01-26 21:01:45 +08:00
|
|
|
<div className="mx-auto px-4">
|
2025-02-14 11:45:41 +08:00
|
|
|
<div className="py-1 relative">
|
|
|
|
{" "}
|
|
|
|
{/* 添加relative定位上下文 */}
|
2025-01-26 18:24:16 +08:00
|
|
|
<div className="flex items-center justify-between gap-4">
|
2025-01-26 21:01:45 +08:00
|
|
|
{/* 左侧logo部分 */}
|
2025-02-17 09:26:30 +08:00
|
|
|
<div
|
|
|
|
onClick={() => {
|
|
|
|
window.location.href = env.HOME_URL;
|
|
|
|
}}
|
|
|
|
className="hover:cursor-pointer flex items-center flex-shrink-0">
|
2025-02-14 11:45:41 +08:00
|
|
|
{" "}
|
|
|
|
{/* 防止压缩 */}
|
2025-02-17 09:26:30 +08:00
|
|
|
<div className="text-xl flex justify-center items-center font-bold text-primary-500/80 whitespace-nowrap">
|
|
|
|
{/* {env.APP_NAME} */}
|
|
|
|
<HomeOutlined className="mr-2" />
|
|
|
|
<span>{env.HOME_TEXT} </span>
|
2025-01-26 21:01:45 +08:00
|
|
|
</div>
|
2025-01-26 18:24:16 +08:00
|
|
|
</div>
|
2025-02-14 11:45:41 +08:00
|
|
|
{/* <SearchBar /> */}
|
|
|
|
{/* 中间标题部分 */}
|
|
|
|
{/* <div className="absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2"></div> */}
|
2025-01-26 21:01:45 +08:00
|
|
|
{/* 右侧登录部分 */}
|
2025-02-14 11:45:41 +08:00
|
|
|
<div className="flex items-center flex-shrink-0">
|
|
|
|
{" "}
|
|
|
|
{/* 防止压缩 */}
|
2025-02-17 16:02:13 +08:00
|
|
|
{!isAuthenticated
|
|
|
|
? !previewMode && (
|
|
|
|
<Button
|
|
|
|
className=" text-lg bg-primary-500/80 "
|
|
|
|
style={{
|
|
|
|
boxShadow: "none",
|
|
|
|
}}
|
|
|
|
onClick={() => {
|
|
|
|
navigate("/auth");
|
|
|
|
}}
|
|
|
|
type="primary"
|
|
|
|
icon={
|
|
|
|
<UserOutlined></UserOutlined>
|
|
|
|
}>
|
|
|
|
登录
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
: !previewMode && <UserMenu />}
|
|
|
|
{previewMode && (
|
2025-02-14 11:45:41 +08:00
|
|
|
<Button
|
|
|
|
className=" text-lg bg-primary-500/80 "
|
|
|
|
style={{
|
|
|
|
boxShadow: "none",
|
|
|
|
}}
|
2025-02-17 16:02:13 +08:00
|
|
|
type="primary">
|
2025-02-18 08:34:50 +08:00
|
|
|
预览模式
|
2025-01-26 21:04:02 +08:00
|
|
|
</Button>
|
2025-01-26 18:24:16 +08:00
|
|
|
)}
|
|
|
|
</div>
|
2025-01-26 21:01:45 +08:00
|
|
|
|
|
|
|
{/* 独立定位的搜索栏 */}
|
2025-02-14 11:45:41 +08:00
|
|
|
{/* <div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-2xl px-4">
|
|
|
|
|
|
|
|
</div> */}
|
2025-01-26 18:24:16 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2025-02-14 11:45:41 +08:00
|
|
|
{/* <Navigation /> */}
|
2025-01-26 18:24:16 +08:00
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
);
|
2025-02-14 11:45:41 +08:00
|
|
|
});
|