31 lines
2.3 KiB
TypeScript
31 lines
2.3 KiB
TypeScript
import { ArrowLeft, Building2, ChevronDown, Menu, UserRound,LogOut } from 'lucide-react';
|
|
import { useState, type ReactNode } from 'react';
|
|
import { Brand } from './Brand';
|
|
import { Sidebar } from './Sidebar';
|
|
import {useNavigationOverlay} from './overlay';
|
|
|
|
export function AppShell({ page, tenantName, displayName, hostScoped = false, hostView = false, hostName, onBack, onNavigate, onSecurity,onLogout, children }: { page: string; tenantName: string; displayName: string; hostScoped?: boolean; hostView?: boolean; hostName?:string; onBack?:()=>void; onNavigate: (page: string) => void; onSecurity: () => void;onLogout?:()=>void; children: ReactNode }) {
|
|
const [mobileNavOpen, setMobileNavOpen] = useState(false);
|
|
useNavigationOverlay(mobileNavOpen,setMobileNavOpen);
|
|
function navigate(pageName: string) {
|
|
onNavigate(pageName);
|
|
setMobileNavOpen(false);
|
|
}
|
|
return (
|
|
<div className="app-shell">
|
|
<header className="topbar">
|
|
<button className="mobile-menu" aria-label={mobileNavOpen ? '关闭导航' : '打开导航'} aria-expanded={mobileNavOpen} onClick={() => setMobileNavOpen((value) => !value)}><Menu size={21} /></button>
|
|
<Brand />
|
|
<div className="tenant-switch"><Building2 size={17} /><span>{hostView || hostScoped ? hostName : tenantName}</span></div>
|
|
<div className="top-actions">
|
|
{onLogout?<button className="icon-button" aria-label="退出登录" onClick={onLogout}><LogOut size={18}/></button>:null}
|
|
<button className="user-menu" onClick={onSecurity} aria-label="账号安全"><span className="avatar"><UserRound size={17} /></span><span>{displayName}</span><ChevronDown size={15} /></button>
|
|
</div>
|
|
</header>
|
|
{mobileNavOpen ? <button className="mobile-nav-backdrop" aria-label="关闭导航" onClick={() => setMobileNavOpen(false)} /> : null}
|
|
<div className={mobileNavOpen ? 'mobile-sidebar open' : 'mobile-sidebar'}><Sidebar page={page} hostScoped={hostScoped} hostView={hostView} onNavigate={navigate} /></div>
|
|
<main className="main-content">{onBack ? <div className="host-context-bar"><span>目前主机 <b>{hostName}</b></span><button className="secondary" onClick={()=>{setMobileNavOpen(false);onBack()}}><ArrowLeft size={15}/>返回用户总览</button></div> : null}{children}</main>
|
|
</div>
|
|
);
|
|
}
|