F1-3: 工作台首页与待办中心成品化

- 新增 WorkbenchPage (/workbench):KPI 卡片(待办数接真实 API)、待办快照(最近 5 条)、常用功能(localStorage 最近访问优先,回退菜单叶子)
- 升级 TodoPage:待办/已办 Tab、关键字本地筛选、pageUrl 优先跳转、Pagination 组件复用
- 新增 api/done.ts:GET /api/done 已办接口,与待办接口同样的 503 降级逻辑
- 新增 utils/recentPages.ts:localStorage 常用功能工具,MAX_RECENT=8 LRU
- 新增 utils/recentPages.test.ts:5 个单测覆盖写入/提升/截断/清空逻辑
- AppShell:顶栏铃铛接真实待办数(60s 轮询);默认 Tab 改为工作台
- App.tsx:新增 /workbench 路由,根路径重定向目标改为 /workbench

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 20:13:53 +08:00
parent 0e5d42debc
commit effc21d929
7 changed files with 1067 additions and 107 deletions

View File

@@ -7,11 +7,12 @@
// 原因:keep-alive 需要将所有 Tab 内容同时挂载在 DOM 中,对 amis 渲染宿主
// 会产生大量隐藏实例,内存/副作用难以控制。当前阶段优先保证正确性,
// keep-alive 作为后续优化项。
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import { getProfile } from '../auth/token';
import { collectLeaves, fetchMenu } from '../api/menu';
import type { MenuLeaf } from '../api/menu';
import { fetchTodo } from '../api/todo';
import { ToastHost } from '../components/ui/Toast';
import { Topbar } from './Topbar';
import { SideMenu } from './SideMenu';
@@ -22,8 +23,11 @@ import { SettingsDrawer, initTheme } from './SettingsDrawer';
const TABS_KEY = 'eip4-tabs';
const ACTIVE_KEY = 'eip4-active-tab';
// 初始 Tab:「待办」作为保底 Tab,不可关闭
const TODO_TAB: Tab = { key: '/todo', title: '待办' };
// 待办 badge 轮询间隔(毫秒),每 60 秒刷新一次
const TODO_POLL_INTERVAL = 60_000;
// 初始 Tab:「工作台」作为保底 Tab,不可关闭
const TODO_TAB: Tab = { key: '/workbench', title: '工作台' };
function loadTabs(): Tab[] {
try {
@@ -60,6 +64,9 @@ export function AppShell() {
const [collapsed, setCollapsed] = useState(false);
const [showSettings, setShowSettings] = useState(false);
const [leaves, setLeaves] = useState<MenuLeaf[]>([]);
// 顶栏铃铛真实待办数(F1-3:接真实 API)
const [todoBadge, setTodoBadge] = useState<number | undefined>(undefined);
const pollTimer = useRef<ReturnType<typeof setInterval> | null>(null);
const profile = getProfile();
@@ -105,6 +112,30 @@ export function AppShell() {
});
}, []);
// 顶栏铃铛:每 TODO_POLL_INTERVAL 轮询一次待办数(503 时 badge 清零不报错)
useEffect(() => {
const loadBadge = () => {
fetchTodo(0, 1)
.then((r) => {
if (r.unavailable) {
setTodoBadge(undefined);
return;
}
// 当前 API 无 totalCount,用 items 数量作近似(maxResults=1 不准确)
// 实际拉取少量条目仅做"有无"判断;完整 count 等待后端 GET /api/todo/count 端点
fetchTodo(0, 200).then((full) => {
if (!full.unavailable) setTodoBadge(full.items.length || undefined);
}).catch(() => setTodoBadge(undefined));
})
.catch(() => setTodoBadge(undefined));
};
loadBadge();
pollTimer.current = setInterval(loadBadge, TODO_POLL_INTERVAL);
return () => {
if (pollTimer.current) clearInterval(pollTimer.current);
};
}, []);
// 打开/激活一个 Tab
const openTab = useCallback(
(key: string, title: string) => {
@@ -125,6 +156,10 @@ export function AppShell() {
openTab('/todo', '待办');
return;
}
if (templateId === '__workbench__') {
openTab('/workbench', '工作台');
return;
}
openTab(`/page/${templateId}`, templateId);
},
[openTab],
@@ -174,6 +209,7 @@ export function AppShell() {
<Topbar
leaves={leaves}
profile={profile}
todoBadge={todoBadge}
onOpenTodo={() => handleActive('/todo')}
onOpenTemplate={handleSearchOpen}
onOpenSettings={() => setShowSettings(true)}