feat(ui): 适配手机端布局与触控交互
窄屏改用抽屉导航和卡片列表,加大触控区域并处理安全区,避免表格横向溢出。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -29,36 +29,44 @@ export function Topbar({
|
||||
const pathname = usePathname();
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const { toggle } = useSidebar();
|
||||
const { toggle, toggleMobile, mobileOpen } = useSidebar();
|
||||
|
||||
function onMenu() {
|
||||
if (window.matchMedia("(min-width: 768px)").matches) toggle();
|
||||
else toggleMobile();
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
function onClick(e: MouseEvent) {
|
||||
function onClick(e: Event) {
|
||||
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||
}
|
||||
document.addEventListener("mousedown", onClick);
|
||||
return () => document.removeEventListener("mousedown", onClick);
|
||||
document.addEventListener("pointerdown", onClick);
|
||||
return () => document.removeEventListener("pointerdown", onClick);
|
||||
}, []);
|
||||
|
||||
const roleLabel = user.roles.includes("super admin") ? "超级管理员" : "业务员";
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-20 flex h-16 items-center justify-between border-b bg-[var(--color-surface)]/90 px-6 backdrop-blur">
|
||||
<div className="flex items-center gap-3">
|
||||
<header className="sticky top-0 z-20 flex h-[calc(4rem+env(safe-area-inset-top))] items-center justify-between border-b bg-[var(--color-surface)]/90 px-3 pt-[env(safe-area-inset-top)] backdrop-blur md:px-6">
|
||||
<div className="flex min-w-0 items-center gap-2 md:gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
aria-label="收起/展开菜单"
|
||||
className="-ml-1.5 rounded-md p-1.5 text-[var(--color-muted-foreground)] transition-colors hover:bg-[var(--color-muted)] hover:text-[var(--color-foreground)]"
|
||||
onClick={onMenu}
|
||||
aria-label="打开/关闭菜单"
|
||||
aria-expanded={mobileOpen}
|
||||
className="-ml-1 flex h-11 w-11 items-center justify-center rounded-md text-[var(--color-muted-foreground)] transition-colors hover:bg-[var(--color-muted)] hover:text-[var(--color-foreground)] md:h-auto md:w-auto md:p-1.5"
|
||||
>
|
||||
<PanelLeft className="h-[18px] w-[18px]" />
|
||||
</button>
|
||||
<h1 className="text-base font-semibold">{pageTitle(pathname)}</h1>
|
||||
<h1 className="truncate text-base font-semibold">{pageTitle(pathname)}</h1>
|
||||
</div>
|
||||
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className="flex items-center gap-2.5 rounded-full py-1 pl-1 pr-2.5 transition-colors hover:bg-[var(--color-muted)]"
|
||||
className="flex min-h-11 items-center gap-2.5 rounded-full py-1 pl-1 pr-2.5 transition-colors hover:bg-[var(--color-muted)]"
|
||||
aria-expanded={open}
|
||||
>
|
||||
<Avatar name={user.name ?? user.username} src={user.image} size={32} />
|
||||
<div className="hidden text-left leading-tight sm:block">
|
||||
@@ -73,7 +81,7 @@ export function Topbar({
|
||||
<Link
|
||||
href="/me"
|
||||
onClick={() => setOpen(false)}
|
||||
className="flex items-center gap-2.5 px-4 py-2 text-sm hover:bg-[var(--color-muted)]"
|
||||
className="flex min-h-11 items-center gap-2.5 px-4 py-2 text-sm hover:bg-[var(--color-muted)] md:min-h-0"
|
||||
>
|
||||
<User className="h-4 w-4" /> 个人中心
|
||||
</Link>
|
||||
@@ -85,7 +93,7 @@ export function Topbar({
|
||||
window.location.assign("/login");
|
||||
});
|
||||
}}
|
||||
className="flex w-full items-center gap-2.5 px-4 py-2 text-sm text-[var(--color-danger)] hover:bg-[var(--color-danger-soft)]"
|
||||
className="flex min-h-11 w-full items-center gap-2.5 px-4 py-2 text-sm text-[var(--color-danger)] hover:bg-[var(--color-danger-soft)] md:min-h-0"
|
||||
>
|
||||
<LogOut className="h-4 w-4" /> 退出登录
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user