2025-01-26 16:05:24 +08:00
|
|
|
import { Link, NavLink, useNavigate } from "react-router-dom";
|
2025-01-26 18:24:16 +08:00
|
|
|
import { memo, 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-01-24 17:37:51 +08:00
|
|
|
import { UserOutlined } from "@ant-design/icons";
|
2025-01-26 12:45:59 +08:00
|
|
|
import { UserMenu } from "../element/usermenu/usermenu";
|
2025-01-26 18:24:16 +08:00
|
|
|
import { api, useAppConfig } from "@nice/client";
|
|
|
|
import { env } from "@web/src/env";
|
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();
|
|
|
|
const { logo } = useAppConfig();
|
|
|
|
const { data: logoRes, isLoading } = api.resource.findFirst.useQuery(
|
|
|
|
{
|
|
|
|
where: {
|
|
|
|
fileId: logo,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
url: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
enabled: !!logo,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const logoUrl: string = useMemo(() => {
|
|
|
|
return `http://${env.SERVER_IP}/uploads/${logoRes?.url}`;
|
|
|
|
}, [logoRes]);
|
|
|
|
return (
|
|
|
|
<header className="sticky top-0 z-50 bg-gradient-to-br from-primary-500 to-primary-800 text-white shadow-lg">
|
|
|
|
<div className=" mx-auto px-4">
|
|
|
|
<div className="py-2">
|
|
|
|
<div className="flex items-center justify-between gap-4">
|
|
|
|
<div className="">
|
|
|
|
{/** 在这里放置logo */}
|
|
|
|
{isLoading ? (
|
|
|
|
<div className="w-48 h-24 bg-gray-300 animate-pulse"></div>
|
|
|
|
) : (
|
|
|
|
logoUrl && (
|
|
|
|
<img
|
|
|
|
src={logoUrl}
|
|
|
|
alt="Logo"
|
|
|
|
style={{ width: 192, height: 72 }}
|
|
|
|
className=" w-full h-full"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="flex-grow max-w-2xl">
|
|
|
|
<SearchBar />
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center ">
|
|
|
|
{!isAuthenticated ? (
|
|
|
|
<Link
|
|
|
|
to="/auth"
|
|
|
|
className="group flex items-center gap-2 rounded-lg
|
2025-01-23 23:59:49 +08:00
|
|
|
bg-[#00539B]/90 px-5 py-2.5 font-medium
|
|
|
|
shadow-lg transition-all duration-300
|
|
|
|
hover:-translate-y-0.5 hover:bg-[#0063B8]
|
|
|
|
hover:shadow-xl hover:shadow-[#00539B]/30
|
|
|
|
focus:outline-none focus:ring-2
|
|
|
|
focus:ring-[#8EADD4] focus:ring-offset-2
|
|
|
|
focus:ring-offset-[#13294B]"
|
2025-01-26 18:24:16 +08:00
|
|
|
aria-label="Login">
|
|
|
|
<UserOutlined
|
|
|
|
className="h-5 w-5 transition-transform
|
2025-01-24 17:37:51 +08:00
|
|
|
group-hover:scale-110 group-hover:rotate-12"></UserOutlined>
|
|
|
|
|
2025-01-26 18:24:16 +08:00
|
|
|
<span>登录</span>
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
<UserMenu />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Navigation />
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
);
|
2025-01-26 10:49:19 +08:00
|
|
|
});
|