From a9f0c5ced245a7d44f5e2333ebcf4a65d17c2409 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Mon, 17 Nov 2025 14:47:24 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E5=88=A0=E9=99=A4=E6=B5=8B=E8=AF=95=20?= =?UTF-8?q?API=EF=BC=88=E4=BC=98=E5=85=88=EF=BC=89=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contexts/NotificationContext.js | 86 ----------------------------- 1 file changed, 86 deletions(-) diff --git a/src/contexts/NotificationContext.js b/src/contexts/NotificationContext.js index 07e2ccc2..7120c23f 100644 --- a/src/contexts/NotificationContext.js +++ b/src/contexts/NotificationContext.js @@ -984,92 +984,6 @@ export const NotificationProvider = ({ children }) => { }; }, [browserPermission, toast]); - // 🔧 开发环境调试:暴露方法到 window - useEffect(() => { - if (process.env.NODE_ENV === 'development' || process.env.REACT_APP_ENABLE_DEBUG === 'true') { - if (typeof window !== 'undefined') { - window.__TEST_NOTIFICATION__ = { - // 手动触发网页通知 - testWebNotification: (type = 'event_alert', priority = 'normal') => { - console.log('%c[Debug] 手动触发网页通知', 'color: #FF9800; font-weight: bold;'); - - const testData = { - id: `test_${Date.now()}`, - type: type, - priority: priority, - title: '🧪 测试网页通知', - content: `这是一条测试${type === 'announcement' ? '公告' : type === 'stock_alert' ? '股票' : type === 'event_alert' ? '事件' : '分析'}通知 (优先级: ${priority})`, - timestamp: Date.now(), - clickable: true, - link: '/home', - }; - - console.log('测试数据:', testData); - addNotification(testData); - console.log('✅ 通知已添加到队列'); - }, - - // 测试所有类型 - testAllTypes: () => { - console.log('%c[Debug] 测试所有通知类型', 'color: #FF9800; font-weight: bold;'); - const types = ['announcement', 'stock_alert', 'event_alert', 'analysis_report']; - types.forEach((type, i) => { - setTimeout(() => { - window.__TEST_NOTIFICATION__.testWebNotification(type, 'normal'); - }, i * 2000); // 每 2 秒一个 - }); - }, - - // 测试所有优先级 - testAllPriorities: () => { - console.log('%c[Debug] 测试所有优先级', 'color: #FF9800; font-weight: bold;'); - const priorities = ['normal', 'important', 'urgent']; - priorities.forEach((priority, i) => { - setTimeout(() => { - window.__TEST_NOTIFICATION__.testWebNotification('event_alert', priority); - }, i * 2000); - }); - }, - - // 帮助 - help: () => { - console.log('\n%c=== 网页通知测试 API ===', 'color: #FF9800; font-weight: bold; font-size: 16px;'); - console.log('\n%c基础用法:', 'color: #2196F3; font-weight: bold;'); - console.log(' window.__TEST_NOTIFICATION__.testWebNotification(type, priority)'); - console.log('\n%c参数说明:', 'color: #2196F3; font-weight: bold;'); - console.log(' type (通知类型):'); - console.log(' - "announcement" 公告通知(蓝色)'); - console.log(' - "stock_alert" 股票动向(红色/绿色)'); - console.log(' - "event_alert" 事件动向(橙色)'); - console.log(' - "analysis_report" 分析报告(紫色)'); - console.log('\n priority (优先级):'); - console.log(' - "normal" 普通(15秒自动关闭)'); - console.log(' - "important" 重要(30秒自动关闭)'); - console.log(' - "urgent" 紧急(不自动关闭)'); - console.log('\n%c示例:', 'color: #4CAF50; font-weight: bold;'); - console.log(' // 测试紧急事件通知'); - console.log(' window.__TEST_NOTIFICATION__.testWebNotification("event_alert", "urgent")'); - console.log('\n // 测试所有类型'); - console.log(' window.__TEST_NOTIFICATION__.testAllTypes()'); - console.log('\n // 测试所有优先级'); - console.log(' window.__TEST_NOTIFICATION__.testAllPriorities()'); - console.log('\n'); - } - }; - - console.log('[NotificationContext] 🔧 调试 API 已加载: window.__TEST_NOTIFICATION__'); - console.log('[NotificationContext] 💡 使用 window.__TEST_NOTIFICATION__.help() 查看帮助'); - } - } - - // 清理函数 - return () => { - if (typeof window !== 'undefined' && window.__TEST_NOTIFICATION__) { - delete window.__TEST_NOTIFICATION__; - } - }; - }, [addNotification]); // 依赖 addNotification 函数 - const value = { notifications, isConnected,