hb_zhgd_screen/js/pages/dataAnalysisOctober/environDetection.js

612 lines
17 KiB
JavaScript
Raw Normal View History

2025-10-18 15:55:58 +08:00
let table, layer, form,laydate;
2025-10-16 18:13:19 +08:00
let fontSize = '14', fontFamily = 'Alibaba PuHuiTi R', fontColor = '#fff';
const bidCode = parent.$('#bidPro').val();
2025-10-18 15:55:58 +08:00
layui.use(["layer", "table", "form", "laydate"], function () {
2025-10-16 18:13:19 +08:00
layer = layui.layer;
table = layui.table;
form = layui.form;
2025-10-18 15:55:58 +08:00
laydate = layui.laydate;
laydate.render({
elem: "#ID-laydate-rangeLinked",
range: ["#ID-laydate-start-date-1", "#ID-laydate-end-date-1"],
rangeLinked: true, // 开启日期范围选择时的区间联动标注模式 --- 2.8+ 新增
});
2025-10-16 18:13:19 +08:00
2025-10-18 15:55:58 +08:00
// $("#ID-laydate-start-date-1").val(getNowTime())
// $("#ID-laydate-end-date-1").val(getNowTime())
2025-10-16 18:13:19 +08:00
2025-10-18 15:55:58 +08:00
$("#ID-laydate-start-date-1").val('2024-05-28')
$("#ID-laydate-end-date-1").val('2024-06-02')
2025-10-16 18:13:19 +08:00
2025-10-18 15:55:58 +08:00
let startTime = "";
let endTime = "";
if ($("#ID-laydate-start-date-1").val() != "") {
startTime = $("#ID-laydate-start-date-1").val();
endTime = $("#ID-laydate-end-date-1").val();
} else {
startTime = "";
endTime = "";
}
getProEnvironment(startTime, endTime);
2025-10-16 18:13:19 +08:00
});
2025-10-18 15:55:58 +08:00
function query(){
let startTime = "";
let endTime = "";
if ($("#ID-laydate-start-date-1").val() != "") {
startTime = $("#ID-laydate-start-date-1").val();
endTime = $("#ID-laydate-end-date-1").val();
} else {
startTime = "";
endTime = "";
}
getProEnvironment(startTime, endTime);
}
function getProEnvironment(startTime, endTime) {
const url =
commonUrl +
"screen/proEnvironment/selectProEnvironment?startDate=" + startTime + "&endDate=" + endTime + "&bidCode=" + '1512P017007Y01';
ajaxRequestGet(
url,
"GET",
true,
function () {
},
function (result) {
if (result.code === 200) {
setData(result.data);
} else if (result.code === 500) {
console.error("实时监测" + result.msg);
setData(null);
} else if (result.code === 401) {
loginout(1);
}
},
function (xhr, status, error) {
errorFn(xhr, status, error);
setData(null);
},
aqEnnable
);
/* 实时检测赋值 */
function setData(data) {
if (data) {
let pmTwo = data["PM2.5"];
let pmTen = data["PM10"];
getAirQualityChart(pmTwo, pmTen)
let noise = data["噪声"];
getNoiseChart(noise);
let temperature = data["温度"];
let humidity = data["湿度"];
getTemperatureHumidityChart(temperature,humidity)
let warning = data["预警"];
warningList(warning);
let windSpeed = data["风速"];
getWindSpeedChart(windSpeed);
}
}
}
function getTemperatureHumidityChart(temperature,humidity) {
let timeData = [];
let timeData1 = [];
let timeData2 = [];
let temperatureData = [];
let humidityData = [];
if (temperature) {
for (let i = 0; i < temperature.length; i++){
timeData1.push(temperature[i].hour +':00');
temperatureData.push(temperature[i].val)
}
}
if( humidity){
for (let i = 0; i < humidity.length; i++){
timeData2.push(humidity[i].hour +':00');
humidityData.push(humidity[i].val)
}
}
if(timeData1.length>0){
timeData = timeData1
}else{
timeData = timeData2
}
2025-10-16 18:13:19 +08:00
initTemperatureHumidityChart(timeData, temperatureData, humidityData)
}
function initTemperatureHumidityChart(timeData, temperatureData, humidityData) {
2025-10-18 15:55:58 +08:00
if(timeData.length<=0){
return "";
}
2025-10-16 18:13:19 +08:00
const myChart = echarts.init(document.getElementById("temperatureHumidityChart"));
const option = {
grid: {
left: "8%",
right: "8%",
top: "20%",
bottom: "5%",
containLabel: true,
},
legend: {
data: ["温度", "湿度"],
top: "12%",
right: "15%",
textStyle: {
color: "#ffffff",
fontSize: 12,
},
itemWidth: 14,
itemHeight: 4,
icon: "rect",
},
xAxis: {
type: "category",
data: timeData,
axisLine: {
lineStyle: {
color: "#A6B8BB",
},
},
axisLabel: {
color: "#A6B8BB",
fontSize: 14,
},
axisTick: {
show: false,
},
},
yAxis: [
{
type: "value",
name: "°C",
nameTextStyle: {
color: "#ffffff",
fontSize: 12,
},
axisLine: {
show: false,
},
axisLabel: {
color: "#A6B8BB",
fontSize: 12,
},
splitLine: {
lineStyle: {
color: 'rgba(255, 255, 255, 0.2)',
type: 'dashed'
}
},
},
{
type: "value",
name: "%",
nameTextStyle: {
color: "#ffffff",
fontSize: 12,
},
axisLine: {
show: false,
},
axisLabel: {
color: "#A6B8BB",
fontSize: 12,
},
splitLine: {
2025-10-18 15:55:58 +08:00
lineStyle: {
color: 'rgba(255, 255, 255, 0.2)',
type: 'dashed'
}
2025-10-16 18:13:19 +08:00
},
},
],
series: [
{
name: "温度",
type: "bar",
data: temperatureData,
barWidth: "35%",
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 1, color: "#134045"},
{offset: 0.5, color: "#3EB2BB"},
{offset: 0, color: "#59E1FF"},
]),
borderRadius: [4, 4, 0, 0],
},
},
{
name: "湿度",
type: "line",
yAxisIndex: 1,
data: humidityData,
smooth: true,
lineStyle: {
color: "#00ff88",
width: 3,
shadowColor: "rgba(0, 255, 136, 0.5)",
shadowBlur: 10,
},
itemStyle: {
color: "#00ff88",
borderWidth: 2,
borderColor: "#00ff88",
},
symbolSize: 0,
},
],
}
myChart.setOption(option)
// 响应窗口大小变化
window.addEventListener('resize', function () {
myChart.resize();
});
}
2025-10-18 15:55:58 +08:00
function getNoiseChart(noise) {
var timeData = [];
var noiseData = [];
if (noise) {
for (let i = 0; i < noise.length; i++){
timeData.push(noise[i].hour +':00');
noiseData.push(noise[i].val)
}
}
2025-10-16 18:13:19 +08:00
initNoiseChart(timeData, noiseData);
}
function initNoiseChart(timeData, noiseData) {
var myChart = echarts.init(document.getElementById('noiseChart'));
var option = {
grid: {
left: '5%',
right: '5%',
bottom: '5%',
top: '23%',
containLabel: true
},
xAxis: {
type: 'category',
data: timeData,
axisLine: {
lineStyle: {
color: '#A6B8BB'
}
},
axisLabel: {
color: '#A6B8BB',
fontSize: 12
},
axisTick: {
show: false
}
},
yAxis: {
type: 'value',
name: '分贝',
nameTextStyle: {
color: '#ffffff',
fontSize: 12,
},
axisLine: {
show: false,
},
axisLabel: {
color: '#A6B8BB',
fontSize: 12,
},
splitLine: {
lineStyle: {
color: 'rgba(255, 255, 255, 0.2)',
type: 'dashed'
}
}
},
series: [
{
name: '噪声',
type: 'line',
data: noiseData,
symbolSize: 0,
lineStyle: {
color: "#00FEFC",
width: 3,
shadowColor: "rgba(0, 255, 136, 0.5)",
shadowBlur: 10,
},
itemStyle: {
color: "#00ff88",
borderWidth: 2,
borderColor: "#00ff88",
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: '#1ED6FF'},
{offset: 1, color: 'rgba(30,214,255,0)'}
])
}
}]
};
myChart.setOption(option);
// 响应窗口大小变化
window.addEventListener('resize', function () {
myChart.resize();
});
}
2025-10-18 15:55:58 +08:00
function getWindSpeedChart(windSpeed) {
var timeData = [];
var noiseData = [];
if (windSpeed) {
for (let i = 0; i < windSpeed.length; i++){
timeData.push(windSpeed[i].hour +':00');
noiseData.push(windSpeed[i].val)
}
}
2025-10-16 18:13:19 +08:00
initWindSpeedChart(timeData, noiseData);
}
function initWindSpeedChart(timeData, noiseData) {
var myChart = echarts.init(document.getElementById('windSpeedChart'));
var option = {
grid: {
left: '5%',
right: '5%',
bottom: '5%',
top: '23%',
containLabel: true
},
xAxis: {
type: 'category',
data: timeData,
axisLine: {
lineStyle: {
color: '#A6B8BB'
}
},
axisLabel: {
color: '#A6B8BB',
fontSize: 12
},
axisTick: {
show: false
}
},
yAxis: {
type: 'value',
name: 'm/s',
nameTextStyle: {
color: '#ffffff',
fontSize: 12,
},
axisLine: {
show: false,
},
axisLabel: {
color: '#A6B8BB',
fontSize: 12,
},
splitLine: {
lineStyle: {
color: 'rgba(255, 255, 255, 0.2)',
type: 'dashed'
}
}
},
series: [
{
name: '噪声',
type: 'line',
data: noiseData,
symbolSize: 0,
lineStyle: {
color: "#1CFFA3 ",
width: 3,
shadowColor: "rgba(0, 255, 136, 0.5)",
shadowBlur: 10,
},
itemStyle: {
color: "#00ff88",
borderWidth: 2,
borderColor: "#00ff88",
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: '#1CFFA3'},
{offset: 1, color: 'rgba(28,255,163,0)'}
])
}
}]
};
myChart.setOption(option);
// 响应窗口大小变化
window.addEventListener('resize', function () {
myChart.resize();
});
}
2025-10-18 15:55:58 +08:00
function getAirQualityChart(pmTwo, pmTen) {
var timeData = [];
var timeData1 = [];
var timeData2 = [];
var pm25Data = [];
var pm10Data = [];
if (pmTwo) {
for (let i = 0; i < pmTwo.length; i++){
timeData1.push(pmTwo[i].hour +':00');
pm25Data.push(pmTwo[i].val)
}
}
if (pmTen) {
for (let i = 0; i < pmTen.length; i++){
timeData2.push(pmTen[i].hour +':00');
pm10Data.push(pmTen[i].val)
}
}
if (timeData1){
timeData = timeData1;
} else {
timeData = timeData2;
}
2025-10-16 18:13:19 +08:00
initAirQualityChart(timeData, pm25Data, pm10Data);
}
function initAirQualityChart(timeData, pm25Data, pm10Data) {
var myChart = echarts.init(document.getElementById('airQualityChart'));
var option = {
legend: {
data: ['PM2.5', 'PM10'],
top: "12%",
right: "5%",
textStyle: {
color: "#ffffff",
fontSize: 12,
},
itemWidth: 14,
itemHeight: 4,
icon: "rect",
},
grid: {
left: '5%',
right: '5%',
bottom: '5%',
top: '22%',
containLabel: true
},
xAxis: {
type: 'category',
data: timeData,
axisLine: {
lineStyle: {
color: '#A6B8BB'
}
},
axisLabel: {
color: '#A6B8BB',
fontSize: 12
},
axisTick: {
show: false
}
},
yAxis: {
type: 'value',
name: 'Jpg/m³',
nameTextStyle: {
color: 'rgba(255,255,255,0.8)',
fontSize: 12
},
axisLine: {
show:false,
},
axisLabel: {
color: '#A6B8BB',
fontSize: 12,
formatter: '{value}'
},
splitLine: {
lineStyle: {
color: 'rgba(255, 255, 255, 0.2)',
type: 'dashed'
}
}
},
series: [
{
name: 'PM2.5',
type: 'line',
data: pm25Data,
symbolSize: 0,
color: '#00FEFC', // 添加color属性
lineStyle: {
color: '#00FEFC',
width: 3
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: '#1ED6FF'},
{offset: 1, color: 'rgba(30,214,255,0)'}
])
}
},
{
name: 'PM10',
type: 'line',
data: pm10Data,
color: '#1CFFA3', // 添加color属性
symbolSize: 0,
lineStyle: {
color: '#1CFFA3',
width: 3
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: '#1CFFA3'},
{offset: 1, color: 'rgba(28,255,163,0)'}
])
}
}
]
};
// 使用配置项和数据显示图表
myChart.setOption(option);
// 响应窗口大小变化
window.addEventListener('resize', function () {
myChart.resize();
});
}
2025-10-18 15:55:58 +08:00
function warningList(warning){
// 确保 efficiency 是数组且不为空
const tableData = warning && warning.length > 0 ? warning : [];
if (tableData.length === 0) {
console.log('没有数据可显示');
// 可以显示空数据提示
document.getElementById('dome1').innerHTML = '<div class="no-data">暂无数据</div>';
return;
}
2025-10-16 18:13:19 +08:00
table.render({
elem: '#dome1',
2025-10-18 15:55:58 +08:00
data: tableData,
2025-10-16 18:13:19 +08:00
skin: 'line',
page: false,
headers:{
decrypt:"decrypt",
"Authorization":token
},
cols: [[
{field: 'number', width:'10%',title: '序号', align: 'center', type: 'numbers'},
2025-10-18 15:55:58 +08:00
{field: 'modeName', width:'30%', align: 'center', title: '预警类型'},
{field: 'currentDay', width:'30%', align: 'center', title: '预警时间'},
{field: 'deviceName', width:'30%', align: 'center', title: '预警内容'},
2025-10-16 18:13:19 +08:00
]],
initComplete: function () {
// 在表格渲染完成后,重新渲染序号列
var that = this.elem.next();
var tool = that.children('.layui-table-box').children('.layui-table-fixed').children('.layui-table-body').children('.layui-table');
tool.find("tr").each(function (index, item) {
$(this).find('td[data-field="LAY_TABLE_INDEX"]').text(index + 1);
});
},
done:function(res, curr, count, origin){
console.log(res);
}
})
}