refactor(socket): 移除 Mock Socket 服务并简化导出逻辑
- 删除 mockSocketService.js(916 行) - 简化 socket/index.js(365 行 → 19 行) - 移除 Mock/Real 服务选择逻辑 - 移除 SOCKET_TYPE 和 useMock 标识 - 移除全局调试 API(迁移到 src/devtools/) - 更新相关文档说明 Mock Socket 已移除 现在仅使用真实 Socket.IO 服务连接后端,代码更简洁清晰。 🔧 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -48,16 +48,18 @@ npm start
|
||||
|
||||
### 3. 触发通知
|
||||
|
||||
**Mock 模式**(默认):
|
||||
- 等待 60 秒,会自动推送 1-2 条通知
|
||||
- 或在控制台执行:
|
||||
**测试通知**:
|
||||
- 使用调试 API 发送测试通知:
|
||||
```javascript
|
||||
import { mockSocketService } from './services/mockSocketService.js';
|
||||
mockSocketService.sendTestNotification();
|
||||
```
|
||||
// 方式1: 使用调试工具(推荐)
|
||||
window.__DEBUG__.notification.forceNotification({
|
||||
title: '测试通知',
|
||||
body: '验证暗色模式下的通知样式'
|
||||
});
|
||||
|
||||
**Real 模式**:
|
||||
- 创建测试事件(运行后端测试脚本)
|
||||
// 方式2: 等待后端真实推送
|
||||
// 确保已连接后端,等待真实事件推送
|
||||
```
|
||||
|
||||
### 4. 验证效果
|
||||
|
||||
@@ -139,61 +141,46 @@ npm start
|
||||
|
||||
### 手动触发各类型通知
|
||||
|
||||
```javascript
|
||||
// 引入服务
|
||||
import { mockSocketService } from './services/mockSocketService.js';
|
||||
import { NOTIFICATION_TYPES, PRIORITY_LEVELS } from './constants/notificationTypes.js';
|
||||
> **注意**: Mock Socket 已移除,请使用调试工具或真实后端测试。
|
||||
|
||||
// 测试公告通知(蓝色)
|
||||
mockSocketService.sendTestNotification({
|
||||
type: NOTIFICATION_TYPES.ANNOUNCEMENT,
|
||||
priority: PRIORITY_LEVELS.IMPORTANT,
|
||||
```javascript
|
||||
// 使用调试工具测试不同类型的通知
|
||||
// 确保已开启调试模式:REACT_APP_ENABLE_DEBUG=true
|
||||
|
||||
// 测试公告通知
|
||||
window.__DEBUG__.notification.forceNotification({
|
||||
title: '测试公告通知',
|
||||
content: '这是暗色模式下的蓝色通知',
|
||||
timestamp: Date.now(),
|
||||
body: '这是暗色模式下的蓝色通知',
|
||||
tag: 'test_announcement',
|
||||
autoClose: 0,
|
||||
});
|
||||
|
||||
// 测试股票上涨(红色)
|
||||
mockSocketService.sendTestNotification({
|
||||
type: NOTIFICATION_TYPES.STOCK_ALERT,
|
||||
priority: PRIORITY_LEVELS.URGENT,
|
||||
title: '测试股票上涨',
|
||||
content: '宁德时代 +5.2%',
|
||||
extra: { priceChange: '+5.2%' },
|
||||
timestamp: Date.now(),
|
||||
autoClose: 0,
|
||||
window.__DEBUG__.notification.forceNotification({
|
||||
title: '🔴 测试股票上涨',
|
||||
body: '宁德时代 +5.2%',
|
||||
tag: 'test_stock_up',
|
||||
});
|
||||
|
||||
// 测试股票下跌(绿色)
|
||||
mockSocketService.sendTestNotification({
|
||||
type: NOTIFICATION_TYPES.STOCK_ALERT,
|
||||
priority: PRIORITY_LEVELS.IMPORTANT,
|
||||
title: '测试股票下跌',
|
||||
content: '比亚迪 -3.8%',
|
||||
extra: { priceChange: '-3.8%' },
|
||||
timestamp: Date.now(),
|
||||
autoClose: 0,
|
||||
window.__DEBUG__.notification.forceNotification({
|
||||
title: '🟢 测试股票下跌',
|
||||
body: '比亚迪 -3.8%',
|
||||
tag: 'test_stock_down',
|
||||
});
|
||||
|
||||
// 测试事件动向(橙色)
|
||||
mockSocketService.sendTestNotification({
|
||||
type: NOTIFICATION_TYPES.EVENT_ALERT,
|
||||
priority: PRIORITY_LEVELS.IMPORTANT,
|
||||
title: '测试事件动向',
|
||||
content: '央行宣布降准',
|
||||
timestamp: Date.now(),
|
||||
autoClose: 0,
|
||||
window.__DEBUG__.notification.forceNotification({
|
||||
title: '🟠 测试事件动向',
|
||||
body: '央行宣布降准',
|
||||
tag: 'test_event',
|
||||
});
|
||||
|
||||
// 测试分析报告(紫色)
|
||||
mockSocketService.sendTestNotification({
|
||||
type: NOTIFICATION_TYPES.ANALYSIS_REPORT,
|
||||
priority: PRIORITY_LEVELS.NORMAL,
|
||||
title: '测试分析报告',
|
||||
content: '医药行业深度报告',
|
||||
timestamp: Date.now(),
|
||||
autoClose: 0,
|
||||
window.__DEBUG__.notification.forceNotification({
|
||||
title: '🟣 测试分析报告',
|
||||
body: '医药行业深度报告',
|
||||
tag: 'test_report',
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -330,13 +330,14 @@ if (Notification.permission === 'granted') {
|
||||
|
||||
### 关键文件
|
||||
|
||||
- `src/services/mockSocketService.js` - Mock Socket 服务
|
||||
- `src/services/socketService.js` - 真实 Socket.IO 服务
|
||||
- `src/services/socket/index.js` - 统一导出
|
||||
- `src/contexts/NotificationContext.js` - 通知上下文(含适配器)
|
||||
- `src/services/socketService.js` - Socket.IO 服务
|
||||
- `src/services/socket/index.js` - Socket 服务导出
|
||||
- `src/contexts/NotificationContext.js` - 通知上下文
|
||||
- `src/hooks/useEventNotifications.js` - React Hook
|
||||
- `src/views/Community/components/EventList.js` - 事件列表集成
|
||||
|
||||
> **注意**: `mockSocketService.js` 已移除(2025-01-10),现仅使用真实 Socket 连接。
|
||||
|
||||
### 数据流
|
||||
|
||||
```
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
# 实时消息推送系统 - 完整技术文档
|
||||
|
||||
> **版本**: v2.11.0
|
||||
> **更新日期**: 2025-01-07
|
||||
> **更新日期**: 2025-01-10
|
||||
> **文档类型**: 快速入门 + 完整技术规格
|
||||
>
|
||||
> ⚠️ **重要更新**: Mock Socket 已移除(2025-01-10),文档中关于 `mockSocketService` 的内容仅供历史参考。
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user