mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-08 17:26:41 +08:00
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:
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
@@ -2,6 +2,7 @@
|
|||||||
import type { SystemNotification } from '@/api/types'
|
import type { SystemNotification } from '@/api/types'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { clearUnreadMessages } from '@/utils/badge'
|
import { clearUnreadMessages } from '@/utils/badge'
|
||||||
|
import { emitAgentAssistantNotificationBubble } from '@/utils/agentAssistantBubble'
|
||||||
import { formatDateDifference } from '@core/utils/formatters'
|
import { formatDateDifference } from '@core/utils/formatters'
|
||||||
import { useBackground } from '@/composables/useBackground'
|
import { useBackground } from '@/composables/useBackground'
|
||||||
import { useToast } from 'vue-toastification'
|
import { useToast } from 'vue-toastification'
|
||||||
@@ -452,6 +453,7 @@ function handleMessage(event: MessageEvent) {
|
|||||||
|
|
||||||
if (mergeNotifications([notification], { prepend: true, read: false })) {
|
if (mergeNotifications([notification], { prepend: true, read: false })) {
|
||||||
hasNewMessage.value = true
|
hasNewMessage.value = true
|
||||||
|
emitAgentAssistantNotificationBubble(notification)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('解析通知失败:', error)
|
console.error('解析通知失败:', error)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user