搜索结果列表页面开发
This commit is contained in:
35
src/utils/eventBus.ts
Normal file
35
src/utils/eventBus.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import mitt from 'mitt';
|
||||
|
||||
export type EventBus = {
|
||||
logout?: boolean
|
||||
login?: any
|
||||
updateNaviBar: void
|
||||
responseError:string
|
||||
updateMrAction:string
|
||||
updateIssueAction:string
|
||||
notice: void
|
||||
forbiddenRefresh: void
|
||||
microRouterChange: void
|
||||
openModal:void
|
||||
updateNotice: number
|
||||
updateUserInfo: Record<string, any>
|
||||
reportView: void // 子应用中的路由主动上报
|
||||
}
|
||||
|
||||
const emitter = mitt<EventBus>();
|
||||
|
||||
export const addEventListener = (evtName: keyof EventBus, callback: (payload: any) => void) => emitter.on(evtName, callback);
|
||||
|
||||
export const emitEvent = (evtName: keyof EventBus, payload?: any) => emitter.emit(evtName, payload);
|
||||
|
||||
export const offEvent = (evtName: keyof EventBus, handler?:any) => emitter.off(evtName, handler || undefined);
|
||||
|
||||
export const offEvents = (list: Array<keyof EventBus>) => {
|
||||
list.forEach(offEvent);
|
||||
};
|
||||
|
||||
export const getEvents = () => emitter.all;
|
||||
|
||||
export const clearEvent = () => emitter.all.clear();
|
||||
|
||||
export default emitter;
|
||||
Reference in New Issue
Block a user