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
@@ -35,11 +35,29 @@ export const NOTIFICATION_CATEGORY_OPTIONS: ReadonlyArray<{
export type NotificationLevel = 'info' | 'warning' | 'error'
/** 业务严重度:紧急 / 高危 / 中危 / 低危(后端按 scene + level 推导,前端只展示与排序)。 */
export type NotificationSeverity = 'urgent' | 'high' | 'medium' | 'low'
/** 列表排序:默认按严重度;time=按时间倒序。 */
export type NotificationSortMode = 'severity' | 'time'
export const NOTIFICATION_SEVERITY_LABELS: Readonly<Record<NotificationSeverity, string>> = {
urgent: '紧急',
high: '高危',
medium: '中危',
low: '低危',
}
/** 优先级顺序:排序/筛选选项都从这里取,避免两份顺序漂移。 */
export const NOTIFICATION_SEVERITY_ORDER: readonly NotificationSeverity[] = ['urgent', 'high', 'medium', 'low']
export interface NotificationItem {
id: number
scene: string
category: string
level: string
/** 业务严重度;旧后端不返回时前端按 level 兜底。 */
severity?: string
title: string
content: string
read: boolean
@@ -72,6 +90,8 @@ export interface NotificationGroup {
rowCount: number
unreadCount: number
level: string
/** 组内最高严重度。 */
severity?: string
title: string
content: string
createdAt: string | null
@@ -108,6 +128,8 @@ export interface NotificationListParams {
category?: string
startDate?: string
endDate?: string
/** 排序:severity(默认)或 time;默认值不下发,由后端兜底。 */
sort?: NotificationSortMode
/** 展开聚合组:两个条件取自该组自己返回的值,原样回传(空表示不限制)。 */
scene?: string
day?: string
@@ -144,6 +166,10 @@ export function buildNotificationListQuery(
if (params.endDate) {
query.endDate = params.endDate
}
// severity 是后端默认值,不必下发;只有切到时间排序时才带参,减少老后端/日志噪音。
if (params.sort === 'time') {
query.sort = 'time'
}
if (params.scene) {
query.scene = params.scene
}
@@ -124,6 +124,25 @@
{{ option.label }}
</button>
</div>
<div class="bell-sort-chips" role="group" aria-label="通知排序">
<span class="bell-sort-label">排序</span>
<button
type="button"
class="bell-chip"
:class="{ 'is-active': sortMode === 'severity' }"
@click="setSortMode('severity')"
>
严重度
</button>
<button
type="button"
class="bell-chip"
:class="{ 'is-active': sortMode === 'time' }"
@click="setSortMode('time')"
>
时间
</button>
</div>
<div class="bell-search-days">
<el-date-picker
:model-value="dateRange"
@@ -179,7 +198,8 @@
<ul v-else class="bell-list">
<template v-for="(group, index) in groups" :key="notificationGroupKey(group)">
<li v-if="startsNewDay(index)" class="bell-day-head">{{ formatDayLabel(group.day) }}</li>
<!-- 严重度排序会跨天交错,日期头只在时间排序下有意义 -->
<li v-if="sortMode === 'time' && startsNewDay(index)" class="bell-day-head">{{ formatDayLabel(group.day) }}</li>
<li
class="bell-item bell-group"
:class="[`bell-item--${itemLevel(group)}`, { 'bell-group--open': isExpanded(group) }]"
@@ -188,6 +208,9 @@
<NotificationLevelIcon :level="itemLevel(group)" />
<div class="bell-item-main">
<div class="bell-item-head">
<span class="bell-severity-tag" :class="`bell-severity-tag--${itemSeverity(group)}`">
{{ severityLabel(group) }}
</span>
<span class="bell-item-title" :title="group.title">{{ group.title }}</span>
<span
class="bell-item-dot"
@@ -217,6 +240,9 @@
<NotificationLevelIcon :level="itemLevel(item)" />
<div class="bell-item-main">
<div class="bell-item-head">
<span class="bell-severity-tag" :class="`bell-severity-tag--${itemSeverity(item)}`">
{{ severityLabel(item) }}
</span>
<span class="bell-item-title" :title="item.title">{{ item.title }}</span>
<span class="bell-item-dot" :class="{ 'bell-item-dot--on': !item.read }" aria-hidden="true"></span>
<span class="bell-item-time">{{ formatTime(item.createdAt) }}</span>
@@ -275,6 +301,8 @@ import { NOTIFICATION_CATEGORY_OPTIONS } from '@/shared/api/types/modules/notifi
import {
PANEL_PAGE_SIZES as PAGE_SIZES,
itemLevel,
itemSeverity,
severityLabel,
startsNewDay as groupStartsNewDay,
useNotificationBellPanel,
} from '@/shared/composables/useNotificationBellPanel'
@@ -329,6 +357,8 @@ const {
resetFilters,
rowCount,
selectCategory,
setSortMode,
sortMode,
toggleGroup,
total,
totalPages,
@@ -718,6 +748,18 @@ onUnmounted(() => {
font-weight: 500;
}
.bell-sort-chips {
display: flex;
align-items: center;
gap: 6px;
}
.bell-sort-label {
margin-right: 2px;
color: var(--bell-text-mute);
font-size: 11px;
}
.bell-search-days {
display: flex;
align-items: center;
@@ -933,6 +975,56 @@ onUnmounted(() => {
white-space: nowrap;
}
.bell-severity-tag {
flex: 0 0 auto;
padding: 1px 6px;
border: 1px solid currentColor;
border-radius: 999px;
font-size: 10.5px;
font-weight: 600;
line-height: 1.5;
}
.bell-severity-tag--urgent {
background: rgba(255, 123, 123, 0.12);
color: #ff7b7b;
}
.bell-severity-tag--high {
background: rgba(240, 187, 97, 0.12);
color: #f0bb61;
}
.bell-severity-tag--medium {
background: rgba(110, 168, 255, 0.12);
color: #6ea8ff;
}
.bell-severity-tag--low {
background: rgba(147, 161, 179, 0.12);
color: #93a1b3;
}
.bell-panel--light .bell-severity-tag--urgent {
background: #fdecec;
color: #c92a2a;
}
.bell-panel--light .bell-severity-tag--high {
background: #fdf3e2;
color: #b26a12;
}
.bell-panel--light .bell-severity-tag--medium {
background: #eaf2fb;
color: #2f6fb3;
}
.bell-panel--light .bell-severity-tag--low {
background: #f1f4f7;
color: #6b7c8e;
}
.bell-item--unread .bell-item-title {
color: var(--bell-text);
font-weight: 700;
@@ -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,