feat(design-center): 集中式设计中心,替代每页设计按钮
用户反馈每个功能页右上角一颗「设计」按钮散落、不合理。改为: - 新增 /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) <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import { LoginPage } from './pages/LoginPage';
|
|||||||
import { PageRenderPage } from './pages/PageRenderPage';
|
import { PageRenderPage } from './pages/PageRenderPage';
|
||||||
import { TodoPage } from './pages/TodoPage';
|
import { TodoPage } from './pages/TodoPage';
|
||||||
import { WorkbenchPage } from './pages/WorkbenchPage';
|
import { WorkbenchPage } from './pages/WorkbenchPage';
|
||||||
|
import { DesignCenterPage } from './pages/DesignCenterPage';
|
||||||
|
|
||||||
// 把 401 跳登录的 handler 注入 http 层(在路由上下文内,可用 navigate)
|
// 把 401 跳登录的 handler 注入 http 层(在路由上下文内,可用 navigate)
|
||||||
function UnauthorizedBridge() {
|
function UnauthorizedBridge() {
|
||||||
@@ -37,6 +38,8 @@ export default function App() {
|
|||||||
<Route path="/workbench" element={<WorkbenchPage />} />
|
<Route path="/workbench" element={<WorkbenchPage />} />
|
||||||
<Route path="/todo" element={<TodoPage />} />
|
<Route path="/todo" element={<TodoPage />} />
|
||||||
<Route path="/page/:templateId" element={<PageRenderPage />} />
|
<Route path="/page/:templateId" element={<PageRenderPage />} />
|
||||||
|
{/* 设计中心(管理员集中式低代码设计入口,替代每页设计按钮)*/}
|
||||||
|
<Route path="/design-center" element={<DesignCenterPage />} />
|
||||||
{/* 根路径默认跳工作台 */}
|
{/* 根路径默认跳工作台 */}
|
||||||
<Route index element={<Navigate to="/workbench" replace />} />
|
<Route index element={<Navigate to="/workbench" replace />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
181
src/pages/DesignCenterPage.tsx
Normal file
181
src/pages/DesignCenterPage.tsx
Normal file
@@ -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<Group[]>([]);
|
||||||
|
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 <div style={{ padding: 24, color: 'var(--text-3)' }}>设计中心仅管理员可用。</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ height: '100%', overflow: 'auto', padding: 'var(--pad-lg)' }} data-testid="design-center">
|
||||||
|
{/* 头部 */}
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 16, marginBottom: 16, flexWrap: 'wrap' }}>
|
||||||
|
<div>
|
||||||
|
<h2 style={{ margin: 0, fontSize: 18, fontWeight: 600, color: 'var(--text)' }}>设计中心</h2>
|
||||||
|
<div className="sub-text" style={{ marginTop: 4 }}>
|
||||||
|
集中管理 {total} 个功能页面的低代码设计 · 点「设计」在新标签页打开设计器
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style={{ flex: 1 }} />
|
||||||
|
<div className="gsearch" style={{ width: 280 }}>
|
||||||
|
<input
|
||||||
|
value={q}
|
||||||
|
onChange={(e) => setQ(e.target.value)}
|
||||||
|
placeholder="搜索页面名称 / 路径 / 模板ID…"
|
||||||
|
data-testid="design-center-search"
|
||||||
|
/>
|
||||||
|
{q ? (
|
||||||
|
<span className="link" style={{ fontSize: 'var(--fs-sm)' }} onClick={() => setQ('')}>
|
||||||
|
清除
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<div style={{ padding: 24, color: 'var(--text-3)' }}>加载中…</div>
|
||||||
|
) : error ? (
|
||||||
|
<div style={{ padding: 16, color: 'var(--err)' }}>菜单加载失败:{error}</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{q ? (
|
||||||
|
<div className="sub-text" style={{ marginBottom: 10 }}>
|
||||||
|
命中 {shown} 个页面
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{filtered.map((g) => (
|
||||||
|
<div key={g.root} className="card" style={{ marginBottom: 14, padding: 0 }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
padding: '10px 16px',
|
||||||
|
borderBottom: '1px solid var(--line)',
|
||||||
|
fontWeight: 600,
|
||||||
|
fontSize: 'var(--fs)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{g.root}
|
||||||
|
<span className="tag tag-gray">{g.leaves.length}</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'grid',
|
||||||
|
gridTemplateColumns: 'repeat(auto-fill, minmax(280px, 1fr))',
|
||||||
|
gap: 1,
|
||||||
|
background: 'var(--line)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{g.leaves.map((l) => (
|
||||||
|
<div
|
||||||
|
key={l.id}
|
||||||
|
style={{
|
||||||
|
background: 'var(--surface)',
|
||||||
|
padding: '10px 14px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 10,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ flex: 1, minWidth: 0 }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: 'var(--fs)',
|
||||||
|
color: 'var(--text)',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
}}
|
||||||
|
title={l.name}
|
||||||
|
>
|
||||||
|
{l.name}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="muted"
|
||||||
|
style={{
|
||||||
|
fontSize: 11,
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
}}
|
||||||
|
title={l.path || l.templateId}
|
||||||
|
>
|
||||||
|
{l.path || l.templateId}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
className="btn btn-sm"
|
||||||
|
data-testid="design-center-open"
|
||||||
|
onClick={() => openDesigner(l.templateId)}
|
||||||
|
title={`设计 ${l.name}`}
|
||||||
|
>
|
||||||
|
设计
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{filtered.length === 0 ? (
|
||||||
|
<div className="empty">没有匹配的页面</div>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@ import { fetchSchema } from '../api/schema';
|
|||||||
import { AmisRenderer } from '../components/AmisRenderer';
|
import { AmisRenderer } from '../components/AmisRenderer';
|
||||||
import { recordRecentPage } from '../utils/recentPages';
|
import { recordRecentPage } from '../utils/recentPages';
|
||||||
import { useTabTitle } from '../shell/TabTitleContext';
|
import { useTabTitle } from '../shell/TabTitleContext';
|
||||||
import { getProfile } from '../auth/token';
|
|
||||||
|
|
||||||
// ---- amis 渲染层错误边界(class component,捕获子树抛错)----
|
// ---- amis 渲染层错误边界(class component,捕获子树抛错)----
|
||||||
interface ErrorBoundaryState {
|
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 (
|
|
||||||
<button
|
|
||||||
data-testid="designer-open-btn"
|
|
||||||
onClick={() => window.open(`/editor.html?templateId=${encodeURIComponent(templateId)}`, '_blank')}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 8,
|
|
||||||
right: 12,
|
|
||||||
zIndex: 10,
|
|
||||||
background: '#1890ff',
|
|
||||||
color: '#fff',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: 4,
|
|
||||||
padding: '4px 12px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: 500,
|
|
||||||
opacity: 0.85,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
设计
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- 主组件 ----
|
// ---- 主组件 ----
|
||||||
export function PageRenderPage() {
|
export function PageRenderPage() {
|
||||||
const { templateId = '' } = useParams();
|
const { templateId = '' } = useParams();
|
||||||
@@ -147,7 +116,7 @@ export function PageRenderPage() {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div style={{ height: '100%', position: 'relative' }} data-testid="amis-host">
|
<div style={{ height: '100%', position: 'relative' }} data-testid="amis-host">
|
||||||
<DesignButton templateId={templateId} />
|
{/* 设计入口已收敛到顶栏「设计中心」(admin),不再每页一颗按钮 */}
|
||||||
<AmisErrorBoundary templateId={templateId}>
|
<AmisErrorBoundary templateId={templateId}>
|
||||||
<AmisRenderer schema={schema} />
|
<AmisRenderer schema={schema} />
|
||||||
</AmisErrorBoundary>
|
</AmisErrorBoundary>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Topbar — 顶栏:品牌 + 搜索 + 待办入口 + 用户信息 + 设置入口
|
// Topbar — 顶栏:品牌 + 搜索 + 待办入口 + 用户信息 + 设置入口
|
||||||
// 从原型 frame.jsx Topbar 迁移,待办 badge 数由父层传入(后续可接真实 API)
|
// 从原型 frame.jsx Topbar 迁移,待办 badge 数由父层传入(后续可接真实 API)
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Icon } from '../components/ui/Icon';
|
import { Icon } from '../components/ui/Icon';
|
||||||
import { GlobalSearch } from './GlobalSearch';
|
import { GlobalSearch } from './GlobalSearch';
|
||||||
import type { MenuLeaf } from '../api/menu';
|
import type { MenuLeaf } from '../api/menu';
|
||||||
@@ -28,6 +29,8 @@ export function Topbar({
|
|||||||
}: TopbarProps) {
|
}: TopbarProps) {
|
||||||
// 用户名显示:取 name 首字作头像
|
// 用户名显示:取 name 首字作头像
|
||||||
const avatarChar = profile?.name?.[0] ?? '?';
|
const avatarChar = profile?.name?.[0] ?? '?';
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="topbar">
|
<header className="topbar">
|
||||||
@@ -63,6 +66,18 @@ export function Topbar({
|
|||||||
) : null}
|
) : null}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{/* 设计中心(管理员)—— 集中式低代码设计入口,替代每页设计按钮 */}
|
||||||
|
{isAdmin ? (
|
||||||
|
<button
|
||||||
|
className="tb-icon"
|
||||||
|
title="设计中心"
|
||||||
|
data-testid="open-design-center"
|
||||||
|
onClick={() => navigate('/design-center')}
|
||||||
|
>
|
||||||
|
<Icon name="brush" size={17} />
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{/* 设置 */}
|
{/* 设置 */}
|
||||||
<button className="tb-icon" title="界面设置" onClick={onOpenSettings}>
|
<button className="tb-icon" title="界面设置" onClick={onOpenSettings}>
|
||||||
<Icon name="gear" size={17} />
|
<Icon name="gear" size={17} />
|
||||||
|
|||||||
Reference in New Issue
Block a user