feat: add agent assistant notification bubble functionality

- Introduced a new utility for managing agent assistant notifications.
- Created functions to emit and listen for notification bubbles using custom events.
- Defined types for notification payloads to ensure type safety.
This commit is contained in:
jxxghp
2026-06-23 17:37:48 +08:00
parent 8d9c622dc5
commit 05c2e7855a
5 changed files with 3728 additions and 3372 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
import type { SystemNotification } from '@/api/types'
import api from '@/api'
import { clearUnreadMessages } from '@/utils/badge'
import { emitAgentAssistantNotificationBubble } from '@/utils/agentAssistantBubble'
import { formatDateDifference } from '@core/utils/formatters'
import { useBackground } from '@/composables/useBackground'
import { useToast } from 'vue-toastification'
@@ -452,6 +453,7 @@ function handleMessage(event: MessageEvent) {
if (mergeNotifications([notification], { prepend: true, read: false })) {
hasNewMessage.value = true
emitAgentAssistantNotificationBubble(notification)
}
} catch (error) {
console.error('解析通知失败:', error)

View File

@@ -0,0 +1,56 @@
import type { SystemNotification } from '@/api/types'
const AGENT_ASSISTANT_BUBBLE_EVENT = 'agentAssistantBubble'
export interface AgentAssistantNotificationBubblePayload {
id: string
title?: string
text?: string
type?: string
mtype?: string
source?: string
date?: string
reg_time?: string
}
interface AgentAssistantBubbleEvent extends CustomEvent<AgentAssistantNotificationBubblePayload> {}
function createNotificationBubbleId(notification: SystemNotification) {
if (notification.id) return `notification-${notification.id}`
return `notification-${Date.now()}-${Math.random().toString(16).slice(2)}`
}
// 通知中心和智能助手入口没有父子关系,通过全局事件传递实时通知气泡数据。
export function emitAgentAssistantNotificationBubble(notification: SystemNotification) {
if (typeof window === 'undefined') return
window.dispatchEvent(
new CustomEvent<AgentAssistantNotificationBubblePayload>(AGENT_ASSISTANT_BUBBLE_EVENT, {
detail: {
id: createNotificationBubbleId(notification),
title: notification.title,
text: notification.text,
type: notification.type,
mtype: notification.mtype,
source: notification.source,
date: notification.date,
reg_time: notification.reg_time,
},
}),
)
}
export function onAgentAssistantNotificationBubble(
callback: (payload: AgentAssistantNotificationBubblePayload) => void,
) {
if (typeof window === 'undefined') return () => {}
const handler = (event: Event) => {
callback((event as AgentAssistantBubbleEvent).detail)
}
window.addEventListener(AGENT_ASSISTANT_BUBBLE_EVENT, handler)
return () => window.removeEventListener(AGENT_ASSISTANT_BUBBLE_EVENT, handler)
}