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
@@ -12,6 +12,7 @@ import { computed, onUnmounted, ref } from 'vue'
import { ElMessage } from 'element-plus'
import {
NOTIFICATION_SEVERITY_LABELS,
fetchNotificationGroups,
fetchNotificationList,
fetchNotificationSummary,
@@ -20,6 +21,8 @@ import {
type NotificationGroup,
type NotificationItem,
type NotificationListParams,
type NotificationSeverity,
type NotificationSortMode,
} from '@/shared/api/types/modules/notification'
import {
hasNewNotification,
@@ -51,10 +54,14 @@ export function normalizedDayRange(range: [string, string] | null): { startDate?
}
/** 下钻条件:三维缺一维就会把别的主体的行混进这一组的明细(同场景同一天有好几组)。 */
export function detailQueryFor(group: NotificationGroup): NotificationListParams {
export function detailQueryFor(
group: NotificationGroup,
sort: NotificationSortMode = 'severity',
): NotificationListParams {
return {
page: 1,
pageSize: PANEL_DETAIL_LIMIT,
sort,
scene: group.scene,
day: group.day,
subjectUserId: group.subjectUserId,
@@ -106,6 +113,22 @@ export function itemLevel(item: { level: string }): 'error' | 'warning' | 'info'
return item.level === 'error' || item.level === 'info' ? item.level : 'warning'
}
/** 严重度兜底:新后端直接给 severity;旧后端没这列时按 level 推,绝不让标签空白。 */
export function itemSeverity(item: { severity?: string | null; level?: string | null }): NotificationSeverity {
const value = item.severity
if (value === 'urgent' || value === 'high' || value === 'medium' || value === 'low') {
return value
}
if (item.level === 'error') return 'urgent'
if (item.level === 'info') return 'low'
return 'high'
}
/** 中文标签:紧急/高危/中危/低危。 */
export function severityLabel(item: { severity?: string | null; level?: string | null }): string {
return NOTIFICATION_SEVERITY_LABELS[itemSeverity(item)]
}
export function useNotificationBellPanel(options: { uid: () => string }) {
const uid = options.uid
@@ -122,6 +145,8 @@ export function useNotificationBellPanel(options: { uid: () => string }) {
const keyword = ref('')
const dateRange = ref<[string, string] | null>(null)
const category = ref('')
/** 默认按严重度;用户可切「按时间」。 */
const sortMode = ref<NotificationSortMode>('severity')
const expandedKey = ref('')
const details = ref<NotificationItem[]>([])
const detailTotal = ref(0)
@@ -180,6 +205,7 @@ export function useNotificationBellPanel(options: { uid: () => string }) {
pageSize: pageSize.value,
keyword: keyword.value,
category: category.value,
sort: sortMode.value,
...normalizedDayRange(dateRange.value),
})
const applied = applyGroupsPage(result, {
@@ -221,7 +247,7 @@ export function useNotificationBellPanel(options: { uid: () => string }) {
expandedKey.value = key
detailLoading.value = true
try {
const result = await fetchNotificationList(detailQueryFor(group))
const result = await fetchNotificationList(detailQueryFor(group, sortMode.value))
// 请求期间用户可能已经收了另一组:晚到的结果不能盖掉当前展开的那组
if (expandedKey.value !== key) return
details.value = Array.isArray(result?.items) ? result.items : []
@@ -255,6 +281,16 @@ export function useNotificationBellPanel(options: { uid: () => string }) {
void loadPage(1)
}
/** 排序切换:重复点同一个不重复请求;切换后回到第一页并收起明细。 */
function setSortMode(value: NotificationSortMode) {
if (sortMode.value === value) {
return
}
sortMode.value = value
console.log('[notification] 排序切换为', value === 'time' ? '按时间' : '按严重度')
void loadPage(1)
}
/** 类型筛选:重复点同一个不重复请求;切换后回到第一页。 */
function selectCategory(value: string) {
if (category.value === value) {
@@ -370,6 +406,8 @@ export function useNotificationBellPanel(options: { uid: () => string }) {
resetFilters,
rowCount,
selectCategory,
setSortMode,
sortMode,
toggleGroup,
total,
totalPages,