import {formatterSecondOrMillisecond} from "@/utils/date"; import CellsysChart from "./cellsysChart"; class CellsysEquipmentMonitor { constructor(param) { let params = param || {}; this.id = param.id; this.sysTypeId = params["equipment_type_id"]; this.sysTypeName = params["equipment_type_name"]; this.monitorIdList = params["equipment_monitor_ids"]; this.dataType = params["data_type"]; this.dataName = params["data_name"]; this.topicName = params["mq_topic"]; this.remark = params["remark"]; this.createTime = params["create_time"]; this.updateTime = params["update_time"]; this.monitorList = params["equipment_monitor_objects"].map(item => { item.charts = item.charts.map(chart => { chart.monitorKey = item.key; chart.monitorName = item.name; return new CellsysChart(chart) }) return item; }); } /** * 获取监控量集合(有序) * @returns {*[]} */ getMonitorList() { let keys = []; if (this.monitorIdList && this.monitorList) { keys = this.monitorIdList.map(id => { return this.monitorList.find(o => o.id === id); }); } return keys; } /** * 格式化监控量数据 * @param data 监控量数据 */ formatterMonitorData(data, macId) { let keys = this.getMonitorList(); if (data && Object.keys(data).length > 0) { return keys.map(o => { let value = data[o.key]; if (Object.hasOwnProperty.call(o, "format_type")) { //的判断是否有数据类型字段 switch (o["format_type"]) { case "datetime": value = formatterSecondOrMillisecond(value); break; case "time": value = formatterSecondOrMillisecond(value); break; } } if (o["key"] === "coordinatesType") { //这里本来应该是读取字典表里的定位类型配置,暂时先以页面写死的形式实现,后续跟移动端和接口放讨论具体实现方案 value = formatterCoordinatesType(value) } if (o["key"] === "macid") { value = macId; } return Object.assign({}, o, {value: value}); }); } else { return keys.map(o => { return Object.assign({}, o, {value: '--'}); }) } } } function formatterCoordinatesType(value) { switch (value) { case 1: return "北斗定位"; case 2: return "GPS定位"; case 3: return "GPS、北斗双模定位"; case 4: return "固话北斗定位"; default: return "未知类型" } } export default CellsysEquipmentMonitor