feat(webui): kiosk (展示模式) for chrome-free wall displays (B2)
A session-sticky kiosk mode for showing the dashboard on a wall display: - Entry: `?kiosk=1` URL param (stripped after read) or a top-bar button (toggleable via topbarItems 'kiosk'). - Hides the sidebar + top bar (MainLayout) and any in-content edit entry marked data-kiosk-hide (the overview 编辑布局 toolbar) via an html[data-kiosk] CSS rule. - Exit: Esc key or a dim corner button. Purely cosmetic — never touches auth and issues no token. A new KioskProvider (sessionStorage-backed, mounted under LayoutProvider) owns the state. Completes the B2 dashboard/components batch.
This commit is contained in:
6 files changed
+134
-26
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState, type ReactNode } from 'react';
|
import { useEffect, useState, type ReactNode } from 'react';
|
||||||
import { motion, AnimatePresence } from 'motion/react';
|
import { motion, AnimatePresence } from 'motion/react';
|
||||||
import { useRouterState } from '@tanstack/react-router';
|
import { useRouterState } from '@tanstack/react-router';
|
||||||
|
import { Minimize2 } from 'lucide-react';
|
||||||
import { Sheet, SheetContent, SheetDescription, SheetTitle } from '@/components/ui/sheet';
|
import { Sheet, SheetContent, SheetDescription, SheetTitle } from '@/components/ui/sheet';
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
import { Sidebar } from '@/components/layout/sidebar';
|
import { Sidebar } from '@/components/layout/sidebar';
|
||||||
@@ -8,6 +9,7 @@ import { TopBar } from '@/components/layout/top-bar';
|
|||||||
import { useMediaQuery } from '@/hooks/use-media-query';
|
import { useMediaQuery } from '@/hooks/use-media-query';
|
||||||
import { useTheme } from '@/contexts/ThemeContext';
|
import { useTheme } from '@/contexts/ThemeContext';
|
||||||
import { useLayout } from '@/contexts/LayoutContext';
|
import { useLayout } from '@/contexts/LayoutContext';
|
||||||
|
import { useKiosk } from '@/contexts/KioskContext';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
interface MainLayoutProps {
|
interface MainLayoutProps {
|
||||||
@@ -33,6 +35,7 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
|||||||
// “减少动效” setting actually felt.
|
// “减少动效” setting actually felt.
|
||||||
const reduce = appearance.reduceMotion || appearance.disableMotion;
|
const reduce = appearance.reduceMotion || appearance.disableMotion;
|
||||||
const { editing } = useLayout();
|
const { editing } = useLayout();
|
||||||
|
const { kiosk, exit: exitKiosk } = useKiosk();
|
||||||
// Force the sidebar open while editing layout so its drag-to-reorder list
|
// Force the sidebar open while editing layout so its drag-to-reorder list
|
||||||
// has room (it returns to the user's collapsed pref on 完成).
|
// has room (it returns to the user's collapsed pref on 完成).
|
||||||
const effectiveCollapsed = collapsed && !editing;
|
const effectiveCollapsed = collapsed && !editing;
|
||||||
@@ -45,8 +48,8 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('flex h-screen w-screen overflow-hidden text-foreground', customBg ? 'bg-transparent' : 'bg-background')}>
|
<div className={cn('flex h-screen w-screen overflow-hidden text-foreground', customBg ? 'bg-transparent' : 'bg-background')}>
|
||||||
{/* Desktop sidebar */}
|
{/* Desktop sidebar (hidden in kiosk) */}
|
||||||
{!isMobile && (
|
{!isMobile && !kiosk && (
|
||||||
<motion.aside
|
<motion.aside
|
||||||
initial={false}
|
initial={false}
|
||||||
animate={{ width: effectiveCollapsed ? 64 : 248 }}
|
animate={{ width: effectiveCollapsed ? 64 : 248 }}
|
||||||
@@ -57,8 +60,8 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
|||||||
</motion.aside>
|
</motion.aside>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Mobile sidebar in sheet */}
|
{/* Mobile sidebar in sheet (hidden in kiosk) */}
|
||||||
{isMobile && (
|
{isMobile && !kiosk && (
|
||||||
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
|
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
|
||||||
<SheetContent side="left" className="w-64 max-w-[80vw] p-0">
|
<SheetContent side="left" className="w-64 max-w-[80vw] p-0">
|
||||||
{/* Radix Dialog (the Sheet primitive) requires an accessible name +
|
{/* Radix Dialog (the Sheet primitive) requires an accessible name +
|
||||||
@@ -71,17 +74,32 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
|||||||
</Sheet>
|
</Sheet>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Kiosk: chrome-free, with a corner button (+ Esc) to exit. */}
|
||||||
|
{kiosk && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={exitKiosk}
|
||||||
|
title="退出展示模式 (Esc)"
|
||||||
|
aria-label="退出展示模式"
|
||||||
|
className="fixed right-3 top-3 z-50 inline-flex size-9 items-center justify-center rounded-full border bg-background/70 text-muted-foreground opacity-30 backdrop-blur transition-opacity outline-none hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-[3px] focus-visible:ring-ring/40"
|
||||||
|
>
|
||||||
|
<Minimize2 className="size-4" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Main column */}
|
{/* Main column */}
|
||||||
<div className="flex min-w-0 flex-1 flex-col">
|
<div className="flex min-w-0 flex-1 flex-col">
|
||||||
<TopBar
|
{!kiosk && (
|
||||||
status={status}
|
<TopBar
|
||||||
collapsed={effectiveCollapsed}
|
status={status}
|
||||||
onToggleCollapse={() => setCollapsed((v) => !v)}
|
collapsed={effectiveCollapsed}
|
||||||
onOpenMobile={() => setMobileOpen(true)}
|
onToggleCollapse={() => setCollapsed((v) => !v)}
|
||||||
onLogout={onLogout}
|
onOpenMobile={() => setMobileOpen(true)}
|
||||||
isMobile={isMobile}
|
onLogout={onLogout}
|
||||||
editing={editing}
|
isMobile={isMobile}
|
||||||
/>
|
editing={editing}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<main className={cn('flex min-h-0 flex-1 flex-col')}>
|
<main className={cn('flex min-h-0 flex-1 flex-col')}>
|
||||||
<ScrollArea className="flex-1 min-h-0" viewportClassName="[&>div]:!block">
|
<ScrollArea className="flex-1 min-h-0" viewportClassName="[&>div]:!block">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { LogOut, Menu, PanelLeftClose, PanelLeftOpen } from 'lucide-react';
|
import { LogOut, Menu, Monitor, PanelLeftClose, PanelLeftOpen } from 'lucide-react';
|
||||||
import { motion, AnimatePresence } from 'motion/react';
|
import { motion, AnimatePresence } from 'motion/react';
|
||||||
import { useRouterState } from '@tanstack/react-router';
|
import { useRouterState } from '@tanstack/react-router';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -8,12 +8,14 @@ import { ThemeToggle } from '@/components/theme-toggle';
|
|||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||||
import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext';
|
import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext';
|
||||||
|
import { useKiosk } from '@/contexts/KioskContext';
|
||||||
|
|
||||||
// Toggleable top-bar elements (the menu/title/logout are essential and always
|
// Toggleable top-bar elements (the menu/title/logout are essential and always
|
||||||
// render). Labels drive the settings toggles; ids match `topbarItems`.
|
// render). Labels drive the settings toggles; ids match `topbarItems`.
|
||||||
export const TOPBAR_CATALOGUE: { id: string; label: string }[] = [
|
export const TOPBAR_CATALOGUE: { id: string; label: string }[] = [
|
||||||
{ id: 'status', label: '连接状态徽章' },
|
{ id: 'status', label: '连接状态徽章' },
|
||||||
{ id: 'theme', label: '主题切换按钮' },
|
{ id: 'theme', label: '主题切换按钮' },
|
||||||
|
{ id: 'kiosk', label: '展示模式按钮' },
|
||||||
];
|
];
|
||||||
|
|
||||||
interface TopBarProps {
|
interface TopBarProps {
|
||||||
@@ -45,6 +47,7 @@ export function TopBar({
|
|||||||
// Which optional top-bar elements the operator has kept (reconciled against
|
// Which optional top-bar elements the operator has kept (reconciled against
|
||||||
// the live catalogue, so a new element defaults to shown).
|
// the live catalogue, so a new element defaults to shown).
|
||||||
const { topbarItems } = useLayout();
|
const { topbarItems } = useLayout();
|
||||||
|
const { enter: enterKiosk } = useKiosk();
|
||||||
const shown = new Set(
|
const shown = new Set(
|
||||||
reconcileLayoutItems(topbarItems, TOPBAR_CATALOGUE.map((t) => t.id))
|
reconcileLayoutItems(topbarItems, TOPBAR_CATALOGUE.map((t) => t.id))
|
||||||
.filter((i) => i.visible)
|
.filter((i) => i.visible)
|
||||||
@@ -104,6 +107,19 @@ export function TopBar({
|
|||||||
|
|
||||||
{shown.has('theme') && <ThemeToggle />}
|
{shown.has('theme') && <ThemeToggle />}
|
||||||
|
|
||||||
|
{shown.has('kiosk') && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
onClick={enterKiosk}
|
||||||
|
aria-label="展示模式"
|
||||||
|
title="展示模式(隐藏侧栏与顶栏,Esc 退出)"
|
||||||
|
className="text-muted-foreground hover:text-foreground"
|
||||||
|
>
|
||||||
|
<Monitor className="size-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon-sm"
|
size="icon-sm"
|
||||||
|
|||||||
@@ -110,8 +110,9 @@ export function OverviewPage() {
|
|||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
{/* Toolbar: edit toggle on both desktop (2D grid overlays) and mobile
|
{/* Toolbar: edit toggle on both desktop (2D grid overlays) and mobile
|
||||||
(single-column drag-sort panel). The sidebar nav is drag-sortable in
|
(single-column drag-sort panel). The sidebar nav is drag-sortable in
|
||||||
edit mode on both — no separate editor panel. */}
|
edit mode on both — no separate editor panel. Hidden in kiosk mode
|
||||||
<div className="flex items-center justify-end gap-2">
|
(data-kiosk-hide → CSS) so a wall display has no edit entry. */}
|
||||||
|
<div data-kiosk-hide className="flex items-center justify-end gap-2">
|
||||||
{editing && (
|
{editing && (
|
||||||
<Button variant="ghost" size="sm" onClick={resetLayout} className="text-muted-foreground">
|
<Button variant="ghost" size="sm" onClick={resetLayout} className="text-muted-foreground">
|
||||||
<RotateCcw className="size-3.5" /> 恢复默认
|
<RotateCcw className="size-3.5" /> 恢复默认
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import { createContext, useCallback, useContext, useEffect, useState, type ReactNode } from 'react';
|
||||||
|
|
||||||
|
// Kiosk ("展示模式"): a chrome-free full-screen view for dashboards on a wall
|
||||||
|
// display. Entered via `?kiosk=1` or the top-bar button; exited via Esc or the
|
||||||
|
// corner button. Sticky for the session (sessionStorage) so in-app navigation
|
||||||
|
// keeps it. Purely cosmetic — it never touches auth or issues any token.
|
||||||
|
|
||||||
|
const KIOSK_KEY = 'snowluma_kiosk';
|
||||||
|
|
||||||
|
function readInitial(): boolean {
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
if (params.get('kiosk') === '1') {
|
||||||
|
sessionStorage.setItem(KIOSK_KEY, '1');
|
||||||
|
// Strip the param so a later reload (after exiting) doesn't re-enter.
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
url.searchParams.delete('kiosk');
|
||||||
|
window.history.replaceState({}, '', url.pathname + url.search + url.hash);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return sessionStorage.getItem(KIOSK_KEY) === '1';
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KioskValue {
|
||||||
|
kiosk: boolean;
|
||||||
|
enter: () => void;
|
||||||
|
exit: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const KioskContext = createContext<KioskValue | null>(null);
|
||||||
|
|
||||||
|
export function KioskProvider({ children }: { children: ReactNode }) {
|
||||||
|
const [kiosk, setKiosk] = useState(readInitial);
|
||||||
|
|
||||||
|
const enter = useCallback(() => {
|
||||||
|
try { sessionStorage.setItem(KIOSK_KEY, '1'); } catch { /* private mode */ }
|
||||||
|
setKiosk(true);
|
||||||
|
}, []);
|
||||||
|
const exit = useCallback(() => {
|
||||||
|
try { sessionStorage.removeItem(KIOSK_KEY); } catch { /* private mode */ }
|
||||||
|
setKiosk(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Reflect onto <html data-kiosk> so CSS can hide chrome (e.g. the overview
|
||||||
|
// edit entry), and bind Esc-to-exit only while active.
|
||||||
|
useEffect(() => {
|
||||||
|
document.documentElement.setAttribute('data-kiosk', kiosk ? '1' : '0');
|
||||||
|
if (!kiosk) return;
|
||||||
|
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') exit(); };
|
||||||
|
window.addEventListener('keydown', onKey);
|
||||||
|
return () => window.removeEventListener('keydown', onKey);
|
||||||
|
}, [kiosk, exit]);
|
||||||
|
|
||||||
|
return <KioskContext.Provider value={{ kiosk, enter, exit }}>{children}</KioskContext.Provider>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useKiosk(): KioskValue {
|
||||||
|
const ctx = useContext(KioskContext);
|
||||||
|
if (!ctx) throw new Error('useKiosk must be used within KioskProvider');
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
@@ -210,6 +210,12 @@ html[data-contrast="high"] {
|
|||||||
--sidebar-border: color-mix(in oklab, var(--foreground) 55%, var(--sidebar-border));
|
--sidebar-border: color-mix(in oklab, var(--foreground) 55%, var(--sidebar-border));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Kiosk ("展示模式"): hide any in-content edit/config entry points marked with
|
||||||
|
data-kiosk-hide (the chrome itself is removed in MainLayout). */
|
||||||
|
html[data-kiosk="1"] [data-kiosk-hide] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
/* Reduce motion: a CSS fallback for non-Framer transitions/animations.
|
/* Reduce motion: a CSS fallback for non-Framer transitions/animations.
|
||||||
Framer Motion itself is handled by <MotionConfig reducedMotion>. */
|
Framer Motion itself is handled by <MotionConfig reducedMotion>. */
|
||||||
html[data-reduce-motion="1"] *,
|
html[data-reduce-motion="1"] *,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { NAV_ITEMS } from '@/components/layout/sidebar';
|
|||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { AppStateProvider } from '@/contexts/AppStateContext';
|
import { AppStateProvider } from '@/contexts/AppStateContext';
|
||||||
|
import { KioskProvider } from '@/contexts/KioskContext';
|
||||||
import { LayoutProvider, useLayout } from '@/contexts/LayoutContext';
|
import { LayoutProvider, useLayout } from '@/contexts/LayoutContext';
|
||||||
import { useSession } from '@/contexts/SessionContext';
|
import { useSession } from '@/contexts/SessionContext';
|
||||||
import type { AppPath } from '@/router';
|
import type { AppPath } from '@/router';
|
||||||
@@ -157,16 +158,18 @@ export function AppLayout() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LayoutProvider>
|
<LayoutProvider>
|
||||||
<DefaultRouteRedirect />
|
<KioskProvider>
|
||||||
<MainLayout status={session.status} onLogout={handleLogout}>
|
<DefaultRouteRedirect />
|
||||||
{/* Routes use `lazyRouteComponent` (router/index.tsx) for
|
<MainLayout status={session.status} onLogout={handleLogout}>
|
||||||
code-splitting, which suspends until the chunk is fetched.
|
{/* Routes use `lazyRouteComponent` (router/index.tsx) for
|
||||||
The chrome (sidebar / top bar) stays mounted across this
|
code-splitting, which suspends until the chunk is fetched.
|
||||||
boundary so only the page surface flashes a skeleton. */}
|
The chrome (sidebar / top bar) stays mounted across this
|
||||||
<Suspense fallback={<PageFallback />}>
|
boundary so only the page surface flashes a skeleton. */}
|
||||||
<Outlet />
|
<Suspense fallback={<PageFallback />}>
|
||||||
</Suspense>
|
<Outlet />
|
||||||
</MainLayout>
|
</Suspense>
|
||||||
|
</MainLayout>
|
||||||
|
</KioskProvider>
|
||||||
</LayoutProvider>
|
</LayoutProvider>
|
||||||
|
|
||||||
<ConfirmDialog
|
<ConfirmDialog
|
||||||
|
|||||||
Reference in new issue
Block a user