import * as echarts from '../../components/ec-canvas/echarts'; import constant from '../../utils/constant.js'; var Constant = require('../../utils/constant.js'); var util = require('../../utils/util.js'); import Request from "../../utils/api" var app = getApp(); var g_pointParas = {}; var g_refreshTime = 120; var g_realTimeChartRecords = []; var barec1 = null; var barec2 = null; Page({ data: { seriesDataOne:[], ec1: { onInit: function (canvas, width, height, dpr) { barec1 = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr }); canvas.setChart(barec1); return barec1; } }, ec2: { onInit: function (canvas, width, height, dpr) { barec2 = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr }); canvas.setChart(barec2); return barec2; } }, Fixed: { ec1: { refresh: "onTapRefresh", interval: "onTapInterval" }, ec2: { refresh: "onTapRefreshHistory", interval: "onTapIntervalHistory" }, }, tabBar: [{ index: 0, iconPath: "icon-shebeijiance-dianji", selectedIconPath: "icon-shebeijiance-dianji blue", text: "监控" }, { index: 1, iconPath: "icon-lishi2", selectedIconPath: "icon-lishi2 blue", text: "历史" }, { index: 2, iconPath: "icon-guzhang2", selectedIconPath: "icon-guzhang2 blue", text: "警报" } ], loadingInfo: "加载中,请稍等...", loadingHidden: false, realChartWidth: 100, realChartHeight: 100, historyChartWidth: 100, historyChartHeight: 200, today: util.formatDay(new Date()), yestday: util.formatDay(util.GetNextDate(new Date(), -1)), historyDate: util.formatDay(util.GetNextDate(new Date(), -1)), isNextDayAble: false, //是否可以点击下一天 pointID: 0, pointName: "", pointUnit: "", pointParas: null, historyChart: null, realTimeChart: null, formatType:null, isInitialHistoryData: false, //是否初始化过历史记录 isInitialAlarmData: false, //是否初始化警报记录 lastRefreshTime: g_refreshTime, //秒 currentTabIndex: 0, hasAlarmData: false, isChecked: false, //switch选中状态 ---是否显示报警点 alarmListInfo:[], currentRecordParas: {}, scrollOneId: '', //实时监控数据列表对应的列表子项id scrollTwoId: '', //历史监控数据列表对应的列表子项id startAlarmDate: util.formatDay(util.GetBeforeDate(7)), endAlarmDate: util.formatDay(new Date()), PageIndex: 1, //初始化页数 PageSize: 20, //初始化条数 message: '未发生报警', bottomStatus: false, isShowFloatMenu: false, //是否显示 animationFloatMenu: '', //显示动画 scrollHeight: wx.getSystemInfoSync().windowHeight, scrollTop: 0, historyScrollTop: 0, ishidden: false, monitorList: [], //监测页面列表 historyStatus: false, real_time_records: [], //存放实时的监控点 monitorAlam: [], //存放监测界面 -- 所有报警点的监控值 history_records: [], //存放历史的监控点 historyAlam: [], //存放历史界面 -- 所有报警点的监控值 isMonitorChange: false, //监测界面 --- 是否启用状态筛选 isHistoryChange: false, //历史界面 --- 是否启用状态筛选 real_chart_data:[],//初始化图表的数据源 real_monitor_data:[],//初始化列表的数据源 history_chart_data:[],//初始化历史图表的数据源 history_monitor_data:[],//初始化历史列表的数据源 isloadHistoryChart: false, //是否加载了历史图表 isloadCurrentDayChart: false, //是否加载了当天的图标 getParamInfo:{ Items:[], FormatType:"" } , stationName:'' //测点组的名字 (如1#机组) }, /**生命周期函数--监听页面加载*/ onLoad: function (options) { var pointid = options.id; // console.log('打印point', options); wx.setNavigationBarTitle({ //自定义顶部页面标题 title: options.name }) if (pointid == null) { return; } if (options.unit == "null" || options.unit == null) { options.unit = "" } var chartWidth = app.getWindowWidth(); //console.log(app.getWindowWidth()) this.setData({ pointID: pointid, pointName: options.name, pointUnit: options.unit, realChartWidth: app.globalData.screenSize.width, realChartHeight: app.globalData.screenSize.height * 1.5 - 120, historyChartWidth: app.globalData.screenSize.width, historyChartHeight: app.globalData.screenSize.height * 2.5 - 50, stationName:options.stationName }); }, //初始化获取参数 initParamsReal:function(){ var that = this; that.setData({ loadingHidden: false, loadingInfo: "数据请求中,请稍等..." }); Request({ url: Constant.BASE_SERVER_URL + "Monitor/Signal/Std/GetDisplayParasByID@V1.0", method: 'GET', data: { ID : that.data.pointID, }, header: { 'content-type': 'application/json' }, fail: function (err) { //请求失败 util.popup.showModal('', '通讯失败'); return; }, complete: function () { //请求完成后执行的函数 that.setData({ loadingHidden: true }); }, success: function (res) { // console.log(res,181) let result=res.data if (result.Code != 0) { wx.showModal({ title: '', content: result.Message, }); return; } that.data.getParamInfo.FormatType=result.Data.FormatType that.data.getParamInfo.Items=result.Data.DisplayParas.Items setTimeout(function () { that.initialRealTimeRecord() }, 500) } }) }, //初始化数据(实时数据) initialRealTimeRecord: function () { var that = this; that.setData({ loadingHidden: false, loadingInfo: "数据请求中,请稍等..." }); var formatType=that.data.getParamInfo.FormatType Request({ url: Constant.BASE_SERVER_URL + "Monitor/Record/Real/Std/GetBySignalIDOfDay@V2.0", method: 'GET', data: { SignalID : that.data.pointID, // Day: "2024-01-15" Day: util.formatDay(new Date()) }, header: { 'content-type': 'application/json' }, fail: function (err) { //请求失败 util.popup.showModal('', '通讯失败'); return; }, complete: function () { //请求完成后执行的函数 that.setData({ loadingHidden: true }); }, success: function (res) { var result = res.data; // console.log('195行', result); if (result.Code != 0) { wx.showModal({ title: '', content: result.Message, }); return; } var real_time_records = result.Data; if (real_time_records == null || real_time_records.length == 0) { util.popup.showModal('', '未开启监控'); return; } let chartData = [] if(formatType==1){ let errorEnumData = ["SZGSCW", "ZHSB", "GLSB", "BJ"] real_time_records.forEach(element => { let isErrorData = false for (var i = 0; i < element.DataStatus.length; i++) { if (errorEnumData.indexOf(element.DataStatus[i]) != -1) { isErrorData = true } } if (!isErrorData) { if (element.DataStatus != -1) { chartData.push(element); } } }) that.setData({ real_chart_data:chartData, real_monitor_data:result.Data }) that.initChart(chartData) return } if(formatType!=1){ real_time_records.forEach(element => { chartData.push(element) }) that.setData({ real_chart_data:chartData }) // that.data.real_chart_data=chartData that.initFormatChart(chartData) return } } }); }, //构建折线图图表 initChart: function (real_time_records) { var that=this var real_monitor_data=that.data.real_monitor_data var last_record = real_time_records[real_time_records.length - 1]; last_record.DataValue = parseFloat(last_record.DataValue).toFixed(2) //获取监控当天的监控指及状态 var monitorList = [] for (var i = 0; i < real_monitor_data.length; i++) { real_monitor_data[i].DataStatusText = DataStatusTextEmun(real_monitor_data[i].DataStatus[0]) var monitor = { id: real_monitor_data[i].SignalID, RecordValue: parseFloat(parseFloat(Number(real_monitor_data[i].DataValue).toFixed(2))), RecordStatus: real_monitor_data[i].DataStatus, RecordStatusText: real_monitor_data[i].DataStatusText, RecordTime: util.functions.sub(real_monitor_data[i].DataTime, 11, 16), } monitorList.push(monitor) } // console.log(monitorList,"monitorList") var alarm_number = 0; for (var i = 0; i < real_time_records.length; i++) { // 循环获取报警次数 var record = real_time_records[i]; if (record.DataStatus[0] == "BJ") { alarm_number++; } } that.setData({ loadingHidden: true, real_time_records: real_time_records, monitorList: monitorList&&monitorList.reverse(), currentRecordParas: { HistoryRecordValue: '', RecordValue: last_record.DataValue, RecordTime: util.functions.sub(last_record.DataTime, 0, 10), RecordStatus: last_record.DataStatus, RecordStatusName: alarm_number > 0 ? "报警" : "正常", AlarmNumber: alarm_number } }); // console.log(monitorList,271) //判断是否有报警点,如果有则显示在图表上 var realAlarmPoint = [] for (let r = 0; r < real_time_records.length; r++) { if (real_time_records[r].DataStatus[0] == "BJ") { real_time_records[r].DataTime = real_time_records[r].DataTime.replace(/-/gi, '/') var real_alarm_point = { value: '', coord: [real_time_records[r].DataTime, real_time_records[r].DataValue], itemStyle: { color: '#ff0000' } } realAlarmPoint.push(real_alarm_point) } } g_realTimeChartRecords = TransChartRecordPoint(real_time_records); if (barec1 == null) { util.popup.showModal('图表提示', '图表加载错误,请点击刷新重试') return; } barec1.setOption({ color: ["#37A2DA"], legend: { top: 0, left: 'center', z: 100 }, grid: { containLabel: true, top: 30, left: 15, right: 20, }, tooltip: { show: true, trigger: 'axis', formatter: function (params) { // console.log('479', params); let pointTime = 'T' + params[0].axisValueLabel.slice(0, 5) that.setData({ scrollOneId: pointTime, nowDayMonitorTime: params[0].axisValueLabel.slice(0, 5) }) // console.log(pointTime) // that.filterMonitorList(pointTime) return '时间:' + util.functions.sub(params[0].value[0], 11, 16) + '\n' + "实时值:" + params[0].value[1]; }, }, xAxis: { type: 'time', min: function (value) { //设置X轴的最小刻度 let minTime = new Date().setHours(0, 0, 0, 0) return minTime; }, max: function (value) { //设置X轴的最大刻度 let maxTime = new Date().setHours(23, 59, 59, 0) return maxTime; }, boundaryGap: false, axisLabel: { formatter: function (v, index) { var date = new Date(v); return util.formatTimeUtil("hh:mm", date); } }, }, yAxis: { x: 'center', type: 'value', splitLine: { lineStyle: { type: 'dashed' } }, scale: true, axisLabel: { formatter: function (val) { //console.log(val) var value = val if (val >= 1000 && val < 1000000) { value = parseFloat(formatNumber(val / 1000).toFixed(2)) + "K" } else if (val >= 1000000) { value = parseFloat(formatNumber(val / 1000000).toFixed(2)) + "M" } return value; }, } // show: false }, dataZoom: [{ type: 'slider', //图表下方的伸缩条 show: true, //是否显示 realtime: true, // start: 0, //伸缩条开始位置(1-100),可以随时更改 end: 100, //伸缩条结束位置(1-100),可以随时更改 left: 10, right: 15, fillerColor: "rgba(22,181,203,0.4)", //选中范围的填充颜色。 borderColor: "#ddd", //边框颜色。 backgroundColor: "rgba(167,183,204,0.4)", //组件的背景颜色 throttle: 100, //设置触发视图刷新的频率。单位为毫秒(ms)。 handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', handleSize: '80%', // 控制手柄的尺寸,可以是像素大小,也可以是相对于 dataZoom 组件宽度的百分比,默认跟 dataZoom 宽度相同。 handleStyle: { color: '#16b5cb', shadowBlur: 3, // shadowBlur图片阴影模糊值,shadowColor阴影的颜色 shadowColor: '#77CCD8', shadowOffsetX: 1, shadowOffsetY: 1, opacity: 0.6, } }], series: [{ type: 'line', showSymbol: false, data: g_realTimeChartRecords, markPoint: { symbol: 'pin', symbolSize: 10, data: realAlarmPoint } }] }) // barec1.setOption({series:{markPoint:{data:}}}) //获取报警记录 var drawRefreshTimeText = that.data.lastRefreshTime + "s后刷新"; util.popup.showToast(drawRefreshTimeText, 'none', '', 2000) //定时器 var intervalRefreshTime = setInterval(function () { var lastRefreshTime = that.data.lastRefreshTime; lastRefreshTime = lastRefreshTime - 1; if (lastRefreshTime <= 0) { var drawRefreshTimeText = "刷新中"; util.popup.showToast(drawRefreshTimeText, 'none', '', 2000) lastRefreshTime = g_refreshTime; //更新数据 // console.log('马上刷新') that.refreshRealTimeValue(); } that.setData({ lastRefreshTime: lastRefreshTime }); }, 1000); that.setData({ intervalRefreshTime: intervalRefreshTime }); //获取报警记录 that.getAlarmRecord() return; }, //构建文本图表 initFormatChart: function (real_time_records) { // console.log(records,"已获取导数据") var that=this var seriesData=[] // console.log(real_time_records,433) var formatData = getFormatData4Enum(real_time_records); //数据转换 const getParamsList = that.data.getParamInfo.Items; formatData.forEach((item) => { getParamsList.forEach(paramsItem=>{ if (paramsItem.EnumName == item.Status) { seriesData.push({ name: that.data.pointName, value: [ 0, +new Date(item.StartTime) - 0, +new Date(item.EndTime) - 0, item.Status, item.Duration, ], itemStyle: { color: paramsItem.DisplayColor, }, }); } }); }) // console.log(seriesData,505) var last_record = real_time_records[real_time_records.length - 1]; //获取监控当天的监控指及状态 var monitorList = [] for (var i = 0; i < real_time_records.length; i++) { real_time_records[i].DataStatusText = DataStatusTextEmun(real_time_records[i].DataStatus[0]) var monitor = { id: real_time_records[i].SignalID, RecordValue: real_time_records[i].DataValue, RecordStatus: real_time_records[i].DataStatus, RecordStatusText: real_time_records[i].DataStatusText, RecordTime: util.functions.sub(real_time_records[i].DataTime, 11, 16), } monitorList.push(monitor) } that.setData({ // loadingHidden: true, monitorList: monitorList&&monitorList.reverse(), currentRecordParas: { HistoryRecordValue: '', RecordValue: last_record.DataValue, RecordTime: util.functions.sub(last_record.DataTime, 0, 10), RecordStatus: last_record.DataStatus, RecordStatusName: "正常", AlarmNumber: 0 } }); barec1.setOption({ disableTouch: true, tooltip: { show: true, formatter: function (params) { // console.log(params,492) return ( params.name + ': ' + params.value[4] + '小时' + '\n' + '开始时间: ' + new Date(params.value[1]).getHours() + ':' + new Date(params.value[1]).getMinutes() + '\n' + '结束时间: ' + new Date(params.value[2]).getHours() + ':' + new Date(params.value[2]).getMinutes() ); }, }, title: { text: that.data.stationName, x: 'center', y: '7px', textStyle: { color: '#16b5cb', fontSize: 16 }, textAlign: 'left' }, grid: { left: '17%', bottom: '60', top: '40', right: '4%' }, xAxis: { type: 'time', boundaryGap: false, axisLabel: { formatter: function (v, index) { var date = new Date(v); return util.formatTimeUtil("hh:mm", date); } }, }, yAxis: { splitLine: { show: false }, axisLabel: { interval: 0, rotate: 20 }, inverse: true, data: [that.data.pointName] }, dataZoom: [{ type: 'slider', //图表下方的伸缩条 show: true, //是否显示 realtime: true, // start: 0, //伸缩条开始位置(1-100),可以随时更改 end: 100, //伸缩条结束位置(1-100),可以随时更改 left: 10, right: 15, fillerColor: "rgba(22,181,203,0.4)", //选中范围的填充颜色。 borderColor: "#ddd", //边框颜色。 backgroundColor: "rgba(167,183,204,0.4)", //组件的背景颜色 throttle: 100, //设置触发视图刷新的频率。单位为毫秒(ms)。 handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', handleSize: '80%', // 控制手柄的尺寸,可以是像素大小,也可以是相对于 dataZoom 组件宽度的百分比,默认跟 dataZoom 宽度相同。 handleStyle: { color: '#16b5cb', shadowBlur: 3, // shadowBlur图片阴影模糊值,shadowColor阴影的颜色 shadowColor: '#77CCD8', shadowOffsetX: 1, shadowOffsetY: 1, opacity: 0.6, } }], series: [{ type: 'custom', renderItem: renderItemFunc, itemStyle: { opacity: 1 }, encode: { x: [1, 2], y: 0 }, data: seriesData }] }) var drawRefreshTimeText = that.data.lastRefreshTime + "s后刷新"; util.popup.showToast(drawRefreshTimeText, 'none', '', 2000) return; }, //获取当天的报警记录 getAlarmRecord() { let that = this let real_time_records = this.data.real_time_records Request({ url: Constant.BASE_SERVER_URL + "Monitor/Value/Alarm/Record/Std/GetBySignalIDOfDay@V1.0", method: 'GET', data: { SignalID : that.data.pointID, Day: util.formatDay(new Date()) }, header: { 'content-type': 'application/json' }, success: (res) => { //当天图表加载完成 that.setData({ isloadCurrentDayChart: true }) // console.log("报警记录",res) if (res.data.Data == null) { res.data.Data = [] } else { var monitorList = [] let result = res.data.Data for (let j = 0; j < result.length; j++) { let resultRecord = result[j] resultRecord.DataTime = resultRecord.DataTime.replace(/-/gi, '/') let resultRecordDataTime = new Date(resultRecord.DataTime).getTime() for (var i = 0; i < real_time_records.length; i++) { let realRecord = real_time_records[i] realRecord.DataTime = realRecord.DataTime.replace(/-/gi, '/') let realRecordDataTime = new Date(realRecord.DataTime).getTime() if (realRecordDataTime == resultRecordDataTime) { // realRecord.DataStatus.push('BJ') //BJ:报警 realRecord.DataStatus[0] = "BJ" realRecord.DataStatusText = DataStatusTextEmun(realRecord.DataStatus[0]) break; } } } // console.log(real_time_records,475) for (let index = 0; index < real_time_records.length; index++) { let element = real_time_records[index]; let monitorNode = { id: element.SignalID, RecordStatus: element.DataStatus, RecordStatusText: DataStatusTextEmun(element.DataStatus[0]), RecordTime: util.functions.sub(element.DataTime, 11, 16), RecordValue: parseFloat(element.DataValue).toFixed(2), } monitorList.push(monitorNode) } // console.log(monitorList,469) var alarm_number = 0; for (var i = 0; i < real_time_records.length; i++) { // 循环获取报警次数 var record = real_time_records[i]; if (record.DataStatus[0] == 'BJ') { alarm_number++; } } // console.log(monitorList.reverse(),497) that.setData({ real_time_records: real_time_records, monitorList: monitorList.reverse(), "currentRecordParas.RecordStatusName": alarm_number > 0 ? "报警" : "正常", "currentRecordParas.AlarmNumber": alarm_number }); //判断是否有报警点,如果有则显示在图表上 var realAlarmPoint = [] for (let r = 0; r < real_time_records.length; r++) { if (real_time_records[r].DataStatus[0] == "BJ") { real_time_records[r].DataTime = real_time_records[r].DataTime.replace(/-/gi, '/') var real_alarm_point = { value: '', coord: [real_time_records[r].DataTime, real_time_records[r].DataValue], itemStyle: { color: '#ff0000' } } realAlarmPoint.push(real_alarm_point) } } barec1.setOption({ series: { markPoint: { data: realAlarmPoint } } }) } }, fail: (err) => { } }) }, //刷新获取最近一条报警记录 refreshRealAlarmRecord() { var that = this; var real_time_records = that.data.real_time_records var real_data_time=real_time_records[real_time_records.length-1].DataTime console.log(real_time_records,real_data_time,517) that.setData({ loadingHidden: false, loadingInfo: "刷新中,请稍等..." }); //console.log(that.data.pointID) Request({ url: Constant.BASE_SERVER_URL + "Monitor/Value/Alarm/Record/Std/GetBySignalIDOfTime@V1.0", method: 'GET', data: { Time: real_data_time, SignalID : that.data.pointID, }, header: { 'content-type': 'application/json' }, fail: function (err) { that.setData({ loadingHidden: true }); util.popup.showModal('', '通讯失败'); }, //请求失败 complete: function () { that.setData({ loadingHidden: true }); }, //请求完成后执行的函数 success: function (res) { var result = res.data; // console.log(result, '540行') if (result.Code != 0) { return; } var newAlarmRecords = result.Data; console.log(newAlarmRecords, '356行') if (newAlarmRecords == null || newAlarmRecords.length == 0) return; var last_alarm_record = newAlarmRecords[0]; last_alarm_record.DataTime = last_alarm_record.DataTime.replace(/-/gi, '/') let last_recordTime = new Date(last_alarm_record.DataTime).getTime() var isAlarm = false; // 新数据与现有的数据的最后一条比对 for (let i = 0, length = real_time_records.length; i < length; i++) { let current_record = real_time_records[i] current_record.DataTime = current_record.DataTime.replace(/-/gi, '/') let curren_last_recordTime = new Date(current_record.DataTime).getTime() if (last_recordTime == curren_last_recordTime) { current_record.DataStatus[0] = "BJ" //添加最近一条报警数据 current_record.DataStatusText = DataStatusTextEmun(current_record.DataStatus[0]) current_record.DataValue = last_alarm_record.DataValue if (current_record.DataStatus == "BJ") { isAlarm = true; } break } } // console.log(last_recordTime,curren_last_recordTime) //获取监控当天的监控指及状态 var monitorList = [] for (var i = 0; i < real_time_records.length; i++) { // console.log(real_time_records[i],529) let realRecord = real_time_records[i] var monitor = { id: i, RecordValue: parseFloat(realRecord.DataValue).toFixed(2), RecordStatus: real_time_records[i].DataStatus, RecordStatusText: DataStatusTextEmun(real_time_records[i].DataStatus[0]), RecordTime: util.functions.sub(realRecord.DataTime, 11, 16), } monitorList.push(monitor) } //console.log(last_record, '366'); that.setData({ loadingHidden: true, real_time_records: real_time_records, monitorList: monitorList.reverse(), // "currentRecordParas.RecordTime": util.functions.sub(last_alarm_record.DataTime, 0, 10), "currentRecordParas.RecordStatusName": isAlarm ? "报警" : "正常", "currentRecordParas.AlarmNumber": isAlarm ? that.data.currentRecordParas.AlarmNumber + 1 : that.data.currentRecordParas.AlarmNumber }); //判断是否有报警点,如果有则显示在图表上 var realRefreshAlarmPoint = [] for (let r = 0; r < that.data.real_time_records.length; r++) { that.data.real_time_records[r].DataTime = that.data.real_time_records[r].DataTime.replace(/-/gi, '/') if (that.data.real_time_records[r].DataStatus[0] == "BJ") { var real_refresh_alarm_point = { value: '', coord: [that.data.real_time_records[r].DataTime, that.data.real_time_records[r].DataValue], itemStyle: { color: '#ff0000' } } realRefreshAlarmPoint.push(real_refresh_alarm_point) } } if (barec1 == null) { util.popup.showModal('图表提示', '图表加载错误,请点击刷新重试') return; } barec1.setOption({ series: { markPoint: { data: realRefreshAlarmPoint } } }) return; } }) }, goTop() { this.setData({ historyScrollTop: 0 }) }, scrollListView(e) { let scrollTop = e.detail.scrollTop // console.log(e) // 如果超过半屏 if (scrollTop > this.data.scrollHeight / 2) { this.setData({ isShowFloatMenu: true, animationFloatMenu: 'fadeIn' }) } else { this.setData({ isShowFloatMenu: false, animationFloatMenu: 'fadeOut' }) // setTimeout(() => {this.setData({visual: false})}, 1000) } }, //监控刷新 onTapRefresh() { //clearInterval(this.data.intervalRefreshTime); this.setData({ scrollOneId: '', nowDayMonitorTime: '', scrollTop: 0 }) this.refreshRealTimeValue(); }, //刷新实时值 refreshRealTimeValue: function () { var that = this; var real_time_records = that.data.real_time_records that.setData({ loadingHidden: false, loadingInfo: "刷新中,请稍等..." }); //console.log(that.data.pointID) Request({ url: Constant.BASE_SERVER_URL + "Monitor/Record/Real/Std/GetLastRecord@V2.0", method: 'GET', data: { SignalID : that.data.pointID, }, header: { 'content-type': 'application/json' }, fail: function (err) { that.setData({ loadingHidden: true }); util.popup.showModal('', '通讯失败'); }, //请求失败 complete: function () { that.setData({ loadingHidden: true }); }, //请求完成后执行的函数 success: function (res) { var result = res.data; // console.log(result, '355行') if (result.Code != 0) { return; } var formatType=that.data.getParamInfo.FormatType var newRecords = result.Data; //console.log(newRecords, '356行') if (newRecords == null) return; var last_record = newRecords; // console.log(last_record, 1017) if(formatType==1){ last_record.DataValue = parseFloat(last_record.DataValue).toFixed(2) last_record.DataTime = last_record.DataTime.replace(/-/gi, '/') if (last_record.DataStatus.length > 0) { last_record.DataStatusText = DataStatusTextEmun(last_record.DataStatus[0]) } // 新数据与现有的数据的最后一条比对 let current_record = real_time_records[real_time_records.length - 1] current_record.DataTime = current_record.DataTime.replace(/-/gi, '/') let last_recordTime = new Date(last_record.DataTime).getTime() let curren_last_recordTime = new Date(current_record.DataTime).getTime() // console.log(last_record,716) if (last_recordTime > curren_last_recordTime && last_record.DataValue != current_record.DataValue) { real_time_records.push(last_record) //添加最后一条数据 } var isAlarm = false; if (last_record.DataStatus[0] == "BJ") { isAlarm = true; } //获取监控当天的监控指及状态 var monitorList = [] for (var i = 0; i < real_time_records.length; i++) { var monitor = { id: i, RecordValue: parseFloat(real_time_records[i].DataValue), RecordStatus: real_time_records[i].DataStatus, RecordStatusText: DataStatusTextEmun(real_time_records[i].DataStatus[0]), RecordTime: util.functions.sub(real_time_records[i].DataTime, 11, 16) } monitorList.push(monitor) } that.setData({ loadingHidden: true, real_time_records: real_time_records, monitorList: monitorList.reverse(), currentRecordParas: { HistoryRecordValue: that.data.currentRecordParas.RecordValue, RecordValue: last_record.DataValue, RecordTime: util.functions.sub(last_record.DataTime, 0, 10), RecordStatus: last_record.DataStatus, RecordStatusName: isAlarm ? "报警" : "正常", AlarmNumber: isAlarm ? that.data.currentRecordParas.AlarmNumber + 1 : that.data.currentRecordParas.AlarmNumber } }); //判断是否有报警点,如果有则显示在图表上 var realRefreshAlarmPoint = [] for (let r = 0; r < that.data.real_time_records.length; r++) { that.data.real_time_records[r].DataTime = that.data.real_time_records[r].DataTime.replace(/-/gi, '/') if (that.data.real_time_records[r].DataStatus == "BJ") { var real_refresh_alarm_point = { value: '', coord: [that.data.real_time_records[r].DataTime, that.data.real_time_records[r].DataValue], itemStyle: { color: '#ff0000' } } realRefreshAlarmPoint.push(real_refresh_alarm_point) } } // console.log(last_record,732) if (last_record.DataStatus.length > 0 && last_record.DataStatus[0] == 'BJ') { return } var m_chartRecordList = TransChartRecordPoint([last_record]); g_realTimeChartRecords.push(m_chartRecordList[0]); // console.log(g_realTimeChartRecords,418) console.log(barec1,777) if (barec1 == null) { util.popup.showModal('图表提示', '图表加载错误,请点击刷新重试') return; } barec1.setOption({ color: ["#37A2DA"], legend: { // data: [g_pointParas.RecordName + '/' + g_pointParas.UnitName], top: 0, left: 'center', z: 100 }, grid: { containLabel: true, top: 30, left: 15, right: 20, }, tooltip: { show: true, trigger: 'axis', formatter: function (params) { // console.log('479', params); // let pointTime = 'T' + params[0].axisValueLabel.slice(0, 5) // that.setData({ // scrollOneId: pointTime, // nowDayMonitorTime: params[0].axisValueLabel.slice(0, 5) // }) return '时间:' + util.functions.sub(params[0].value[0], 11, 16) + '\n' + "实时值:" + params[0].value[1]; }, }, xAxis: { type: 'time', boundaryGap: false, min: function (value) { //设置X轴的最小刻度 let minTime = new Date().setHours(0, 0, 0, 0) return minTime; }, max: function (value) { //设置X轴的最大刻度 let maxTime = new Date().setHours(23, 59, 59, 0) return maxTime; }, axisLabel: { formatter: function (v, index) { var date = new Date(v); return util.formatTimeUtil("hh:mm", date); } }, }, yAxis: { x: 'center', type: 'value', splitLine: { lineStyle: { type: 'dashed' } }, axisLabel: { formatter: (value) => { if (value >= 1000000) { value = (value / 1000000) + 'M'; } if (value >= 10000) { value = (value / 10000) + 'W'; } if (value >= 1000) { value = (value / 1000) + 'K'; } return value; } } // show: false }, dataZoom: [{ type: 'slider', //图表下方的伸缩条 show: true, //是否显示 realtime: true, // start: 0, //伸缩条开始位置(1-100),可以随时更改 end: 100, //伸缩条结束位置(1-100),可以随时更改 left: 10, right: 15, fillerColor: "rgba(22,181,203,0.4)", //选中范围的填充颜色。 borderColor: "#ddd", //边框颜色。 backgroundColor: "rgba(167,183,204,0.4)", //组件的背景颜色 throttle: 100, //设置触发视图刷新的频率。单位为毫秒(ms)。 handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', handleSize: '80%', // 控制手柄的尺寸,可以是像素大小,也可以是相对于 dataZoom 组件宽度的百分比,默认跟 dataZoom 宽度相同。 handleStyle: { color: '#16b5cb', shadowBlur: 3, // shadowBlur图片阴影模糊值,shadowColor阴影的颜色 shadowColor: '#77CCD8', shadowOffsetX: 1, shadowOffsetY: 1, opacity: 0.6, } }], series: [{ type: 'line', showSymbol: false, // smooth: true, // name: g_pointParas.RecordName + '/' + g_pointParas.UnitName, data: g_realTimeChartRecords, markPoint: { symbol: 'pin', symbolSize: 10, data: realRefreshAlarmPoint } }] }) that.refreshRealAlarmRecord() return; } if(formatType==2){ // console.log(123) that.data.real_chart_data.push(last_record) return } } }); }, //监测界面---是否展示报警点 isShowPoint: function (e) { var that = this let real_time_records = that.data.real_time_records g_realTimeChartRecords = TransChartRecordPoint(real_time_records); // console.log(e.detail.value) let status = e.detail.value if (status == true) { barec1.setOption({ series: [{ type: 'line', showSymbol: false, // smooth: true, // name: g_pointParas.RecordName + '/' + g_pointParas.UnitName, data: g_realTimeChartRecords, markPoint: { symbol: 'pin', symbolSize: 10, data: "" } }] }) } else { //判断是否有报警点,如果有则显示在图表上 let realAlarmPoint = [] for (let r = 0; r < real_time_records.length; r++) { real_time_records[r].DataTime = real_time_records[r].DataTime.replace(/-/gi, '/') if (real_time_records[r].DataStatus.length > 0) { let real_alarm_point = { value: '', coord: [real_time_records[r].DataTime, real_time_records[r].DataValue], itemStyle: { color: '#ff0000' } } realAlarmPoint.push(real_alarm_point) } } barec1.setOption({ series: [{ type: 'line', showSymbol: false, // smooth: true, // name: g_pointParas.RecordName + '/' + g_pointParas.UnitName, data: g_realTimeChartRecords, markPoint: { symbol: 'pin', symbolSize: 10, data: realAlarmPoint } }] }) } }, bindStartAlarmDateChange: function (e) { this.setData({ startAlarmDate: e.detail.value }) }, bindEndAlarmDateChange: function (e) { this.setData({ endAlarmDate: e.detail.value }) }, //底部导航栏切换 tapTab: function (e) { var selIndex = e.currentTarget.dataset.index; var that = this; this.setData({ currentTabIndex: selIndex }); if (selIndex == 0 && !that.data.isloadCurrentDayChart) { console.log(that.data.isloadCurrentDayChart, "loadCurrentChart") setTimeout(function () { that.refreshRealTimeValue() }, 1000) } if (selIndex == 1) { //当选中的下标为1的时候修改图表配置 setTimeout(function () { that.getHistoryData() }, 500) } if (selIndex == 2 && !this.data.isInitialAlarmData) { //当选中的下标为2的时候展示报警列表 this.setData({ loadingHidden: false, isInitialAlarmData: true }) that.getAlarmData(); //调用警报 } }, //选择历史日期 tapChangeHistoryDay: function (e) { var isNextDayAble = true; if (e.detail.value == this.data.yestday) { isNextDayAble = false; } this.setData({ historyDate: e.detail.value, isNextDayAble: isNextDayAble }) this.getHistoryData(); }, //历史--上一天 lastHistoryDay: function () { this.setData({ historyDate: util.formatDay(util.GetNextDate(this.data.historyDate, -1)), isNextDayAble: true, isHistoryChange: false }); this.getHistoryData(); }, //历史--下一天 nextHistoryDay: function () { var day = util.formatDay(util.GetNextDate(this.data.historyDate, 1)); var isNextDayAble = true; if (day == this.data.yestday) { isNextDayAble = false; } this.setData({ historyDate: day, isNextDayAble: isNextDayAble, isHistoryChange: false }); this.getHistoryData(); }, //历史数据 getHistoryData: function () { var that = this; that.setData({ loadingHidden: false, loadingInfo: "数据请求中,请稍等..." }); var formatType=that.data.getParamInfo.FormatType Request({ url: Constant.BASE_SERVER_URL + "Monitor/Record/Real/Std/GetBySignalIDOfDay@V2.0", method: 'GET', data: { SignalID : that.data.pointID, Day: that.data.historyDate }, header: { 'content-type': 'application/json' }, fail: function (err) { //util.popup.showModal('', '通讯失败'); }, //请求失败 complete: function () { that.setData({ loadingHidden: true }); }, //请求完成后执行的函数 success: function (res) { var result = res.data; // console.log("历史数据",result) if (result.Code != 0) { wx.showModal({ title: '', content: result.Message, }); return; } var history_records = result.Data; if (history_records == null || history_records.length == 0) { wx.showModal({ title: '', content: "当前日期,没有获取到监控值", }); barec2.setOption({ series: { data: [] } }) that.setData({ history_chart_data: [] }) return; } const chartData=[] // console.log(formatType,1367) if(formatType==1){ let errorEnumData = ["SZGSCW", "ZHSB", "GLSB", "BJ"] history_records.forEach(element => { let isErrorData = false for (var i = 0; i < element.DataStatus.length; i++) { if (errorEnumData.indexOf(element.DataStatus[i]) != -1) { isErrorData = true } } if (!isErrorData) { if (element.DataStatus != -1) { chartData.push(element); } } }); that.setData({ history_chart_data:chartData, history_monitor_data:result.Data }) that.initHistoryChart() return } if(formatType==2){ that.setData({ history_chart_data:history_records }) that.initHistoryFormatChart() return } } }); }, //初始化历史查询折线图 formatType=1 initHistoryChart:function(){ var that=this var history_records =that.data.history_chart_data var history_monitor_data=that.data.history_monitor_data var recordsHistoryList = []; //历史数据 var alamPointList = []; //报警点 let historyChartPoint = [] //历史图表数据 for (var i = 0; i < history_monitor_data.length; i++) { history_monitor_data[i].DataTime = history_monitor_data[i].DataTime.replace(/-/gi, '/') var rec = { RecordValue: history_monitor_data[i].DataValue, RecordStatus: history_monitor_data[i].DataStatus, RecordStatusText: DataStatusTextEmun(history_monitor_data[i].DataStatus[0]), RecordTime: util.functions.sub(history_monitor_data[i].DataTime, 11, 16) } recordsHistoryList.push(rec) if (history_monitor_data[i].DataStatus[0] == "BJ") { var alarm_point = { value: '', coord: [history_monitor_data[i].DataTime, history_monitor_data[i].DataValue], itemStyle: { color: '#ff0000' } } alamPointList.push(alarm_point) } } let errorEnumData = ["SZGSCW", "ZHSB", "GLSB", "BJ"] history_records.forEach(element => { let isErrorData = false for (var i = 0; i < element.DataStatus.length; i++) { if (errorEnumData.indexOf(element.DataStatus[i]) != -1) { isErrorData = true } } if (!isErrorData) { historyChartPoint.push(element) } }); that.setData({ recordsHistory: recordsHistoryList&&recordsHistoryList.reverse(), history_records: history_records }) // console.log('recordsHistory', that.data.recordsHistory) var history_chartRecordList = TransChartRecordPoint(historyChartPoint); // console.log('767', history_chartRecordList) if (barec2 == null) { wx.showModal({ title: '', content: "图表提示', '图表加载错误,请点击刷新重试", }); return; } barec2.setOption({ color: ["#37A2DA"], legend: { data: [that.data.pointName + '/' + that.data.pointUnit], top: 0, left: 'center', z: 100 }, grid: { containLabel: true, top: 30, left: 15, right: 20, }, tooltip: { show: true, trigger: 'axis', formatter: function (params) { // console.log('479', params); let pointTime = 'T' + params[0].axisValueLabel.slice(0, 5) that.setData({ scrollTwoId: pointTime, nowHistoryMonitorTime: params[0].axisValueLabel.slice(0, 5) }) return '时间:' + util.functions.sub(params[0].value[0], 11, 16) + '\n' + "历史值:" + params[0].value[1]; }, }, xAxis: { type: 'time', boundaryGap: false, axisLabel: { formatter: function (v, index) { var date = new Date(v); return util.formatTimeUtil("hh:mm", date); } }, }, yAxis: { x: 'center', type: 'value', splitLine: { lineStyle: { type: 'dashed' } }, scale: true, axisLabel: { formatter: function (val) { //console.log(val) var value = val if (val >= 1000 && val < 1000000) { value = parseFloat(formatNumber(val / 1000).toFixed(2)) + "K" } else if (val >= 1000000) { value = parseFloat(formatNumber(val / 1000000).toFixed(2)) + "M" } return value; }, }, // show: false }, dataZoom: [{ type: 'slider', //图表下方的伸缩条 show: true, //是否显示 realtime: true, // start: 0, //伸缩条开始位置(1-100),可以随时更改 end: 100, //伸缩条结束位置(1-100),可以随时更改 left: 10, right: 15, fillerColor: "rgba(22,181,203,0.4)", //选中范围的填充颜色。 borderColor: "#ddd", //边框颜色。 backgroundColor: "rgba(167,183,204,0.4)", //组件的背景颜色 throttle: 100, //设置触发视图刷新的频率。单位为毫秒(ms)。 handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', handleSize: '80%', // 控制手柄的尺寸,可以是像素大小,也可以是相对于 dataZoom 组件宽度的百分比,默认跟 dataZoom 宽度相同。 handleStyle: { color: '#16b5cb', shadowBlur: 3, // shadowBlur图片阴影模糊值,shadowColor阴影的颜色 shadowColor: '#77CCD8', shadowOffsetX: 1, shadowOffsetY: 1, opacity: 0.6, } }], series: [{ type: 'line', showSymbol: false, // smooth: true, name: that.data.pointName + '/' + that.data.pointUnit, data: history_chartRecordList, markPoint: { symbol: 'pin', symbolSize: 10, data: alamPointList } }] }) that.getHistoryAlarmRecord() }, //初始化历史查询文本图 formatType=2 initHistoryFormatChart:function(){ var that =this var seriesHitoryData = [] var history_records =that.data.history_chart_data // console.log(history_records,1592) var format_Data = getFormatData4Enum(history_records); //数据转换 const getParams_List = that.data.getParamInfo.Items; format_Data.forEach((item,i) => { getParams_List.forEach(paramsItem=>{ if (paramsItem.EnumName == item.Status) { seriesHitoryData.push({ name: that.data.pointName, value: [ i, new Date(item.StartTime) - 0, new Date(item.EndTime) - 0, item.Status, item.Duration, ], itemStyle: { color: paramsItem.DisplayColor, }, }); } }); }) //获取监控当天的监控指及状态 var monitorList = [] for (var i = 0; i < history_records.length; i++) { history_records[i].DataStatusText = DataStatusTextEmun(history_records[i].DataStatus[0]) var monitor = { id: history_records[i].SignalID, RecordValue: history_records[i].DataValue, RecordStatus: history_records[i].DataStatus, RecordStatusText: history_records[i].DataStatusText, RecordTime: util.functions.sub(history_records[i].DataTime, 11, 16), } monitorList.push(monitor) } // console.log(monitorList,1616) that.setData({ recordsHistory: monitorList&&monitorList.reverse() }); if (barec2 == null) { util.popup.showModal('图表提示', '图表加载错误,请点击刷新重试') return; } setTimeout(() => { barec2.setOption({ tooltip: { show: true, formatter: function (params) { // console.log(params,492) return ( params.name + ': ' + params.value[4] + '小时' + '\n' + '开始时间: ' + new Date(params.value[1]).getHours() + ':' + new Date(params.value[1]).getMinutes() + '\n' + '结束时间: ' + new Date(params.value[2]).getHours() + ':' + new Date(params.value[2]).getMinutes() ); }, }, title: { text: that.data.stationName, x: 'center', y: '7px', textStyle: { color: '#16b5cb', fontSize: 16 }, textAlign: 'left' }, grid: { left: '17%', bottom: '60', top: '40', right: '4%' }, xAxis: { type: 'time', min: function (value) { //设置X轴的最小刻度 let minTime = new Date(that.data.historyDate).setHours(0, 0, 0, 0) return minTime; }, max: function (value) { //设置X轴的最大刻度 let maxTime = new Date(that.data.historyDate).setHours(23, 59, 59, 0) return maxTime; }, boundaryGap: false, axisLabel: { formatter: function (v, index) { var date = new Date(v); return util.formatTimeUtil("hh:mm", date); } }, }, yAxis: { splitLine: { show: false }, axisLabel: { interval: 0, rotate: 20 }, scale: false, offset: 2, inverse: true, data: [that.data.pointName] }, dataZoom: [{ type: 'slider', //图表下方的伸缩条 show: true, //是否显示 realtime: true, // start: 0, //伸缩条开始位置(1-100),可以随时更改 end: 100, //伸缩条结束位置(1-100),可以随时更改 left: 10, right: 15, fillerColor: "rgba(22,181,203,0.4)", //选中范围的填充颜色。 borderColor: "#ddd", //边框颜色。 backgroundColor: "rgba(167,183,204,0.4)", //组件的背景颜色 throttle: 100, //设置触发视图刷新的频率。单位为毫秒(ms)。 handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', handleSize: '80%', // 控制手柄的尺寸,可以是像素大小,也可以是相对于 dataZoom 组件宽度的百分比,默认跟 dataZoom 宽度相同。 handleStyle: { color: '#16b5cb', shadowBlur: 3, // shadowBlur图片阴影模糊值,shadowColor阴影的颜色 shadowColor: '#77CCD8', shadowOffsetX: 1, shadowOffsetY: 1, opacity: 0.6, } }], series: [{ type: 'custom', renderItem: renderItemFunc, itemStyle: { opacity: 1 }, encode: { x: [1, 2], y: 0 }, data:seriesHitoryData }] }) }, 500); return }, //获取历史的报警记录 getHistoryAlarmRecord() { let that = this let history_records = that.data.history_records // console.log(history_records,1180) Request({ url: Constant.BASE_SERVER_URL + "Monitor/Value/Alarm/Record/Std/GetBySignalIDOfDay@V1.0", method: 'GET', data: { SignalID : that.data.pointID, Day: that.data.historyDate }, header: { 'content-type': 'application/json' }, success: (res) => { // console.log("报警记录",res) //第一次加载历史图表成功 that.setData({ isloadHistoryChart: true }) if (res.data.Code < 0) { return } if (res.data.Data == null) { res.data.Data = [] return } let result = res.data.Data let recordHistoryList = [] for (let j = 0; j < result.length; j++) { let resultRecord = result[j] resultRecord.DataTime = resultRecord.DataTime.replace(/-/gi, '/') let resultRecordDataTime = new Date(resultRecord.DataTime).getTime() for (var i = 0; i < history_records.length; i++) { let realRecord = history_records[i] realRecord.DataTime = realRecord.DataTime.replace(/-/gi, '/') let realRecordDataTime = new Date(realRecord.DataTime).getTime() let rec = { RecordValue: parseFloat(realRecord.DataValue).toFixed(2), RecordStatus: realRecord[i].DataStatus, RecordStatusText: DataStatusTextEmun(realRecord[i].DataStatus[0]), RecordTime: util.functions.sub(realRecord.DataTime, 11, 16) } if (realRecordDataTime == resultRecordDataTime) { // console.log(realRecordDataTime == resultRecordDataTime,1209) // realRecord.DataStatus.push('BJ') //BJ:报警 realRecord.DataStatus[0] = 'BJ' //BJ:报警 rec.RecordStatus = realRecord.DataStatus[0] rec.RecordStatusText = DataStatusTextEmun(realRecord.DataStatus[0]) } recordHistoryList.push(rec) } } // console.log(historyMonitorList.length,469) that.setData({ recordsHistory: history_records, }); //判断是否有报警点,如果有则显示在图表上 var realAlarmPoint = [] for (let r = 0; r < history_records.length; r++) { if (history_records[r].RecordStatus == 'BJ') { history_records[r].DataTime = history_records[r].DataTime.replace(/-/gi, '/') var real_alarm_point = { value: '', coord: [history_records[r].DataTime, history_records[r].DataValue], itemStyle: { color: '#ff0000' } } realAlarmPoint.push(real_alarm_point) } } barec2.setOption({ series: { markPoint: { data: realAlarmPoint } } }) }, fail: (err) => { } }) }, //监控界面详情列表隐藏 hiddenList(e) { this.data.ishidden = !this.data.ishidden this.setData({ ishidden: this.data.ishidden }) }, //点击筛选时历史数据列表状态改变 changeStatus() { console.log('我被点击了'); this.data.historyStatus = !this.data.historyStatus this.setData({ historyStatus: this.data.historyStatus }) console.log() }, /**生命周期函数--监听页面初次渲染完成*/ onReady: function () { var DelayTime = 500; //毫秒 延迟0.5秒 防止图表barec1/barec2为null setTimeout(this.initParamsReal, DelayTime) }, /**生命周期函数--监听页面显示*/ onShow: function () {}, /**生命周期函数--监听页面隐藏*/ onHide: function () {}, /**生命周期函数--监听页面卸载*/ onUnload: function () { if (this.data.intervalRefreshTime != null) clearInterval(this.data.intervalRefreshTime); }, /**页面相关事件处理函数--监听用户下拉动作*/ onPullDownRefresh: function () {}, /**页面上拉触底事件的处理函数*/ onReachBottom: function () {}, //获取警报 getAlarmData: function () { var that = this; var alarmListInfo = that.data.alarmListInfo wx.showLoading({ title: '加载中...', }) const endNext=util.formatDay(util.GetNextDate(that.data.endAlarmDate, 1)) Request({ url: Constant.BASE_SERVER_URL + "Monitor/Value/Alarm/Record/Std/GetPageListBySignalID@V1.0", method: 'GET', data: { SignalID : that.data.pointID, StartTime: that.data.startAlarmDate, EndTime: endNext, PageIndex: that.data.PageIndex, PageSize: that.data.PageSize }, header: { 'content-type': 'application/json' }, fail: function (err) { wx.showModal({ title: '', content: '通讯失败', }) }, //请求失败 complete: function () { that.setData({ loadingHidden: true }); }, //请求完成后执行的函数 success: function (res) { console.log('打印警报信息', res.data) wx.hideLoading() if (res.data.Code != 0) { wx.showToast({ title: '获取数据失败', }); that.setData({ hasAlarmData: false }); return; } if(res.data.Data.List==null) { wx.showToast({ title: '当前无报警数据', }); that.setData({ hasAlarmData: false }); return; } if (res.data.Data.List.length == 0) { wx.showToast({ title: '当前日期,没有获取到监控值', }); that.setData({ hasAlarmData: false }); return; } if (res.data.Data.Total == 0) { that.setData({ hasAlarmData: false, message: '暂无报警数据' }); return; } if (res.data.Data.List == null) { that.setData({ bottomStatus: true, message: '暂无报警数据' }); return; } if (that.data.PageIndex * that.data.PageSize > res.data.Data.Total) { let list = res.data.Data.List that.setData({ bottomStatus: true, hasAlarmData: false, alarmListInfo: alarmListInfo.concat(list) }) return; } var ListInfo = res.data.Data.List var pageIndex = that.data.PageIndex //更新数据 that.setData({ hasAlarmData: true, alarmListInfo: alarmListInfo.concat(ListInfo), PageIndex: ++pageIndex }); } }); }, //警报列表 -- 到底部时加载数据 lowRefresh: function () { var that = this if (that.data.bottomStatus == true) { return; } that.getAlarmData() }, //刷新报警 tapRefreshAlarm: function () { this.setData({ PageIndex: 1, alarmListInfo: [], }) this.getAlarmData(); }, /**用户点击右上角分享*/ onShareAppMessage: function () { return Constant.Share; }, //监控图标间隔 onTapInterval() { var fixed = this.data.Fixed; fixed.ec1.interval = "onTapIntervalF"; this.setData({ Fixed: fixed }); barec1.setOption({ yAxis: { boundaryGap: ['15%', '15%'], scale: true, } }) }, onTapIntervalF() { var fixed = this.data.Fixed; fixed.ec1.interval = "onTapInterval"; this.setData({ Fixed: fixed }); barec1.setOption({ yAxis: { boundaryGap: ['0%', '0%'], scale: false, } }) }, //历史刷新 onTapRefreshHistory() { var that = this that.getHistoryData() setTimeout(function () { that.setData({ scrollTwoId: '', historyScrollTop: 0, nowHistoryMonitorTime: '' }) }, 1000) // console.log(this.data.scrollTwoId, this.data.historyScrollTop, this.data.nowHistoryMonitorTime) }, //历史图标间隔 onTapIntervalHistory() { var fixed = this.data.Fixed; fixed.ec2.interval = "onTapIntervalHistoryF"; this.setData({ Fixed: fixed }); barec2.setOption({ yAxis: { boundaryGap: ['15%', '15%'], scale: true, } }) }, onTapIntervalHistoryF() { var fixed = this.data.Fixed; fixed.ec2.interval = "onTapIntervalHistory"; this.setData({ Fixed: fixed }); barec2.setOption({ yAxis: { boundaryGap: ['0%', '0%'], scale: false, } }) }, //筛选监测页面报警或者正常状态 changeMonitorStatus() { var that = this var isMonitorChange = that.data.isMonitorChange var monitorList = that.data.monitorList var monitorAlam = [] if (isMonitorChange) { isMonitorChange = false that.setData({ isMonitorChange: isMonitorChange, monitorList: monitorList }) } else { isMonitorChange = true for (var a = 0; a < monitorList.length; a++) { if (monitorList[a].RecordStatus.length > 0) { monitorAlam.push(monitorList[a]) } } that.setData({ isMonitorChange: isMonitorChange, monitorAlam: monitorAlam }) } }, //筛选历史页面报警或者正常状态 changeHistoryStatus() { var that = this var isHistoryChange = that.data.isHistoryChange var recordsHistory = that.data.recordsHistory var historyAlam = [] if (isHistoryChange) { isHistoryChange = false that.setData({ isHistoryChange: isHistoryChange, recordsHistory: recordsHistory }) } else { isHistoryChange = true for (var h = 0; h < recordsHistory.length; h++) { if (recordsHistory[h].RecordStatus.length > 0) { historyAlam.push(recordsHistory[h]) } } that.setData({ isHistoryChange: isHistoryChange, historyAlam: historyAlam }) } } }) function DataStatusTextEmun(value) { let text = "" if (value == "GLSB") { text = "过滤失败" } else if (value == "SZGSCW") { text = "数据格式错误" } else if (value == "ZHSB") { text = "转换失败" } else { text = "正常" } return text } //数据格式转换 function TransChartRecordPoint(record) { let m_chartRecordList = []; let length = record.length; for (let i = 0; i < length; i++) { let dataValue = { value: [record[i].DataTime, record[i].DataValue] }; m_chartRecordList.push(dataValue); } return m_chartRecordList; } //枚举数据格式化 function getFormatData4Enum(arr) { var temp = arr[0]; var formatData = []; for (var i = 0; i < arr.length - 1; i++) { //var node = arr[i]; if (arr[i].DataValue != arr[i + 1].DataValue) { var duration = ((+new Date(arr[i + 1].DataTime) - +new Date(temp.DataTime)) / 1000 / 60 / 60).toFixed(2); formatData.push({ StartTime: temp.DataTime, EndTime: arr[i + 1].DataTime, Status: temp.DataValue, Duration: duration ,DataStatus:temp.DataStatus}); temp = arr[i + 1]; } if (i == arr.length - 2) { var len = arr.length - 1; let duration = null; duration = Math.round(((+new Date(arr[len].DataTime) - +new Date(temp.DataTime)) / 1000 / 60 / 60) * 100) / 100; formatData.push({ StartTime: temp.DataTime, EndTime: arr[len].DataTime, Status: temp.DataValue, Duration: duration,DataStatus:temp.DataStatus }); } } return formatData; } //解决小数精度问题 function formatNumber(n) { return parseFloat(parseFloat(n).toFixed(12)) } function renderItemFunc(params, api) { var categoryIndex = api.value(0); var start = api.coord([api.value(1), categoryIndex]); var end = api.coord([api.value(2), categoryIndex]); var height = api.size([0, 1])[1] * 0.6 < 40 ? api.size([0, 1])[1] * 0.6 : 40; var barLength = end[0] - start[0]; var runtime = api.value(3) + ':' + api.value(4) + 'h'; var flightNumberWidth = echarts.format.getTextRect(runtime).width; var text = runtime; text = barLength > flightNumberWidth ? text : ''; var rectShape = echarts.graphic.clipRectByRect( { x: start[0], y: start[1] - height / 2, width: end[0] - start[0], height: height, }, { x: params.coordSys.x, y: params.coordSys.y, width: params.coordSys.width, height: params.coordSys.height, } ); return { type: 'rect', shape: rectShape, style: { ...api.style(), text: text, textFill: '#fff', }, }; }