feat(通知): task_failed 带 ref_json 定位锚点,明细可点直达任务详情
用户原话「都没体现哪个任务id/店铺/用户,咋排查」:通知表只有 title/content, 失败任务又按「用户×模块×自然日」聚合成一条,明细被 5 个 taskNo 预览 + 512 字截断吃掉。 - V162 给 biz_user_notification 加 ref_json(TEXT,可重跑迁移,存量不回填) - 扫描器把桶内每个失败任务写成锚点(taskId/taskNo/moduleType/reason/updatedAt/ deviceId),上限 20 条;品牌任务无 task_no 用 #<id> 兜底,保证至少一条可定位 - 详情接口回传 refs;同键刷新时锚点变化也更新,且不重新点亮已读 - 后台铃铛「展开明细」渲染成可点行,跳任务中心 ?taskNo= 自动开详情抽屉 - 新增判据 taskFailedAdminNotificationCarriesUidAndTaskNoAnchor:管理端正文必须含 uid、每个桶的 ref_json 至少一条非空 taskNo
This commit is contained in:
@@ -13,6 +13,17 @@ export const ADMIN_NOTIFICATION_SEVERITY_LABELS: Readonly<Record<AdminNotificati
|
||||
low: '低危',
|
||||
}
|
||||
|
||||
/** 通知里的结构化定位锚点(当前只有 task_failed 使用:桶内每个失败任务一项)。 */
|
||||
export interface AdminNotificationRef {
|
||||
taskId: number | null
|
||||
/** 任务号;品牌任务为 #<id>。任务详情接口按它查。 */
|
||||
taskNo: string
|
||||
moduleType?: string | null
|
||||
reason?: string | null
|
||||
updatedAt?: string | null
|
||||
deviceId?: string | null
|
||||
}
|
||||
|
||||
/** 单条通知(后台铃铛)。 */
|
||||
export interface AdminNotificationItem {
|
||||
id: number
|
||||
@@ -22,6 +33,8 @@ export interface AdminNotificationItem {
|
||||
severity?: string
|
||||
title: string
|
||||
content: string
|
||||
/** 可点的定位锚点;旧后端/历史行没有这一列时为空。 */
|
||||
refs?: AdminNotificationRef[] | null
|
||||
read: boolean
|
||||
readAt: string | null
|
||||
createdAt: string | null
|
||||
|
||||
@@ -140,6 +140,18 @@
|
||||
<span class="bell-item-time">{{ formatTime(item.createdAt) }}</span>
|
||||
</div>
|
||||
<div class="bell-item-content">{{ item.content }}</div>
|
||||
<div v-if="item.refs && item.refs.length" class="bell-ref-list">
|
||||
<button
|
||||
v-for="ref in item.refs"
|
||||
:key="`${item.id}-${ref.taskNo}`"
|
||||
type="button"
|
||||
class="bell-ref-link"
|
||||
:title="ref.reason || `查看任务 ${ref.taskNo}`"
|
||||
@click.stop="openTaskRef(item, ref)"
|
||||
>
|
||||
{{ ref.taskNo }}<span v-if="ref.reason" class="bell-ref-reason">:{{ ref.reason }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
<li v-if="!detailLoading && detailTotal > details.length" class="bell-detail-more">
|
||||
另有 {{ detailTotal - details.length }} 条未列出,可缩小日期范围后查看
|
||||
@@ -175,14 +187,17 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import type { AdminNotificationItem, AdminNotificationRef } from '@/api/notifications'
|
||||
import {
|
||||
NOTIFICATION_POLL_INTERVAL_MS,
|
||||
formatDayLabel,
|
||||
formatGroupCounts,
|
||||
formatNotificationTime,
|
||||
notificationGroupKey,
|
||||
taskCenterRouteForRef,
|
||||
} from '@/layout/notification-bell-model'
|
||||
import { todayDateInput } from '@/utils/datetime'
|
||||
import {
|
||||
@@ -194,6 +209,7 @@ import {
|
||||
} from '@/layout/notification-bell-panel'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const router = useRouter()
|
||||
|
||||
/**
|
||||
* 面板的数据流(聚合组、明细、两个计数、防抖与取数)整块在 notification-bell-panel.ts。
|
||||
@@ -231,6 +247,16 @@ const {
|
||||
unreadCount,
|
||||
} = useNotificationBellPanel({ uid: () => session.user?.id ?? 0, today: () => todayDateInput() })
|
||||
|
||||
/** 点锚点:先按原逻辑标已读,再跳任务中心(路由带 taskNo,页面进来自动开详情抽屉)。 */
|
||||
function openTaskRef(item: AdminNotificationItem, ref: AdminNotificationRef): void {
|
||||
const target = taskCenterRouteForRef(ref)
|
||||
if (!target) {
|
||||
return
|
||||
}
|
||||
void onItemClick(item)
|
||||
void router.push(target)
|
||||
}
|
||||
|
||||
const rootRef = ref<HTMLElement | null>(null)
|
||||
const panelRef = ref<HTMLElement | null>(null)
|
||||
const panelStyle = ref<Record<string, string>>({})
|
||||
@@ -592,6 +618,12 @@ onUnmounted(() => {
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* 定位锚点:任务号可点,直达任务详情。压低视觉权重,不与正文抢注意力。 */
|
||||
.bell-ref-list { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
|
||||
.bell-ref-link { padding: 0; border: none; background: none; color: var(--admin-primary, #2f5d8b); font-family: inherit; font-size: 12px; line-height: 1.5; text-align: left; word-break: break-all; cursor: pointer; }
|
||||
.bell-ref-link:hover { text-decoration: underline; }
|
||||
.bell-ref-reason { color: #8a94a6; }
|
||||
|
||||
.bell-search {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -201,3 +201,22 @@ export function createSummaryFailureAlerter(feedback: BellFeedbackSink): {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** 通知锚点的最小形状(与 AdminNotificationRef 对齐);不 import api 类型,保持本模块可被 node --test 直接跑。 */
|
||||
export interface NotificationTaskRef {
|
||||
taskNo?: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务锚点 → 任务中心深链。taskNo 是任务详情接口的唯一入参,空值不给链接
|
||||
* (宁可只显示文本,也不跳到一个必然查不到的任务上)。
|
||||
*/
|
||||
export function taskCenterRouteForRef(
|
||||
ref: NotificationTaskRef | null | undefined,
|
||||
): { path: string; query: { taskNo: string } } | null {
|
||||
const taskNo = String(ref?.taskNo ?? '').trim()
|
||||
if (!taskNo) {
|
||||
return null
|
||||
}
|
||||
return { path: '/task-center/board', query: { taskNo } }
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* 页签二「变体采集」= 麦象批量任务(variant-collection),数据口径与列不同故独立页签。
|
||||
* 30s 轮询:页面隐藏暂停、回前台立即刷新、卸载清理;另有手动刷新。 */
|
||||
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { userNotice } from '@/api/user-notice'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
@@ -51,6 +52,7 @@ const POLL_INTERVAL_MS = 30_000
|
||||
/** 公司 tab 的唯一取值出口:非超管恒 null(store 里 companyIdForRequest 已经把它算成 null),
|
||||
* 所以这里不需要再判一次角色——第二把尺子就是第二个口径。 */
|
||||
const companyTab = useCompanyTabStore()
|
||||
const route = useRoute()
|
||||
|
||||
type BoardTab = 'tasks' | 'variant'
|
||||
const activeTab = ref<BoardTab>('tasks')
|
||||
@@ -251,12 +253,12 @@ function changeVariantSize(size: number) {
|
||||
|
||||
// ---------------------------------------------------------------- 详情
|
||||
|
||||
async function openDetail(row: TaskCenterTaskRow) {
|
||||
async function openDetailByTaskNo(taskNo: string, companyId: number | null = companyTab.requestCompanyId) {
|
||||
detailVisible.value = true
|
||||
detailLoading.value = true
|
||||
detail.value = null
|
||||
try {
|
||||
detail.value = await fetchTaskCenterTaskDetail(row.taskNo, companyTab.requestCompanyId)
|
||||
detail.value = await fetchTaskCenterTaskDetail(taskNo, companyId)
|
||||
if (!detail.value) ElMessage.warning('任务不存在或无权查看')
|
||||
} catch (error) {
|
||||
showAdminFeedback(errorText(error, '任务详情加载失败'), 'error')
|
||||
@@ -266,6 +268,10 @@ async function openDetail(row: TaskCenterTaskRow) {
|
||||
}
|
||||
}
|
||||
|
||||
async function openDetail(row: TaskCenterTaskRow) {
|
||||
await openDetailByTaskNo(row.taskNo)
|
||||
}
|
||||
|
||||
function accountOf(row: TaskCenterTaskRow): string {
|
||||
return row.username || (row.userId != null ? `UID ${row.userId}` : '—')
|
||||
}
|
||||
@@ -291,6 +297,11 @@ function onVisibilityChange() {
|
||||
onMounted(() => {
|
||||
void refreshAll()
|
||||
void loadInactiveTabTotal()
|
||||
// 通知明细里的 taskNo 深链:进页直接开抽屉;不锁当前公司 tab(通知可能来自另一家,后端仍按数据权限收口)。
|
||||
const linkedTaskNo = typeof route.query.taskNo === 'string' ? route.query.taskNo.trim() : ''
|
||||
if (linkedTaskNo) {
|
||||
void openDetailByTaskNo(linkedTaskNo, null)
|
||||
}
|
||||
document.addEventListener('visibilitychange', onVisibilityChange)
|
||||
pollTimer = setInterval(() => {
|
||||
if (typeof document !== 'undefined' && document.visibilityState !== 'visible') return
|
||||
|
||||
Reference in New Issue
Block a user