import { settingsSectionForLegacyTab } from "@umt/contracts"; import { useEffect } from "react"; import { Link, redirect, useLocation, useNavigate } from "react-router"; import { PageHeader } from "~/components/console/page-header.tsx"; import { parseSettingsHash, SECTIONS, settingsHash } from "~/components/settings/sections.tsx"; import { anchorId } from "~/components/settings/settings-block.tsx"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/components/ui/select.tsx"; import { cn } from "~/lib/utils.ts"; export const meta = () => [{ title: "设置 · UHD 媒体自动化控制台" }]; /** 旧链接 `?tab=xxx` → `#分区[/节]`(console-ia.md §3.3) */ export function clientLoader({ request }: { request: Request }) { const url = new URL(request.url); const tab = url.searchParams.get("tab"); if (!tab) return null; const hit = settingsSectionForLegacyTab(tab); url.searchParams.delete("tab"); const rest = url.searchParams.toString(); return redirect(`${url.pathname}${rest ? `?${rest}` : ""}${hit ? settingsHash(hit.section, hit.anchor) : ""}`); } export default function SettingsPage() { const location = useLocation(); const navigate = useNavigate(); const { section, anchor } = parseSettingsHash(location.hash); // 切分区回到顶部;带节锚点时滚到该节(内容可能还在加载,稍后再试一次) useEffect(() => { if (!anchor) { window.scrollTo({ top: 0 }); return; } let tries = 0; const go = () => { const el = document.getElementById(anchorId(section.id, anchor)); if (el) el.scrollIntoView({ behavior: "smooth", block: "start" }); else if (tries++ < 10) timer = window.setTimeout(go, 150); }; let timer = window.setTimeout(go, 0); return () => window.clearTimeout(timer); }, [section.id, anchor]); return ( <>
{/* 窄屏:顶部下拉 */}

{section.description}

{/* 宽屏:左侧分区导航 */}

{section.label}

{section.description}

{section.render()}
); }