feat(通知): 四级严重度与严重度/时间双排序,客户端与后台管理同步
通知表新增 severity(紧急/高危/中危/低危,V161),由 scene + level 推导且 不回改 level:老客户端配色不受影响,secret_balance 的余量偏低与欠费也能分档。 列表与聚合接口默认按严重度倒序(同档按时间倒序),sort=time 切纯时间排序; 聚合组取组内最高严重度。两端铃铛加彩色等级标签与排序切换,展开明细沿用 同一排序,严重度排序下隐藏会跨天误导的日期头。
This commit is contained in:
@@ -13,6 +13,7 @@ import { computed, onUnmounted, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
import {
|
||||
ADMIN_NOTIFICATION_SEVERITY_LABELS,
|
||||
fetchNotificationGroups,
|
||||
fetchNotificationList,
|
||||
fetchNotificationSummary,
|
||||
@@ -20,6 +21,8 @@ import {
|
||||
markNotificationRead,
|
||||
type AdminNotificationGroup,
|
||||
type AdminNotificationItem,
|
||||
type AdminNotificationSeverity,
|
||||
type AdminNotificationSortMode,
|
||||
} from '@/api/notifications'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import {
|
||||
@@ -64,10 +67,14 @@ export function normalizedDayRange(startDate: string, endDate: string): { startD
|
||||
}
|
||||
|
||||
/** 下钻条件:三维缺一维就会把别的主体的行混进这一组的明细(同场景同一天有好几组)。 */
|
||||
export function detailQueryFor(group: AdminNotificationGroup) {
|
||||
export function detailQueryFor(
|
||||
group: AdminNotificationGroup,
|
||||
sort: AdminNotificationSortMode = 'severity',
|
||||
) {
|
||||
return {
|
||||
page: 1,
|
||||
pageSize: PANEL_DETAIL_LIMIT,
|
||||
sort,
|
||||
scene: group.scene,
|
||||
day: group.day,
|
||||
subjectUserId: group.subjectUserId,
|
||||
@@ -125,6 +132,24 @@ 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
|
||||
}): AdminNotificationSeverity {
|
||||
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 ADMIN_NOTIFICATION_SEVERITY_LABELS[itemSeverity(item)]
|
||||
}
|
||||
|
||||
export function useNotificationBellPanel(options: NotificationPanelOptions) {
|
||||
const uid = options.uid
|
||||
const today = options.today
|
||||
@@ -141,6 +166,8 @@ export function useNotificationBellPanel(options: NotificationPanelOptions) {
|
||||
const keyword = ref('')
|
||||
const startDate = ref(today())
|
||||
const endDate = ref(today())
|
||||
/** 默认按严重度;可切「按时间」。 */
|
||||
const sortMode = ref<AdminNotificationSortMode>('severity')
|
||||
const expandedKey = ref('')
|
||||
const details = ref<AdminNotificationItem[]>([])
|
||||
const detailTotal = ref(0)
|
||||
@@ -204,6 +231,7 @@ export function useNotificationBellPanel(options: NotificationPanelOptions) {
|
||||
page: targetPage,
|
||||
pageSize: PANEL_PAGE_SIZE,
|
||||
keyword: keyword.value,
|
||||
sort: sortMode.value,
|
||||
...normalizedDayRange(startDate.value, endDate.value),
|
||||
})
|
||||
const applied = applyGroupsPage(result, {
|
||||
@@ -244,7 +272,7 @@ export function useNotificationBellPanel(options: NotificationPanelOptions) {
|
||||
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 : []
|
||||
@@ -279,6 +307,15 @@ export function useNotificationBellPanel(options: NotificationPanelOptions) {
|
||||
void loadPage(1)
|
||||
}
|
||||
|
||||
/** 排序切换:同一档不重复请求;切换后回到第一页并收起明细。 */
|
||||
function setSortMode(value: AdminNotificationSortMode) {
|
||||
if (sortMode.value === value) {
|
||||
return
|
||||
}
|
||||
sortMode.value = value
|
||||
void loadPage(1)
|
||||
}
|
||||
|
||||
async function onItemClick(item: AdminNotificationItem) {
|
||||
if (item.read) return
|
||||
try {
|
||||
@@ -363,6 +400,8 @@ export function useNotificationBellPanel(options: NotificationPanelOptions) {
|
||||
badgeText,
|
||||
totalPages,
|
||||
hasFilter,
|
||||
sortMode,
|
||||
setSortMode,
|
||||
dateRangeValue,
|
||||
onDateRangeChange,
|
||||
refreshSummary,
|
||||
|
||||
Reference in New Issue
Block a user