/*
|
* @Description: 监测页面的公共方法
|
* @Version: 1.0
|
* @Author: yangsx
|
* @Date: 2019-11-29 09:12:06
|
* @LastEditors: yangsx
|
* @LastEditTime: 2019-12-13 17:08:09
|
*/
|
|
/**
|
* @description: 获取时间
|
* @param {type}
|
* @return:
|
* @author: yangsx
|
*/
|
|
function currentTime(date) {
|
var day = date;
|
var Year = 0;
|
var Month = 0;
|
var Day = 0;
|
var Hour = 0;
|
var Minute = 0;
|
var Second = 0;
|
var CurrentDateMap = {
|
monthDate: "",
|
dayDate: "",
|
hourDate: "",
|
minuteDate: "",
|
secondDate: ""
|
};
|
var CurrentDate = "";
|
//初始化时间
|
Year = day.getFullYear();
|
Month = day.getMonth() + 1;
|
Day = day.getDate();
|
Hour = day.getHours();
|
Minute = day.getMinutes();
|
Second = day.getSeconds();
|
CurrentDate = CurrentDate + Year + "-";
|
if (Month >= 10) {
|
CurrentDate = CurrentDate + Month;
|
} else {
|
CurrentDate = CurrentDate + "0" + Month;
|
}
|
CurrentDateMap.monthDate = CurrentDate;
|
if (Day >= 10) {
|
CurrentDate = CurrentDate + "-" + Day;
|
} else {
|
CurrentDate = CurrentDate + "-0" + Day;
|
}
|
CurrentDateMap.dayDate = CurrentDate;
|
if (Hour >= 10) {
|
CurrentDate += " " + Hour;
|
} else {
|
CurrentDate += " 0" + Hour;
|
}
|
CurrentDateMap.hourDate = CurrentDate;
|
if (Minute >= 10) {
|
CurrentDate = CurrentDate + ":" + Minute;
|
} else {
|
CurrentDate = CurrentDate + ":0" + Minute;
|
}
|
CurrentDateMap.minuteDate = CurrentDate;
|
if (Second >= 10) {
|
CurrentDate = CurrentDate + ":" + Second;
|
} else {
|
CurrentDate = CurrentDate + ":0" + Second;
|
}
|
CurrentDateMap.secondDate = CurrentDate;
|
return CurrentDateMap;
|
}
|
|
/**
|
* @description: 获取本周时间区间
|
* @param {type}
|
* @return:
|
* @author: yangsx
|
*/
|
function getWeekSL() {
|
return (
|
currentTime(
|
new Date(new Date() - 24 * 60 * 60 * 1000 * (new Date().getDay() - 1))
|
).dayDate + " 00:00:00"
|
);
|
}
|
/**
|
* @description: 获取本月时间区间
|
* @param {type}
|
* @return:
|
* @author: yangsx
|
*/
|
function getMonthSL() {
|
return currentTime(new Date()).monthDate + "-01 00:00:00";
|
}
|
|
/**
|
* @description: 更新时间显示
|
* @param {type}
|
* @return:
|
* @author: yangsx
|
*/
|
(function upCurrentTime() {
|
$("#currentTime").html(currentTime(new Date()).minuteDate);
|
setTimeout(function() {
|
upCurrentTime();
|
}, 1000);
|
})();
|
|
/**
|
* @description: 点击查询调用的事件
|
* @param {void} method 事件函数
|
* @return:
|
* @author: yangsx
|
*/
|
function queryHistoricalData(method) {
|
var queryStart = $("#queryStart").val();
|
var queryEnd = $("#queryEnd").val();
|
method(queryStart, queryEnd);
|
}
|
|
//数据查询定时器
|
var todayTimeout;
|
/**
|
* @description: 当查询时间段为今日时将进行轮询
|
* @param {type}
|
* @return:
|
* @author: yangsx
|
*/
|
function todayTimeoutMethod() {
|
todayTimeout = setTimeout(function() {
|
queryHistoricalData(function(queryStart, queryEnd) {
|
getPastData(queryStart, queryEnd);
|
todayTimeoutMethod();
|
});
|
}, 1000 * 60 * 2);
|
}
|
|
//快捷选择日,周,月查询
|
$("#selectInterval span").click(function() {
|
$("#selectInterval span").removeClass("active");
|
$(this).addClass("active");
|
var name = $(this).attr("name");
|
var slStartDate = "";
|
var slEndDate = currentTime(new Date()).secondDate;
|
if (name === "today") {
|
slStartDate = currentTime(new Date()).dayDate + " 00:00:00";
|
} else if (name === "week") {
|
slStartDate = getWeekSL();
|
} else if (name === "month") {
|
slStartDate = getMonthSL();
|
}
|
$("#queryStart").val(slStartDate);
|
$("#queryEnd").val(slEndDate);
|
if (todayTimeout) {
|
clearTimeout(todayTimeout);
|
}
|
if (name === "today") {
|
queryHistoricalData(function(queryStart, queryEnd) {
|
getPastData(queryStart, queryEnd);
|
});
|
todayTimeoutMethod();
|
} else {
|
queryHistoricalData(function(queryStart, queryEnd) {
|
getPastData(queryStart, queryEnd);
|
});
|
}
|
});
|
|
//点击查询事件
|
$("#queryHistorical").click(function() {
|
$("#queryReset").removeClass("active");
|
$(this).addClass("active");
|
queryHistoricalData(function(queryStart, queryEnd) {
|
getPastData(queryStart, queryEnd);
|
});
|
});
|
|
// 点击取消事件(已取消该功能)
|
$("#queryReset").click(function() {
|
$("#queryHistorical").removeClass("active");
|
$(this).addClass("active");
|
});
|
|
//打开阈值设置界面
|
$(".historical_data_threshold").click(function() {
|
var index = $(this).attr("index");
|
var flag = $("#" + index + "").css("display") == "none";
|
|
if (flag) {
|
$(".threshold_content").hide();
|
$("#" + index + "").show(100);
|
$("#" + index + " input:nth-child(2)").val(
|
$("#" + index + "").attr("minThreshold")
|
);
|
$("#" + index + " input:nth-child(4)").val(
|
$("#" + index + "").attr("maxThreshold")
|
);
|
$("#" + index + " input:nth-child(2)").bind(
|
"input propertychange",
|
function() {
|
$("#" + index + "").attr("minThreshold", $(this).val());
|
}
|
);
|
$("#" + index + " input:nth-child(4)").bind(
|
"input propertychange",
|
function() {
|
$("#" + index + "").attr("maxThreshold", $(this).val());
|
}
|
);
|
} else {
|
$("#" + index + "").hide();
|
}
|
$(".threshold_content_confirm").unbind();
|
$(".threshold_content_confirm").click(function() {
|
var minYz = Number($("#" + index + "").attr("minThreshold"));
|
var maxYz = Number($("#" + index + "").attr("maxThreshold"));
|
|
if (minYz >= maxYz) {
|
alert("阈值最小值不能大于等于最大值");
|
return;
|
}
|
$("#" + index + "").hide();
|
updateYzByStcdAndField(
|
{
|
stcd: stcd,
|
field: index,
|
minYz: minYz,
|
maxYz: maxYz
|
},
|
function(res) {
|
queryHistoricalData(function(queryStart, queryEnd) {
|
getPastData(queryStart, queryEnd);
|
});
|
}
|
);
|
});
|
});
|
|
/**
|
* @description: 提取图表的 x y 轴坐标
|
* @param {map} list 数据集合
|
* @param {number} fixed 需要保留的小数点位数
|
* @return: x y 轴数据集合
|
* @author: yangsx
|
*/
|
function getCoordinate(list, fixed) {
|
var echartsX = [];
|
var echartsY = [];
|
for (var i = 0; i < list.length; i++) {
|
echartsX.push(list[i].endTime);
|
echartsY.push(Number(list[i].value).toFixed(fixed ? fixed : 2));
|
}
|
return {
|
echartsX: echartsX,
|
echartsY: echartsY
|
};
|
}
|
|
/**
|
* @description: 解析设置阈值
|
* @param {type} obj 数据
|
* @return:
|
* @author: yangsx
|
*/
|
function setThreshold(obj) {
|
$("#" + obj.code + "").attr(
|
"minThreshold",
|
obj.minYz == "notNumber" ? 0 : obj.minYz
|
);
|
$("#" + obj.code + "").attr(
|
"maxThreshold",
|
obj.maxYz == "notNumber" ? 1 : obj.maxYz
|
);
|
}
|
|
//数据导出功能
|
$("#exportHistorical").click(function() {
|
var startTimeE = $("#queryStart").val();
|
var endTimeE = $("#queryEnd").val();
|
var eleType = $(this).attr("eleType");
|
var title = $(this).attr("title");
|
layui.use("layer", function() {
|
var layer = layui.layer;
|
layer.confirm(
|
"导出 " + startTimeE + " 至 " + endTimeE + " 的数据!",
|
{
|
btn: ["是", "否"] //按钮
|
},
|
function() {
|
booleanExcelExportElements(
|
{
|
stcd: stcd,
|
startTime: startTimeE,
|
endTime: endTimeE,
|
eleType: eleType,
|
title: title
|
},
|
function(res) {
|
if (!res.success) {
|
layer.msg(res.message);
|
} else {
|
var excelUrl = excelExportElements(
|
"?stcd=" +
|
stcd +
|
"&startTime=" +
|
startTimeE +
|
"&endTime=" +
|
endTimeE +
|
"&eleType=" +
|
eleType +
|
"&title=" +
|
title
|
);
|
layer.closeAll();
|
window.location.href = excelUrl;
|
}
|
}
|
);
|
},
|
function() {}
|
);
|
});
|
});
|