feat(通知): 四级严重度与严重度/时间双排序,客户端与后台管理同步

通知表新增 severity(紧急/高危/中危/低危,V161),由 scene + level 推导且
不回改 level:老客户端配色不受影响,secret_balance 的余量偏低与欠费也能分档。
列表与聚合接口默认按严重度倒序(同档按时间倒序),sort=time 切纯时间排序;
聚合组取组内最高严重度。两端铃铛加彩色等级标签与排序切换,展开明细沿用
同一排序,严重度排序下隐藏会跨天误导的日期头。
This commit is contained in:
2026-10-21 13:33:07 +08:00
parent f6aa04d0f2
commit 86d78160fd
23 changed files with 804 additions and 40 deletions
@@ -40,6 +40,7 @@ const api = vi.hoisted(() => ({
vi.mock('element-plus', () => ({ ElMessage: message }))
vi.mock('@/shared/api/types/modules/notification.ts', () => ({
NOTIFICATION_CATEGORY_OPTIONS: [],
NOTIFICATION_SEVERITY_LABELS: { urgent: '紧急', high: '高危', medium: '中危', low: '低危' },
fetchNotificationSummary: api.fetchNotificationSummary,
fetchNotificationGroups: api.fetchNotificationGroups,
fetchNotificationList: api.fetchNotificationList,
@@ -174,6 +175,49 @@ describe('NotificationBell:三处失败的用户可见性', () => {
expect(message.error).not.toHaveBeenCalled()
expect(document.querySelectorAll('.bell-item')).toHaveLength(0)
})
it('默认展示四级严重度并按严重度请求;切「时间」后带 sort=time 重查并恢复日期头', async () => {
api.fetchNotificationGroups.mockResolvedValue({
groups: [
group({ latestId: 9, severity: 'urgent', level: 'error', day: '2026-09-13' }),
group({ latestId: 8, subjectUserId: 1160, severity: 'low', level: 'info', day: '2026-09-12' }),
],
total: 2,
rowCount: 2,
unreadGroupCount: 2,
unreadCount: 2,
})
await openPanel()
expect(Array.from(document.querySelectorAll('.bell-severity-tag')).map((el) => el.textContent?.trim()))
.toEqual(['紧急', '低危'])
expect(api.fetchNotificationGroups.mock.calls[0][0].sort).toBe('severity')
// 严重度排序会跨天交错,不挂日期头
expect(document.querySelectorAll('.bell-day-head')).toHaveLength(0)
// 展开明细也要带同一种排序,否则会出现「列表按严重度、明细又按时间」
api.fetchNotificationList.mockResolvedValue({
items: [notification({ id: 9, severity: 'urgent' })],
total: 1,
page: 1,
pageSize: 50,
unreadCount: 1,
})
await expandFirstGroup()
expect(api.fetchNotificationList.mock.calls.at(-1)?.[0].sort).toBe('severity')
const timeButton = Array.from(document.querySelectorAll<HTMLElement>('.bell-sort-chips button'))
.find((button) => button.textContent?.includes('时间'))
expect(timeButton).toBeTruthy()
timeButton!.click()
await flushPromises()
expect(api.fetchNotificationGroups.mock.calls.at(-1)?.[0].sort).toBe('time')
expect(document.querySelectorAll('.bell-day-head')).toHaveLength(2)
await expandFirstGroup()
expect(api.fetchNotificationList.mock.calls.at(-1)?.[0].sort).toBe('time')
})
})
describe('NotificationBell:聚合两级与红点口径', () => {