From 306f9ebbae73abbff170884952ab8346694a521e Mon Sep 17 00:00:00 2001 From: zhengwr Date: Mon, 15 Jun 2026 17:37:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(design-center):=20=E9=9B=86=E4=B8=AD?= =?UTF-8?q?=E5=BC=8F=E8=AE=BE=E8=AE=A1=E4=B8=AD=E5=BF=83,=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=E6=AF=8F=E9=A1=B5=E8=AE=BE=E8=AE=A1=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户反馈每个功能页右上角一颗「设计」按钮散落、不合理。改为: - 新增 /design-center 页(DesignCenterPage):列全部功能页(按菜单分组+计数+ 搜索),每页一个「设计」入口开 editor.html;复用 fetchMenu/collectLeaves。 - Topbar 加 admin-only「设计中心」入口(brush 图标),useNavigate 直达。 - PageRenderPage 移除每页 DesignButton(及 getProfile import)。 验证:浏览器 /design-center 渲染 812 页/14 分组、顶栏按钮在、点行选中并存。 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/App.tsx | 3 + src/pages/DesignCenterPage.tsx | 181 +++++++++++++++++++++++++++++++++ src/pages/PageRenderPage.tsx | 33 +----- src/shell/Topbar.tsx | 15 +++ 4 files changed, 200 insertions(+), 32 deletions(-) create mode 100644 src/pages/DesignCenterPage.tsx diff --git a/src/App.tsx b/src/App.tsx index 42ac955..abf6e3a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,7 @@ import { LoginPage } from './pages/LoginPage'; import { PageRenderPage } from './pages/PageRenderPage'; import { TodoPage } from './pages/TodoPage'; import { WorkbenchPage } from './pages/WorkbenchPage'; +import { DesignCenterPage } from './pages/DesignCenterPage'; // 把 401 跳登录的 handler 注入 http 层(在路由上下文内,可用 navigate) function UnauthorizedBridge() { @@ -37,6 +38,8 @@ export default function App() { } /> } /> } /> + {/* 设计中心(管理员集中式低代码设计入口,替代每页设计按钮)*/} + } /> {/* 根路径默认跳工作台 */} } /> diff --git a/src/pages/DesignCenterPage.tsx b/src/pages/DesignCenterPage.tsx new file mode 100644 index 0000000..dee7b62 --- /dev/null +++ b/src/pages/DesignCenterPage.tsx @@ -0,0 +1,181 @@ +// 设计中心 —— 集中式低代码设计入口(替代每页一颗「设计」按钮)。 +// 列出全部功能页(按菜单分组、可搜索),每页一个「设计」入口打开 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} + + )} +
+ ); +} diff --git a/src/pages/PageRenderPage.tsx b/src/pages/PageRenderPage.tsx index e8c8171..97d51cd 100644 --- a/src/pages/PageRenderPage.tsx +++ b/src/pages/PageRenderPage.tsx @@ -8,7 +8,6 @@ import { fetchSchema } from '../api/schema'; import { AmisRenderer } from '../components/AmisRenderer'; import { recordRecentPage } from '../utils/recentPages'; import { useTabTitle } from '../shell/TabTitleContext'; -import { getProfile } from '../auth/token'; // ---- amis 渲染层错误边界(class component,捕获子树抛错)---- interface ErrorBoundaryState { @@ -71,36 +70,6 @@ function SchemaErrorCard({ templateId, summary }: { templateId: string; summary: ); } -// ---- 管理员设计按钮 ---- -function DesignButton({ templateId }: { templateId: string }) { - const profile = getProfile(); - const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN'; - if (!isAdmin) return null; - return ( - - ); -} - // ---- 主组件 ---- export function PageRenderPage() { const { templateId = '' } = useParams(); @@ -147,7 +116,7 @@ export function PageRenderPage() { } return (
- + {/* 设计入口已收敛到顶栏「设计中心」(admin),不再每页一颗按钮 */} diff --git a/src/shell/Topbar.tsx b/src/shell/Topbar.tsx index 2be7bf2..a063959 100644 --- a/src/shell/Topbar.tsx +++ b/src/shell/Topbar.tsx @@ -1,5 +1,6 @@ // Topbar — 顶栏:品牌 + 搜索 + 待办入口 + 用户信息 + 设置入口 // 从原型 frame.jsx Topbar 迁移,待办 badge 数由父层传入(后续可接真实 API) +import { useNavigate } from 'react-router-dom'; import { Icon } from '../components/ui/Icon'; import { GlobalSearch } from './GlobalSearch'; import type { MenuLeaf } from '../api/menu'; @@ -28,6 +29,8 @@ export function Topbar({ }: TopbarProps) { // 用户名显示:取 name 首字作头像 const avatarChar = profile?.name?.[0] ?? '?'; + const navigate = useNavigate(); + const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN'; return (
@@ -63,6 +66,18 @@ export function Topbar({ ) : null} + {/* 设计中心(管理员)—— 集中式低代码设计入口,替代每页设计按钮 */} + {isAdmin ? ( + + ) : null} + {/* 设置 */}