feat(通知): 四级严重度与严重度/时间双排序,客户端与后台管理同步
通知表新增 severity(紧急/高危/中危/低危,V161),由 scene + level 推导且 不回改 level:老客户端配色不受影响,secret_balance 的余量偏低与欠费也能分档。 列表与聚合接口默认按严重度倒序(同档按时间倒序),sort=time 切纯时间排序; 聚合组取组内最高严重度。两端铃铛加彩色等级标签与排序切换,展开明细沿用 同一排序,严重度排序下隐藏会跨天误导的日期头。
This commit is contained in:
@@ -1,11 +1,25 @@
|
||||
import { http } from './http'
|
||||
import { unwrap } from './envelope'
|
||||
|
||||
/** 业务严重度:紧急 / 高危 / 中危 / 低危(后端按 scene + level 推导)。 */
|
||||
export type AdminNotificationSeverity = 'urgent' | 'high' | 'medium' | 'low'
|
||||
|
||||
export type AdminNotificationSortMode = 'severity' | 'time'
|
||||
|
||||
export const ADMIN_NOTIFICATION_SEVERITY_LABELS: Readonly<Record<AdminNotificationSeverity, string>> = {
|
||||
urgent: '紧急',
|
||||
high: '高危',
|
||||
medium: '中危',
|
||||
low: '低危',
|
||||
}
|
||||
|
||||
/** 单条通知(后台铃铛)。 */
|
||||
export interface AdminNotificationItem {
|
||||
id: number
|
||||
scene: string
|
||||
level: string
|
||||
/** 业务严重度;旧后端不返回时前端按 level 兜底。 */
|
||||
severity?: string
|
||||
title: string
|
||||
content: string
|
||||
read: boolean
|
||||
@@ -38,6 +52,8 @@ export interface AdminNotificationGroup {
|
||||
rowCount: number
|
||||
unreadCount: number
|
||||
level: string
|
||||
/** 组内最高严重度。 */
|
||||
severity?: string
|
||||
title: string
|
||||
content: string
|
||||
createdAt: string | null
|
||||
@@ -69,6 +85,8 @@ export interface AdminNotificationListParams {
|
||||
keyword?: string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
/** 排序:severity(默认)或 time;默认值不下发。 */
|
||||
sort?: AdminNotificationSortMode
|
||||
/** 展开聚合组:三个条件取自该组自己返回的值,原样回传。 */
|
||||
scene?: string
|
||||
day?: string
|
||||
@@ -90,6 +108,7 @@ export async function fetchNotificationGroups(
|
||||
keyword: keyword || undefined,
|
||||
startDate: params.startDate || undefined,
|
||||
endDate: params.endDate || undefined,
|
||||
sort: params.sort === 'time' ? 'time' : undefined,
|
||||
},
|
||||
})
|
||||
return unwrap<AdminNotificationGroupPage>(data)
|
||||
@@ -107,6 +126,7 @@ export async function fetchNotificationList(
|
||||
keyword: keyword || undefined,
|
||||
startDate: params.startDate || undefined,
|
||||
endDate: params.endDate || undefined,
|
||||
sort: params.sort === 'time' ? 'time' : undefined,
|
||||
scene: params.scene || undefined,
|
||||
day: params.day || undefined,
|
||||
subjectUserId: params.subjectUserId ?? undefined,
|
||||
|
||||
@@ -75,6 +75,25 @@
|
||||
重置
|
||||
</button>
|
||||
</div>
|
||||
<div class="bell-sort-chips" role="group" aria-label="通知排序">
|
||||
<span class="bell-sort-label">排序</span>
|
||||
<button
|
||||
type="button"
|
||||
class="bell-sort-chip"
|
||||
:class="{ 'is-active': sortMode === 'severity' }"
|
||||
@click="setSortMode('severity')"
|
||||
>
|
||||
严重度
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="bell-sort-chip"
|
||||
:class="{ 'is-active': sortMode === 'time' }"
|
||||
@click="setSortMode('time')"
|
||||
>
|
||||
时间
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading && !groups.length" class="bell-empty">正在加载...</div>
|
||||
@@ -82,13 +101,17 @@
|
||||
<div v-else-if="!groups.length" class="bell-empty">{{ hasFilter ? '没有符合条件的通知' : '暂无通知' }}</div>
|
||||
<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-group"
|
||||
:class="[`bell-item--${group.level || 'warning'}`, { 'bell-group--open': isExpanded(group) }]"
|
||||
@click="toggleGroup(group)"
|
||||
>
|
||||
<div class="bell-item-head">
|
||||
<span class="bell-severity-tag" :class="`bell-severity-tag--${itemSeverity(group)}`">
|
||||
{{ severityLabel(group) }}
|
||||
</span>
|
||||
<span class="bell-item-title">{{ group.title }}</span>
|
||||
<span class="bell-item-time">{{ formatTime(group.createdAt) }}</span>
|
||||
</div>
|
||||
@@ -110,6 +133,9 @@
|
||||
@click="onItemClick(item)"
|
||||
>
|
||||
<div class="bell-item-head">
|
||||
<span class="bell-severity-tag" :class="`bell-severity-tag--${itemSeverity(item)}`">
|
||||
{{ severityLabel(item) }}
|
||||
</span>
|
||||
<span class="bell-item-title">{{ item.title }}</span>
|
||||
<span class="bell-item-time">{{ formatTime(item.createdAt) }}</span>
|
||||
</div>
|
||||
@@ -161,6 +187,8 @@ import {
|
||||
import { todayDateInput } from '@/utils/datetime'
|
||||
import {
|
||||
itemLevel,
|
||||
itemSeverity,
|
||||
severityLabel,
|
||||
startsNewDay as groupStartsNewDay,
|
||||
useNotificationBellPanel,
|
||||
} from '@/layout/notification-bell-panel'
|
||||
@@ -195,6 +223,8 @@ const {
|
||||
reload,
|
||||
resetFilters,
|
||||
rowCount,
|
||||
setSortMode,
|
||||
sortMode,
|
||||
toggleGroup,
|
||||
total,
|
||||
totalPages,
|
||||
@@ -496,6 +526,7 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
.bell-item-title {
|
||||
flex: 1;
|
||||
color: var(--admin-text, #24384d);
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
@@ -505,6 +536,36 @@ onUnmounted(() => {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.bell-severity-tag {
|
||||
flex-shrink: 0;
|
||||
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: #fdecec;
|
||||
color: #c92a2a;
|
||||
}
|
||||
|
||||
.bell-severity-tag--high {
|
||||
background: #fdf3e2;
|
||||
color: #b26a12;
|
||||
}
|
||||
|
||||
.bell-severity-tag--medium {
|
||||
background: #eaf2fb;
|
||||
color: #2f6fb3;
|
||||
}
|
||||
|
||||
.bell-severity-tag--low {
|
||||
background: #f1f4f7;
|
||||
color: #6b7c8e;
|
||||
}
|
||||
|
||||
.bell-item--error .bell-item-title {
|
||||
color: #b23c3c;
|
||||
}
|
||||
@@ -594,6 +655,42 @@ onUnmounted(() => {
|
||||
background: #edf5fb;
|
||||
}
|
||||
|
||||
.bell-sort-chips {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.bell-sort-label {
|
||||
color: #8a99a8;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.bell-sort-chip {
|
||||
height: 24px;
|
||||
padding: 0 10px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 12px;
|
||||
background: #ffffff;
|
||||
color: #667085;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
|
||||
}
|
||||
|
||||
.bell-sort-chip:hover {
|
||||
border-color: var(--admin-primary-strong, #2f5d8b);
|
||||
color: var(--admin-primary-strong, #2f5d8b);
|
||||
}
|
||||
|
||||
.bell-sort-chip.is-active {
|
||||
border-color: var(--admin-primary-strong, #2f5d8b);
|
||||
background: #edf5fb;
|
||||
color: var(--admin-primary-strong, #2f5d8b);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.bell-day-head {
|
||||
padding: 6px 14px;
|
||||
background: #f4f7fa;
|
||||
|
||||
@@ -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