| | |
| | | const messageTypes = [ |
| | | { id: 0, label: '心跳检测', value: '0' }, |
| | | { id: 1, label: '后台任务', value: '1' }, |
| | | { id: 2, label: '业务日志', value: '2' } |
| | | ]; |
| | | export { messageTypes }; |
| | | import { Enum } from './enum'; |
| | | const SOCKET_MESSAGE_TYPE = Enum({ |
| | | BACKGROUND_TASK: { |
| | | id: 1, |
| | | value: '1', |
| | | label: '后台任务', |
| | | name: 'background_task' |
| | | }, |
| | | BUSINESS_LOG: { id: 2, value: '2', label: '业务日志', name: 'business_log' } |
| | | }); |
| | | /** |
| | | * 根据socket消息类型字段得到这个类型对象 |
| | | * @param {*} value socket消息类型 |
| | | * @returns 对应的消息类型对象 |
| | | */ |
| | | /** |
| | | * 通过名称查找枚举类 |
| | | * @param {String} value |
| | | * @returns |
| | | */ |
| | | function getByValue(value) { |
| | | for (const type in SOCKET_MESSAGE_TYPE) { |
| | | const typeObj = SOCKET_MESSAGE_TYPE[type] |
| | | if (typeObj.value == value) { |
| | | return typeObj |
| | | } |
| | | } |
| | | } |
| | | export { SOCKET_MESSAGE_TYPE, getByValue }; |