index.js 3.09 KB
Newer Older
崔佳豪's avatar
崔佳豪 committed
1 2 3
import { MESSAGE_TYPE } from '../constants';
import parseMessageToJSON from './parse';

4 5 6 7 8 9 10 11
import alarmIcon from '../images/types/alarm.png';
import approveIcon from '../images/types/approve.png';
import meetingIcon from '../images/types/meeting.png';
import noticeIcon from '../images/types/notice.png';
import taskIcon from '../images/types/task.png';
import workIcon from '../images/types/work.png';
import writeIcon from '../images/types/write.png';
import otherIcon from '../images/types/other.png';
杨思琦's avatar
杨思琦 committed
12
import recoverIcon from '../images/types/recover.png';
崔佳豪's avatar
崔佳豪 committed
13

14
export const getMessageTypeIcon = message => {
杨思琦's avatar
杨思琦 committed
15 16
  const { messageType, infoType, infoContent = {} } = message;
  const { alarmState = 0 } = infoContent;
17 18 19
  let icon = otherIcon;
  if (infoType === '通用报警') {
    icon = alarmIcon;
杨思琦's avatar
杨思琦 committed
20 21 22 23
    if (alarmState === 1) {
      icon = recoverIcon;
      return icon;
    }
24 25 26 27 28
  } else if (infoType === '系统通知') {
    icon = noticeIcon;
  } else if (infoType === '工单提醒') {
    icon = workIcon;
  }
杨思琦's avatar
杨思琦 committed
29 30
  const { webIcon } = message;
  if (webIcon) return `${window.location.origin}/${webIcon}`;
崔佳豪's avatar
崔佳豪 committed
31 32
  if (!messageType) return icon;
  if (messageType === '工时填报') {
33
    icon = writeIcon;
崔佳豪's avatar
崔佳豪 committed
34
  } else if (messageType.indexOf('审批') > -1) {
35
    icon = approveIcon;
崔佳豪's avatar
崔佳豪 committed
36
  } else if (messageType.indexOf('会议') > -1) {
37
    icon = meetingIcon;
崔佳豪's avatar
崔佳豪 committed
38
  } else if (messageType.indexOf('任务') > -1) {
39
    icon = taskIcon;
崔佳豪's avatar
崔佳豪 committed
40 41 42 43 44
  }
  return icon;
};

export const getMessageClasses = messageType => {
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  let infoType = '';
  switch (messageType) {
    // 报警类
    case 'SCADA报警':
    case '通用报警':
      infoType = MESSAGE_TYPE.ALARM_TYPE;
      break;
    // 工单类
    case '工单流程':
    case '工单提醒':
      infoType = MESSAGE_TYPE.CASE_TYPE;
      break;
    // 系统消息类
    case '系统通知':
    case '系统消息':
      infoType = MESSAGE_TYPE.SYS_TYPE;
      break;
    // 其他类
    default:
      infoType = MESSAGE_TYPE.UNKNOWN;
      break;
  }
  return infoType;
崔佳豪's avatar
崔佳豪 committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
};

/**
 * 消息语音单位转换
 * 说明:消息通过语音播放时,需要将一些字母单位转换成文字,不然会当做字母播放。
 * @param {*} msg
 * @returns
 */
export const replaceSpeak = msg => {
  msg = msg.replaceAll(' ', '');
  msg = msg.replace(/MPa/gi, '兆帕');
  msg = msg.replace(/m³\/h/gi, '立方米每小时');
  msg = msg.replace(/m³/gi, '立方米');
  msg = msg.replace(/kWh/gi, '千瓦时');
  msg = msg.replace(/kW/gi, '千瓦');
  msg = msg.replace(/min/gi, '分钟');
  msg = msg.replace(/m/gi, '米');
  msg = msg.replace(/A/gi, '安');
  msg = msg.replace(/V/gi, '伏');
杨思琦's avatar
杨思琦 committed
87
  msg = msg.replace(/Hz/gi, '赫兹');
崔佳豪's avatar
崔佳豪 committed
88 89 90 91
  msg = msg.replace(/h/gi, '小时');
  return msg;
};

92
// eslint-disable-next-line arrow-body-style
崔佳豪's avatar
崔佳豪 committed
93 94 95
export const generatedId = () => {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
    .replace(/[xy]/g, function(c) {
96
      // eslint-disable-next-line no-bitwise
崔佳豪's avatar
崔佳豪 committed
97
      const r = (Math.random() * 16) | 0;
98
      // eslint-disable-next-line no-bitwise
崔佳豪's avatar
崔佳豪 committed
99 100 101 102 103 104
      const v = c === 'x' ? r : (r & 0x3) | 0x8;
      return v.toString(16);
    })
    .toUpperCase();
};

105
export { parseMessageToJSON };