// 设计中心 —— 集中式低代码设计入口(替代每页一颗「设计」按钮)。 // 列出全部功能页(按菜单分组、可搜索),每页一个「设计」入口打开 editor.html。 // 仅管理员可见(路由在 AppShell 下,入口在 Topbar admin-only 按钮)。 import { useEffect, useMemo, useState } from 'react'; import { fetchMenu, collectLeaves, type MenuLeaf } from '../api/menu'; import { getProfile } from '../auth/token'; interface Group { root: string; leaves: MenuLeaf[]; } function openDesigner(templateId: string) { window.open(`/editor.html?templateId=${encodeURIComponent(templateId)}`, '_blank'); } export function DesignCenterPage() { const [groups, setGroups] = useState([]); const [error, setError] = useState(''); const [loading, setLoading] = useState(true); const [q, setQ] = useState(''); const profile = getProfile(); const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN'; useEffect(() => { let alive = true; fetchMenu() .then((resp) => { if (!alive) return; const gs: Group[] = resp.roots .map((r) => ({ root: r.name, leaves: collectLeaves(r.children ?? [], []) })) .filter((g) => g.leaves.length > 0); setGroups(gs); }) .catch((e: Error) => alive && setError(e.message ?? '菜单加载失败')) .finally(() => alive && setLoading(false)); return () => { alive = false; }; }, []); const filtered = useMemo(() => { const kw = q.trim().toLowerCase(); if (!kw) return groups; return groups .map((g) => ({ root: g.root, leaves: g.leaves.filter( (l) => l.name.toLowerCase().includes(kw) || l.path.toLowerCase().includes(kw) || l.templateId.includes(kw), ), })) .filter((g) => g.leaves.length > 0); }, [groups, q]); const total = useMemo(() => groups.reduce((n, g) => n + g.leaves.length, 0), [groups]); const shown = useMemo(() => filtered.reduce((n, g) => n + g.leaves.length, 0), [filtered]); if (!isAdmin) { return
设计中心仅管理员可用。
; } return (
{/* 头部 */}

设计中心

集中管理 {total} 个功能页面的低代码设计 · 点「设计」在新标签页打开设计器
setQ(e.target.value)} placeholder="搜索页面名称 / 路径 / 模板ID…" data-testid="design-center-search" /> {q ? ( setQ('')}> 清除 ) : null}
{loading ? (
加载中…
) : error ? (
菜单加载失败:{error}
) : ( <> {q ? (
命中 {shown} 个页面
) : null} {filtered.map((g) => (
{g.root} {g.leaves.length}
{g.leaves.map((l) => (
{l.name}
{l.path || l.templateId}
))}
))} {filtered.length === 0 ? (
没有匹配的页面
) : null} )}
); }