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:
@@ -7,6 +7,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { fetchTodo, type TodoItem } from '../api/todo';
|
||||
import { fetchNotices, markNoticeRead, markAllNoticesRead, type NoticeItem } from '../api/notice';
|
||||
import { fetchMenu, collectLeaves, type MenuLeaf } from '../api/menu';
|
||||
import { loadRecentPages, type RecentPage } from '../utils/recentPages';
|
||||
import { Icon } from '../components/ui/Icon';
|
||||
@@ -165,6 +166,10 @@ export function WorkbenchPage() {
|
||||
const [quickItems, setQuickItems] = useState<QuickItem[]>([]);
|
||||
const [quickLoaded, setQuickLoaded] = useState(false);
|
||||
|
||||
// F2-11 通知公告快照(最近 5 条未读)
|
||||
const [noticeItems, setNoticeItems] = useState<NoticeItem[]>([]);
|
||||
const [noticeLoading, setNoticeLoading] = useState(true);
|
||||
|
||||
// 加载待办快照
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
@@ -217,6 +222,16 @@ export function WorkbenchPage() {
|
||||
.finally(() => setQuickLoaded(true));
|
||||
}, []);
|
||||
|
||||
// 加载通知快照(最近 5 条未读)
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
fetchNotices({ unreadOnly: true, page: 1, perPage: 5 })
|
||||
.then((r) => { if (alive) setNoticeItems(r.items.slice(0, 5)); })
|
||||
.catch(() => alive && setNoticeItems([]))
|
||||
.finally(() => alive && setNoticeLoading(false));
|
||||
return () => { alive = false; };
|
||||
}, []);
|
||||
|
||||
const openPage = (templateId: string) => {
|
||||
navigate(`/page/${templateId}`);
|
||||
};
|
||||
@@ -465,7 +480,100 @@ export function WorkbenchPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 通知公告区:等待 GET /api/notice 端点,当前隐藏 */}
|
||||
{/* F2-11 通知公告卡片 */}
|
||||
{!noticeLoading && noticeItems.length > 0 && (
|
||||
<div className="card" style={{ overflow: 'hidden' }}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
padding: '12px var(--pad)',
|
||||
borderBottom: '1px solid var(--line)',
|
||||
}}
|
||||
>
|
||||
<h3 style={{ margin: 0, fontSize: 'var(--fs)', fontWeight: 600 }}>
|
||||
<Icon name="bell" size={14} style={{ marginRight: 6, color: 'var(--brand)' }} />
|
||||
未读消息
|
||||
<span
|
||||
style={{
|
||||
marginLeft: 8,
|
||||
background: 'var(--err)',
|
||||
color: '#fff',
|
||||
borderRadius: 10,
|
||||
padding: '1px 7px',
|
||||
fontSize: 11,
|
||||
fontWeight: 700,
|
||||
verticalAlign: 'middle',
|
||||
}}
|
||||
>
|
||||
{noticeItems.length}
|
||||
</span>
|
||||
</h3>
|
||||
<button
|
||||
className="btn btn-text btn"
|
||||
onClick={async () => {
|
||||
await markAllNoticesRead().catch(() => null);
|
||||
setNoticeItems([]);
|
||||
}}
|
||||
>
|
||||
全部已读
|
||||
</button>
|
||||
</div>
|
||||
{noticeItems.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 10,
|
||||
padding: '10px var(--pad)',
|
||||
borderBottom: '1px solid var(--line)',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
onClick={async () => {
|
||||
await markNoticeRead(item.id).catch(() => null);
|
||||
setNoticeItems((prev) => prev.filter((n) => n.id !== item.id));
|
||||
}}
|
||||
onMouseEnter={(e) =>
|
||||
((e.currentTarget as HTMLDivElement).style.background = 'var(--brand-softer)')
|
||||
}
|
||||
onMouseLeave={(e) =>
|
||||
((e.currentTarget as HTMLDivElement).style.background = '')
|
||||
}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
width: 8,
|
||||
height: 8,
|
||||
borderRadius: '50%',
|
||||
background: 'var(--brand)',
|
||||
flexShrink: 0,
|
||||
}}
|
||||
/>
|
||||
<span
|
||||
style={{
|
||||
flex: 1,
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
fontSize: 'var(--fs)',
|
||||
}}
|
||||
>
|
||||
{item.title}
|
||||
</span>
|
||||
{item.createtime && (
|
||||
<span className="muted" style={{ fontSize: 'var(--fs-sm)', flexShrink: 0 }}>
|
||||
{(() => {
|
||||
const d = new Date(item.createtime);
|
||||
return `${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
||||
})()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user