src/enum/socketMessage.js
@@ -1,17 +1,29 @@
const messageTypes = [
  { id: 0, value: '0', label: '心跳机制', name: 'heartbeat' },
  { id: 1, value: '1', label: '后台任务', name: 'background_task' },
  { id: 2, value: '2', label: '业务日志', name: 'business_log' }
];
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) {
  return messageTypes.find((v) => v.value == value);
  for (const type in SOCKET_MESSAGE_TYPE) {
    const typeObj = SOCKET_MESSAGE_TYPE[type]
    if (typeObj.value == value) {
      return typeObj
    }
  }
}
function isHeartbeatMessageByType(type) {
  return type == '0';
}
export { messageTypes, getByValue, isHeartbeatMessageByType };
export { SOCKET_MESSAGE_TYPE, getByValue };