吸收数字员工通知跨端同步

This commit is contained in:
baiyanyun
2026-06-11 20:27:10 +08:00
parent 4c862ef4b7
commit 8278fdc81c
15 changed files with 745 additions and 193 deletions

View File

@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from 'react';
import { Bell, Check, Mail, MessageSquare, Settings2, X } from 'lucide-react';
import { Bell, Check, Mail, MessageSquare, RefreshCw, Settings2, X } from 'lucide-react';
import { useLocation, useNavigate } from 'react-router-dom';
import { RoleProvider } from '@/contexts/RoleContext';
import {
@@ -9,6 +9,7 @@ import {
getUnreadNotificationCount,
markNotificationRead,
patchNotificationPreferences,
pullNotificationUpdates,
replyToNotification,
type NotificationPreferences,
type UserNotification,
@@ -129,6 +130,7 @@ export default function DigitalEmployeeShell() {
const [notifications, setNotifications] = useState<UserNotification[]>([]);
const [unreadCount, setUnreadCount] = useState(0);
const [notificationsLoading, setNotificationsLoading] = useState(false);
const [notificationsSyncing, setNotificationsSyncing] = useState(false);
const [notificationSettingsOpen, setNotificationSettingsOpen] = useState(false);
const [notificationPreferences, setNotificationPreferences] = useState<NotificationPreferences>(DEFAULT_NOTIFICATION_PREFERENCES);
const [replyDraftById, setReplyDraftById] = useState<Record<string, string>>({});
@@ -195,6 +197,16 @@ export default function DigitalEmployeeShell() {
await refreshNotifications();
}, [refreshNotifications, replyDraftById]);
const handleNotificationSync = useCallback(async () => {
setNotificationsSyncing(true);
try {
await pullNotificationUpdates();
} finally {
setNotificationsSyncing(false);
await refreshNotifications();
}
}, [refreshNotifications]);
const updateNotificationPreferences = useCallback(async (patch: Partial<NotificationPreferences>) => {
const next = await patchNotificationPreferences(patch);
setNotificationPreferences(next);
@@ -262,6 +274,15 @@ export default function DigitalEmployeeShell() {
<span>{unreadCount > 0 ? `${unreadCount} 条未读` : '暂无未读'}</span>
</div>
<div className="de-notification-head-actions">
<button
type="button"
className={`de-header-icon de-notification-close ${notificationsSyncing ? 'active' : ''}`}
title="同步通知"
onClick={() => { void handleNotificationSync(); }}
disabled={notificationsSyncing}
>
<RefreshCw size={14} />
</button>
<button
type="button"
className={`de-header-icon de-notification-close ${notificationSettingsOpen ? 'active' : ''}`}