Files
ai-kefu-admin/admin/src/utils/sys/mittBus.ts
T
浅念 7cdb4fc970 chore: 锁屏与通知组件删除(enabled:false的最终清理)
Phase 3 终审 M-1/M-2 摘入口后组件保留待决,本提交最终删除:
- art-screen-lock/ 与 art-notification/ 组件目录
- component.ts screen-lock 全局组件项、headerBar.ts notification 项
- types/config HeaderBarFeatureConfig.notification 字段、
  useHeaderBar shouldShowNotification
- art-header-bar 通知按钮/挂载/showNotice/visibleNotice/
  bodyCloseNotice 与 document 点击监听、.notice-button 样式
- components.d.ts 两条目;crypto-js 依赖全套(env.d.ts 声明/
  package.json/lockfile/optimizeDeps)——唯一消费方是锁屏
- en/zh 孤儿语言键(notice.* / lockScreen.* / topBar.user.lockScreen)
  与 mittBus openLockScreen 事件类型(无发射/订阅方)

grep 零残留;vitest 164 passed;build 通过(主 chunk 358.45→355.84 kB,
crypto-js 出预构建);auto-imports.d.ts 行尾漂移已还原。
CLAUDE.md Phase 4 清理单 6/7 结项(并补记 8/9 随 Task 5E/5D 结项)。

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-14 10:43:13 +08:00

61 lines
1.5 KiB
TypeScript

/**
* 全局事件总线模块
*
* 基于 mitt 库实现的类型安全的事件总线
*
* ## 主要功能
*
* - 跨组件通信(发布/订阅模式)
* - 类型安全的事件定义和调用
* - 全局事件管理(烟花效果、设置面板、搜索对话框等)
* - 解耦组件间的直接依赖
*
* ## 使用场景
*
* - 跨层级组件通信
* - 全局功能触发(设置、搜索、聊天等)
* - 特效触发(烟花效果)
* - 避免 props 层层传递
*
* ## 用法示例
*
* ```typescript
* // 订阅事件
* mittBus.on('openSetting', () => { ... })
*
* // 发布事件
* mittBus.emit('openSetting')
*
* // 带参数的事件
* mittBus.emit('triggerFireworks', 'image-url')
* ```
*
* ## 已定义的事件
*
* - triggerFireworks: 触发烟花效果(可选图片URL)
* - openSetting: 打开设置面板
* - openSearchDialog: 打开搜索对话框
* - openChat: 打开聊天窗口
*
* @module utils/sys/mittBus
* @author Art Design Pro Team
*/
import mitt, { type Emitter } from 'mitt'
// 定义事件类型映射
type Events = {
// 烟花效果事件 - 可选的图片URL参数
triggerFireworks: string | undefined
// 打开设置面板事件 - 无参数
openSetting: void
// 打开搜索对话框事件 - 无参数
openSearchDialog: void
// 打开聊天窗口事件 - 无参数
openChat: void
}
// 创建类型安全的事件总线实例
const mittBus: Emitter<Events> = mitt<Events>()
export default mittBus