F2-11: 消息中心前端 — Drawer、顶栏铃铛、工作台通知卡、e2e

- src/api/notice.ts:新增 fetchNotices/fetchUnreadCount/markNoticeRead/markAllNoticesRead
- src/shell/NoticeDrawer.tsx:消息中心抽屉(未读蓝点/展开内容/全部已读/过滤标签)
- src/shell/Topbar.tsx:新增消息图标按钮(doc 图标,noticeBadge badge)
- src/shell/AppShell.tsx:消息未读数 60s 轮询 + NoticeDrawer 状态管理
- src/pages/WorkbenchPage.tsx:点亮通知公告卡片(原占位注释替换为真实卡片)
- e2e/notice.spec.ts:5 个用例(API 3 + UI 2),50/50 全绿
- e2e/artifacts/f2-11/:截图(工作台卡片/Drawer 展开/全部已读后)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 02:27:05 +08:00
parent c8d3209e4d
commit a1c60f8a42
9 changed files with 845 additions and 1 deletions

View File

@@ -13,12 +13,14 @@ import { getProfile } from '../auth/token';
import { collectLeaves, fetchMenu } from '../api/menu';
import type { MenuLeaf } from '../api/menu';
import { fetchTodo } from '../api/todo';
import { fetchUnreadCount } from '../api/notice';
import { ToastHost } from '../components/ui/Toast';
import { Topbar } from './Topbar';
import { SideMenu } from './SideMenu';
import { TabBar } from './TabBar';
import type { Tab } from './TabBar';
import { SettingsDrawer, initTheme } from './SettingsDrawer';
import { NoticeDrawer } from './NoticeDrawer';
import { TabTitleContext } from './TabTitleContext';
const TABS_KEY = 'eip4-tabs';
@@ -67,7 +69,11 @@ export function AppShell() {
const [leaves, setLeaves] = useState<MenuLeaf[]>([]);
// 顶栏铃铛真实待办数(F1-3:接真实 API)
const [todoBadge, setTodoBadge] = useState<number | undefined>(undefined);
// F2-11 消息未读数
const [noticeBadge, setNoticeBadge] = useState<number | undefined>(undefined);
const [showNotice, setShowNotice] = useState(false);
const pollTimer = useRef<ReturnType<typeof setInterval> | null>(null);
const noticePollTimer = useRef<ReturnType<typeof setInterval> | null>(null);
const profile = getProfile();
@@ -145,6 +151,20 @@ export function AppShell() {
};
}, []);
// F2-11 消息未读数轮询(60s,与待办同频)
useEffect(() => {
const loadNoticeBadge = () => {
fetchUnreadCount()
.then((n) => setNoticeBadge(n > 0 ? n : undefined))
.catch(() => setNoticeBadge(undefined));
};
loadNoticeBadge();
noticePollTimer.current = setInterval(loadNoticeBadge, TODO_POLL_INTERVAL);
return () => {
if (noticePollTimer.current) clearInterval(noticePollTimer.current);
};
}, []);
// F2-13:回填 Tab 标题(PageRenderPage 拿到 schema title 后调用)
const updateTabTitle = useCallback((path: string, title: string) => {
setTabs((prev) =>
@@ -226,7 +246,9 @@ export function AppShell() {
leaves={leaves}
profile={profile}
todoBadge={todoBadge}
noticeBadge={noticeBadge}
onOpenTodo={() => handleActive('/todo')}
onOpenNotice={() => setShowNotice(true)}
onOpenTemplate={handleSearchOpen}
onOpenSettings={() => setShowSettings(true)}
/>
@@ -258,6 +280,18 @@ export function AppShell() {
<ToastHost />
{showSettings ? <SettingsDrawer onClose={() => setShowSettings(false)} /> : null}
{/* F2-11 消息中心抽屉 */}
{showNotice ? (
<NoticeDrawer
onClose={() => setShowNotice(false)}
onReadChange={() => {
fetchUnreadCount()
.then((n) => setNoticeBadge(n > 0 ? n : undefined))
.catch(() => setNoticeBadge(undefined));
}}
/>
) : null}
</div>
);
}