feat(通知): 列表按 场景×自然日×主体用户 聚合成两级,红点按组数亮而明细条数同屏;后管日期面板不再被弹窗压住
V158 给 biz_user_notification 加 subject_user_id(事件主体用户,与收件人 user_id 分家): 一行通知是给某个收件人看的,被通知的那个 uid 原先只活在文案字符串里,没有列就没法按用户成组, 也不肯用正则去解历史文案凑分组键。存量不回填(定案)⇒ 老行 subject_user_id 为 NULL,自成「未标注主体」一组。 写入侧 pushOrRefresh 第 8 参带主体,AUDIENCE_USER 时主体=收件人(故新增 7 参便捷档,68 处调用一行没改); pushToAdminsAnyOf 传 null 并注明理由:一把密钥被 N 个账号共用,不挑一个 uid 冒充。 新增 GET /api/notifications/groups 与 /api/admin/notifications/groups:Java 侧分组(复用 baseWrapper 一份筛选实现), 分页按组切,同屏返回 total=组数 与 rowCount=明细条数;unreadGroupCount 走 COUNT(DISTINCT scene, DATE(created_at), IFNULL(subject_user_id,-1)) —— IFNULL 不能省, MySQL 的 COUNT(DISTINCT a,b,c) 会跳过任一表达式为 NULL 的行,不兜就把存量那一组整个数没。 红点是新增 unreadGroupCount 而不动 unreadCount 语义:已装机老客户端读 unreadCount 画徽标, 换语义会让老客户端出现「红点 3、列表 217 条」对不上。 铃铛两级(后管+桌面各一份):聚合行点击只展开、不替用户标已读,已读必须进明细逐条点; 明细一次最多 50 条,超出显示「另有 N 条未列出」;下钻带 scene+day+subjectUserId(主体为空改下发 subjectUnlabelled 旗标走 IS NULL),少一维就会把同场景同天别主体的行混进这一组的明细——桌面端最初就漏了这一维。 死码随两级视图退场:groupNotificationsByDay/NotificationDayGroup 删掉,用例换成 formatDayLabel/notificationGroupKey/formatGroupCounts。 后管日期选择面板 z-index 抬到 3300(面板 3200)之上:Element 弹层只自 2000 起递增,不抬就被面板压住,表现为「日期点不动」。 playwright 加 E2E_PORT+strictPort:实测 5174/5176 被别的项目的 vite 占着,reuseExistingServer 让 e2e 连上别人的应用, 当时 5 条全红是端口归属问题而不是回归。 验证=后端通知面 66/66(-Dtest='Notification*' 63 + AdminNotificationControllerTest 3)BUILD SUCCESS; 后管 node --test 1819/1819、真浏览器 e2e 10/10(含遮挡与「展开只取本组」); 桌面 node --test 834/834、组件挂载 vitest 8/8;两前端 vue-tsc --noEmit rc=0;ops 值班侧 18/18。 记账三处=后管 source-pin 逐文件基线 notification-bell.test.ts 用例 6→7(该文件钉子仍 0,占比不动); 桌面 catch 棘轮 blocks 298→299(新增那支是 toggleGroup 明细失败写进面板 loadError,非静默,silent 84 一格没涨); 桌面 endpoints 台账补 /api/notifications/groups。 变异自证 7 条全 KILLED:红点按条数/组内没读完就减组数/聚合行直接标已读/明细截断不报数/下钻丢主体/ 丢 IS NULL 旗标/null 主体当值下发。其中「组内没读完就减组数」第一轮 SURVIVED——用例只钉了徽标, 而徽标在 unreadGroupCount 归零时会退回条数兜底,把这条回归盖住了;改成同时钉「N 组未读」chip 才杀掉。 已知盲区(下次补,别当已验):①桌面两级只在 happy-dom 跑过真组件,布局与层级没在真浏览器点过 (桌面日期弹层的层级修复本就在 HEAD 里,不是这批引入);②后管 e2e 夹具没有 subjectUserId=null 的行, 「存量自成一组」在后管 UI 层没被点过,只有后端 WHERE 与桌面组件各一条用例钉着。
This commit is contained in:
@@ -77,25 +77,48 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading && !items.length" class="bell-empty">正在加载...</div>
|
||||
<div v-else-if="loadError && !items.length" class="bell-empty bell-empty--error">{{ loadError }}</div>
|
||||
<div v-else-if="!items.length" class="bell-empty">{{ hasFilter ? '没有符合条件的通知' : '暂无通知' }}</div>
|
||||
<div v-if="loading && !groups.length" class="bell-empty">正在加载...</div>
|
||||
<div v-else-if="loadError && !groups.length" class="bell-empty bell-empty--error">{{ loadError }}</div>
|
||||
<div v-else-if="!groups.length" class="bell-empty">{{ hasFilter ? '没有符合条件的通知' : '暂无通知' }}</div>
|
||||
<ul v-else class="bell-list">
|
||||
<template v-for="group in groupedItems" :key="group.day || 'unknown'">
|
||||
<li class="bell-day-head">{{ group.label }}</li>
|
||||
<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-for="item in group.items"
|
||||
:key="item.id"
|
||||
class="bell-item"
|
||||
:class="[`bell-item--${item.level || 'warning'}`, { 'bell-item--unread': !item.read }]"
|
||||
@click="onItemClick(item)"
|
||||
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-item-title">{{ item.title }}</span>
|
||||
<span class="bell-item-time">{{ formatTime(item.createdAt) }}</span>
|
||||
<span class="bell-item-title">{{ group.title }}</span>
|
||||
<span class="bell-item-time">{{ formatTime(group.createdAt) }}</span>
|
||||
</div>
|
||||
<div class="bell-item-content">{{ group.content }}</div>
|
||||
<div class="bell-group-foot">
|
||||
<span class="bell-group-count">{{ formatGroupCounts(group.rowCount, group.unreadCount) }}</span>
|
||||
<span class="bell-group-toggle">{{ isExpanded(group) ? '收起明细' : '展开明细' }}</span>
|
||||
</div>
|
||||
<div class="bell-item-content">{{ item.content }}</div>
|
||||
</li>
|
||||
<!-- 已读只能进明细逐条点:聚合行上的点击只做展开,避免"看一眼顺手把没看过的全标成已读" -->
|
||||
<template v-if="isExpanded(group)">
|
||||
<li v-if="detailLoading" class="bell-empty bell-empty--detail">正在加载明细...</li>
|
||||
<li v-else-if="!details.length" class="bell-empty bell-empty--detail">这一组里没有通知</li>
|
||||
<li
|
||||
v-for="item in details"
|
||||
:key="item.id"
|
||||
class="bell-item bell-item--detail"
|
||||
:class="{ 'bell-item--unread': !item.read }"
|
||||
@click="onItemClick(item)"
|
||||
>
|
||||
<div class="bell-item-head">
|
||||
<span class="bell-item-title">{{ item.title }}</span>
|
||||
<span class="bell-item-time">{{ formatTime(item.createdAt) }}</span>
|
||||
</div>
|
||||
<div class="bell-item-content">{{ item.content }}</div>
|
||||
</li>
|
||||
<li v-if="!detailLoading && detailTotal > details.length" class="bell-detail-more">
|
||||
另有 {{ detailTotal - details.length }} 条未列出,可缩小日期范围后查看
|
||||
</li>
|
||||
</template>
|
||||
</template>
|
||||
</ul>
|
||||
|
||||
@@ -117,7 +140,7 @@
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
<span class="bell-page-total">共 {{ total }} 条</span>
|
||||
<span class="bell-page-total">共 {{ total }} 组 · 明细 {{ rowCount }} 条</span>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
@@ -129,10 +152,12 @@ import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
import {
|
||||
fetchNotificationGroups,
|
||||
fetchNotificationList,
|
||||
fetchNotificationSummary,
|
||||
markAllNotificationsRead,
|
||||
markNotificationRead,
|
||||
type AdminNotificationGroup,
|
||||
type AdminNotificationItem,
|
||||
} from '@/api/notifications'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
@@ -140,17 +165,22 @@ import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import {
|
||||
NOTIFICATION_POLL_INTERVAL_MS,
|
||||
createSummaryFailureAlerter,
|
||||
formatDayLabel,
|
||||
formatGroupCounts,
|
||||
formatNotificationTime,
|
||||
formatUnreadBadge,
|
||||
groupNotificationsByDay,
|
||||
hasNewNotification,
|
||||
markReadFailureMessage,
|
||||
notificationGroupKey,
|
||||
readLastNotifiedId,
|
||||
writeLastNotifiedId,
|
||||
} from '@/layout/notification-bell-model'
|
||||
import { todayDateInput } from '@/utils/datetime'
|
||||
|
||||
const PAGE_SIZE = 10
|
||||
/** 聚合行比单条高(多一行计数与展开入口),一页 6 组刚好是面板的高度量级。 */
|
||||
const PAGE_SIZE = 6
|
||||
/** 展开一组时列出的明细上限:一组最多可能有几百条,全塞进 DOM 会把面板撑到不可滚动。 */
|
||||
const DETAIL_LIMIT = 50
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const rootRef = ref<HTMLElement | null>(null)
|
||||
@@ -158,8 +188,10 @@ const panelRef = ref<HTMLElement | null>(null)
|
||||
const panelStyle = ref<Record<string, string>>({})
|
||||
|
||||
const unreadCount = ref(0)
|
||||
const items = ref<AdminNotificationItem[]>([])
|
||||
const unreadGroupCount = ref(0)
|
||||
const groups = ref<AdminNotificationGroup[]>([])
|
||||
const total = ref(0)
|
||||
const rowCount = ref(0)
|
||||
const page = ref(1)
|
||||
const panelOpen = ref(false)
|
||||
const loading = ref(false)
|
||||
@@ -168,9 +200,15 @@ const loadError = ref('')
|
||||
const keyword = ref('')
|
||||
const startDate = ref(todayDateInput())
|
||||
const endDate = ref(todayDateInput())
|
||||
const expandedKey = ref('')
|
||||
const details = ref<AdminNotificationItem[]>([])
|
||||
const detailTotal = ref(0)
|
||||
const detailLoading = ref(false)
|
||||
|
||||
const badgeText = computed(() => formatUnreadBadge(unreadCount.value))
|
||||
const groupedItems = computed(() => groupNotificationsByDay(items.value))
|
||||
/** 徽标按**组数**亮:同类事件一天刷几十条不该把红点做成计数器;后端没给这个字段时退回条数。 */
|
||||
const badgeText = computed(() =>
|
||||
formatUnreadBadge(unreadGroupCount.value || unreadCount.value),
|
||||
)
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / PAGE_SIZE)))
|
||||
/** 日期恒为「当天」是默认视图、不算主动筛选:若计入,下方「无筛选才记录已提醒 id」的分支会永久失效。 */
|
||||
const hasFilter = computed(() => Boolean(keyword.value.trim()))
|
||||
@@ -223,6 +261,7 @@ async function refreshSummary() {
|
||||
const summary = await fetchNotificationSummary()
|
||||
summaryFailures.reportSuccess()
|
||||
unreadCount.value = Number(summary?.unreadCount ?? 0)
|
||||
unreadGroupCount.value = Number(summary?.unreadGroupCount ?? 0)
|
||||
const latestId = Number(summary?.latestId ?? 0)
|
||||
if (hasNewNotification(latestId, readLastNotifiedId(currentUid()))) {
|
||||
ElMessage.warning('收到新的告警通知,请点击右上角铃铛查看')
|
||||
@@ -241,21 +280,25 @@ async function loadPage(targetPage: number) {
|
||||
if (loading.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await fetchNotificationList({
|
||||
const result = await fetchNotificationGroups({
|
||||
page: targetPage,
|
||||
pageSize: PAGE_SIZE,
|
||||
keyword: keyword.value,
|
||||
...normalizedDayRange(),
|
||||
})
|
||||
const list = Array.isArray(result?.items) ? result.items : []
|
||||
items.value = list
|
||||
const list = Array.isArray(result?.groups) ? result.groups : []
|
||||
groups.value = list
|
||||
total.value = Number(result?.total ?? list.length)
|
||||
rowCount.value = Number(result?.rowCount ?? list.length)
|
||||
unreadCount.value = Number(result?.unreadCount ?? unreadCount.value)
|
||||
unreadGroupCount.value = Number(result?.unreadGroupCount ?? unreadGroupCount.value)
|
||||
page.value = targetPage
|
||||
loadError.value = ''
|
||||
// 换页/重查后展开态必须清掉:旧组的明细列表与新页的组对不上,会串台
|
||||
collapse()
|
||||
// 无筛选时首页就是最新数据,顺带记录「已提醒过的最大 id」;有筛选时最新 id 不代表真实最新
|
||||
if (targetPage <= 1 && !hasFilter.value && list.length) {
|
||||
const latest = Number(list[0].id)
|
||||
const latest = Number(list[0].latestId)
|
||||
if (latest > 0) {
|
||||
writeLastNotifiedId(currentUid(), Math.max(readLastNotifiedId(currentUid()), latest))
|
||||
}
|
||||
@@ -269,6 +312,56 @@ async function loadPage(targetPage: number) {
|
||||
}
|
||||
}
|
||||
|
||||
function isExpanded(group: AdminNotificationGroup): boolean {
|
||||
return expandedKey.value === notificationGroupKey(group)
|
||||
}
|
||||
|
||||
/** 日期头只在"与上一组不是同一天"时出现:同一天可能有多个组(多个用户/多个场景)。 */
|
||||
function startsNewDay(index: number): boolean {
|
||||
if (index === 0) return true
|
||||
return groups.value[index - 1]?.day !== groups.value[index]?.day
|
||||
}
|
||||
|
||||
function collapse() {
|
||||
expandedKey.value = ''
|
||||
details.value = []
|
||||
detailTotal.value = 0
|
||||
detailLoading.value = false
|
||||
}
|
||||
|
||||
async function toggleGroup(group: AdminNotificationGroup) {
|
||||
if (isExpanded(group)) {
|
||||
collapse()
|
||||
return
|
||||
}
|
||||
collapse()
|
||||
expandedKey.value = notificationGroupKey(group)
|
||||
detailLoading.value = true
|
||||
try {
|
||||
const result = await fetchNotificationList({
|
||||
page: 1,
|
||||
pageSize: DETAIL_LIMIT,
|
||||
scene: group.scene,
|
||||
day: group.day,
|
||||
subjectUserId: group.subjectUserId,
|
||||
subjectUnlabelled: group.subjectUserId === null || group.subjectUserId === undefined,
|
||||
})
|
||||
// 请求期间用户可能已经收起了另一组:晚到的结果不能盖掉当前展开的那组
|
||||
if (expandedKey.value !== notificationGroupKey(group)) return
|
||||
details.value = Array.isArray(result?.items) ? result.items : []
|
||||
detailTotal.value = Number(result?.total ?? details.value.length)
|
||||
} catch (error) {
|
||||
if (expandedKey.value !== notificationGroupKey(group)) return
|
||||
details.value = []
|
||||
detailTotal.value = 0
|
||||
showAdminFeedback(error instanceof Error ? error.message : '明细加载失败', 'error')
|
||||
} finally {
|
||||
if (expandedKey.value === notificationGroupKey(group)) {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function goPage(targetPage: number) {
|
||||
const safe = Math.min(Math.max(1, targetPage), totalPages.value)
|
||||
if (safe === page.value || loading.value) return
|
||||
@@ -323,6 +416,14 @@ async function onItemClick(item: AdminNotificationItem) {
|
||||
await markNotificationRead(item.id)
|
||||
item.read = true
|
||||
unreadCount.value = Math.max(0, unreadCount.value - 1)
|
||||
// 组内未读清零 ⇒ 这一组不再计为未读组,红点(按组数)才会跟着掉一格
|
||||
const owner = groups.value.find((group) => notificationGroupKey(group) === expandedKey.value)
|
||||
if (owner && owner.unreadCount > 0) {
|
||||
owner.unreadCount -= 1
|
||||
if (owner.unreadCount === 0) {
|
||||
unreadGroupCount.value = Math.max(0, unreadGroupCount.value - 1)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// 改前只 console.warn:点了通知没反应,用户只能反复点。失败必须可见(统一出口)。
|
||||
console.warn('[admin-notification] 标记已读失败:', error)
|
||||
@@ -335,10 +436,14 @@ async function readAll() {
|
||||
markingAll.value = true
|
||||
try {
|
||||
await markAllNotificationsRead()
|
||||
for (const item of items.value) {
|
||||
for (const group of groups.value) {
|
||||
group.unreadCount = 0
|
||||
}
|
||||
for (const item of details.value) {
|
||||
item.read = true
|
||||
}
|
||||
unreadCount.value = 0
|
||||
unreadGroupCount.value = 0
|
||||
} catch (error) {
|
||||
console.warn('[admin-notification] 全部已读失败:', error)
|
||||
showAdminFeedback(error instanceof Error ? error.message : '操作失败', 'error')
|
||||
@@ -528,6 +633,70 @@ onUnmounted(() => {
|
||||
background: #f7f9fc;
|
||||
}
|
||||
|
||||
/* ---- 聚合行(默认视图的一级)与明细行(展开后的二级)---- */
|
||||
.bell-group {
|
||||
padding: 11px 14px 8px;
|
||||
border-bottom: 1px solid #f0f3f7;
|
||||
cursor: pointer;
|
||||
transition: background 0.12s ease;
|
||||
}
|
||||
|
||||
.bell-group:hover {
|
||||
background: #f7f9fc;
|
||||
}
|
||||
|
||||
.bell-group--open {
|
||||
background: #f4f8fd;
|
||||
}
|
||||
|
||||
.bell-group-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.bell-group-count {
|
||||
color: #7c8b9a;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.bell-group-toggle {
|
||||
color: var(--admin-primary-strong, #2f5d8b);
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* 明细缩进 + 左侧一道竖线,让"这是上面那一组里的东西"看得出来,而不是又一批同级通知 */
|
||||
.bell-item--detail {
|
||||
padding-left: 26px;
|
||||
background: #fcfdfe;
|
||||
border-bottom-color: #f5f8fb;
|
||||
}
|
||||
|
||||
.bell-item--detail::before {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
width: 2px;
|
||||
height: 26px;
|
||||
margin: 0 0 -8px -14px;
|
||||
border-radius: 2px;
|
||||
background: #dce7f2;
|
||||
}
|
||||
|
||||
.bell-empty--detail {
|
||||
padding: 14px 0;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.bell-detail-more {
|
||||
padding: 8px 14px;
|
||||
color: #8a99a8;
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
background: #fcfdfe;
|
||||
}
|
||||
|
||||
.bell-item--unread {
|
||||
background: #f2f6ff;
|
||||
}
|
||||
@@ -697,3 +866,11 @@ onUnmounted(() => {
|
||||
font-size: 11px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/* 日期选择面板与通知面板同为 body 级浮层,须压在通知面板(3200)之上:
|
||||
Element 弹层只自 2000 起递增,不抬就会被面板挡住,表现为「日期点不动」。 */
|
||||
.bell-date-popper {
|
||||
z-index: 3300 !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user