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:聚合两级与红点口径', () => {
@@ -127,6 +127,12 @@ test('buildNotificationListQuery:关键字去空白、空条件不下发、分
})
/** 类型筛选项必须与后端四个大类逐一对应,漏一个用户就永远筛不到那类通知。 */
test('排序参数:默认由后端按严重度,只有切时间排序才下发 sort=time', () => {
assert.equal('sort' in buildNotificationListQuery(), false, '默认 severity 不下发,后端默认即严重度')
assert.equal(buildNotificationListQuery({ sort: 'severity' }).sort, undefined)
assert.equal(buildNotificationListQuery({ sort: 'time' }).sort, 'time')
})
test('类型筛选项覆盖后端四个大类且标签非空', () => {
assert.deepEqual(
NOTIFICATION_CATEGORY_OPTIONS.map((option) => option.value),
@@ -18,7 +18,9 @@ import {
applyMarkReadToCounts,
detailQueryFor,
itemLevel,
itemSeverity,
normalizedDayRange,
severityLabel,
startsNewDay,
} from '@/shared/composables/useNotificationBellPanel'
@@ -112,4 +114,21 @@ describe('用户端通知面板层纯函数', () => {
expect(itemLevel({ level: 'warn' })).toBe('warning')
expect(itemLevel({ level: '' })).toBe('warning')
})
it('四级严重度:后端给值原样用,旧后端缺字段按 level 兜底,绝不出现空标签', () => {
expect(itemSeverity({ severity: 'urgent', level: 'warning' })).toBe('urgent')
expect(itemSeverity({ severity: 'high' })).toBe('high')
expect(itemSeverity({ severity: 'medium' })).toBe('medium')
expect(itemSeverity({ severity: 'low' })).toBe('low')
expect(itemSeverity({ level: 'error' })).toBe('urgent')
expect(itemSeverity({ level: 'info' })).toBe('low')
expect(itemSeverity({ level: 'warning' })).toBe('high')
expect(itemSeverity({ level: '' })).toBe('high')
expect(itemSeverity({ severity: 'fatal', level: 'warning' })).toBe('high')
expect(severityLabel({ severity: 'urgent' })).toBe('紧急')
expect(severityLabel({ severity: 'high' })).toBe('高危')
expect(severityLabel({ severity: 'medium' })).toBe('中危')
expect(severityLabel({ severity: 'low' })).toBe('低危')
})
})