deviceIcon.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * 设备字段图标
  3. * static/icon-new 下的图标已按接口 showColum 的 monitorcode 命名,
  4. * 这里统一按 monitorcode 取图,取不到再按描述/关键字兜底。
  5. */
  6. // 已按 monitorcode 命名的图标(忽略大小写匹配)
  7. const ICON_FILE_LIST = [
  8. "airLeakageRatePerHundred_merge",
  9. "airSupplyDistence_merge",
  10. "atomizeState",
  11. "atomizeState_str",
  12. "batteryLevel",
  13. "centerTemperature",
  14. "ch2val",
  15. "ch4",
  16. "chval",
  17. "co2_merge",
  18. "co2val",
  19. "controlState",
  20. "controlState_str",
  21. "coval",
  22. "createtime",
  23. "cumulativeFlow",
  24. "density",
  25. "ductOutletAirVolume_merge",
  26. "dustval",
  27. "Fan_MOT1_Power",
  28. "Fan_MOT2_Power",
  29. "Fan1StartStatus_str",
  30. "Fan2StartStatus_str",
  31. "FanStartStatus",
  32. "FanStartStatus_str",
  33. "favg",
  34. "fengsu_merge",
  35. "fireval",
  36. "fireval_str",
  37. "flow_merge",
  38. "flowRate",
  39. "fmax",
  40. "fmin",
  41. "frontRearDifference",
  42. "frontRearDP",
  43. "fsectarea",
  44. "fy_merge",
  45. "gasC",
  46. "gasMixMass",
  47. "gasval",
  48. "gcreatetime",
  49. "groutingPump",
  50. "groutingPump_str",
  51. "humidity",
  52. "inletAirVolume_merge",
  53. "instantaneousFlow",
  54. "kpa",
  55. "monitorValue",
  56. "nitrogenContent",
  57. "nitrogenPressure",
  58. "o2val",
  59. "onState",
  60. "onState_str",
  61. "outletTemperature",
  62. "pa",
  63. "pressure",
  64. "pulpingMachine",
  65. "pulpingMachine_str",
  66. "ratio",
  67. "readTime",
  68. "smokeval",
  69. "smokeval_str",
  70. "sprayval",
  71. "strname",
  72. "T",
  73. "temperature",
  74. "timedState",
  75. "timeval",
  76. "ttime",
  77. "type_merge",
  78. "typeName",
  79. "unitval",
  80. "V",
  81. "valvestate_str",
  82. "waterPump",
  83. "waterPump_str",
  84. "waterSupply",
  85. "windSpeed",
  86. "ws_merge",
  87. ];
  88. const ICON_CODE_MAP = {};
  89. ICON_FILE_LIST.forEach((name) => {
  90. ICON_CODE_MAP[name.toLowerCase()] = name;
  91. });
  92. // 匹配不到时的默认图标
  93. const DEFAULT_ICON = "/static/icon-new/type_merge.svg";
  94. /**
  95. * 按字段取图标
  96. * @param {String} monitorcode 接口字段编码
  97. * @param {String} des 字段中文描述
  98. * @param {Number} fanNo 风机编号(1-主机 2-备机),非风机页面可不传
  99. * @returns {String} 图标路径
  100. */
  101. export function getDeviceIcon(monitorcode, des, fanNo) {
  102. let code = (monitorcode || "").toLowerCase();
  103. const desText = des || "";
  104. // 风机型号(code = type_merge)固定使用 type_merge.svg
  105. if (code == "type_merge" || desText.indexOf("风机型号") > -1) {
  106. return "/static/icon-new/type_merge.svg";
  107. }
  108. // 甲烷类字段(ch4_merge 等,含 ch4 即可)使用 ch4.svg
  109. if (code.indexOf("ch4") > -1) {
  110. return "/static/icon-new/ch4.svg";
  111. }
  112. // 时间类字段(readTime、时间 等)使用 T.svg,排除“是否定时”等 timed 字段
  113. if (
  114. (code.indexOf("time") > -1 && code.indexOf("timed") == -1) ||
  115. desText.indexOf("时间") > -1
  116. ) {
  117. return "/static/icon-new/T.svg";
  118. }
  119. if (desText.indexOf("温度") > -1) {
  120. return "/static/icon-new/centerTemperature.svg";
  121. }
  122. // 风机主机/备机:monitorcode 形如 fan1xxx / fan_mot1_xxx,按编号取对应图标
  123. if (fanNo) {
  124. code = code.replace(/^(fan)_?mot[12]/, "$1_mot" + fanNo);
  125. code = code.replace(/^(fan)[12]/, "$1" + fanNo);
  126. }
  127. // 优先按 monitorcode 直接取同名图标
  128. if (code && ICON_CODE_MAP[code]) {
  129. return "/static/icon-new/" + ICON_CODE_MAP[code] + ".svg";
  130. }
  131. if (code.indexOf("frontarea") > -1) {
  132. return "/static/home/gfmj.svg";
  133. }
  134. if (code.indexOf("area") > -1) {
  135. return "/static/icon-new/dmj.svg";
  136. }
  137. if (
  138. code.indexOf("m3") > -1 ||
  139. code.indexOf("va") > -1 ||
  140. code.indexOf("forward") > -1
  141. ) {
  142. return "/static/icon-new/fl.svg";
  143. }
  144. if (code.indexOf("gate") > -1 || code.indexOf("door") > -1) {
  145. return "/static/icon-new/door-icon.svg";
  146. }
  147. if (
  148. code.indexOf("press") > -1 ||
  149. code.indexOf("pressure") > -1 ||
  150. code.indexOf("pa1") > -1 ||
  151. code.indexOf("pa2") > -1 ||
  152. code.indexOf("dp") > -1
  153. ) {
  154. return "/static/icon-new/qyyl-icon.svg";
  155. }
  156. return DEFAULT_ICON;
  157. }
  158. export default getDeviceIcon;