// 环境监测分析页面 let temperatureHumidityChart = null; let windSpeedChart = null; let noiseChart = null; let airQualityChart = null; let table, layer, form, laydate; let bidCode = parent.parent.$('#bidPro').val(); // 获取当天日期 function getTodayDate() { const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); const day = String(now.getDate()).padStart(2, '0'); return year + '-' + month + '-' + day; } // 获取当月第一天和最后一天(保留用于其他功能) function getCurrentMonthRange() { const now = new Date(); const year = now.getFullYear(); const month = now.getMonth(); // 当月第一天 const firstDay = new Date(year, month, 1); const startDate = year + '-' + String(month + 1).padStart(2, '0') + '-' + String(firstDay.getDate()).padStart(2, '0'); // 当月最后一天 const lastDay = new Date(year, month + 1, 0); const endDate = year + '-' + String(month + 1).padStart(2, '0') + '-' + String(lastDay.getDate()).padStart(2, '0'); return { startDate, endDate }; } const today = getTodayDate(); let queryParams = { projectId: bidCode, startTestDay: today, endTestDay: today, }; // 页面初始化 layui.use(['laydate', 'layer', 'table', 'form'], function () { laydate = layui.laydate; layer = layui.layer; table = layui.table; form = layui.form; // 响应成功后的拦截器 $.ajaxSetup({ beforeSend: function (xhr, options) { var originalSuccess = options.success; options.success = function (data, textStatus, jqXhr) { data = modifyResponseData(data); originalSuccess.apply(this, arguments); }; }, }); initDateRangePicker(); initTemperatureHumidityChart(); initWindSpeedChart(); initNoiseChart(); initAirQualityChart(); getEnvironmentAlertList(); getEnvironmentData(); // 窗口大小改变时重新调整图表 window.addEventListener('resize', debounce(() => { if (temperatureHumidityChart) temperatureHumidityChart.resize(); if (windSpeedChart) windSpeedChart.resize(); if (noiseChart) noiseChart.resize(); if (airQualityChart) airQualityChart.resize(); }, 300)); }); // 获取环境监测数据(温湿度、风速、噪声、空气质量) function getEnvironmentData() { const url = commonUrl + 'screen/environment/analysis/list' + '?projectId=' + (bidCode || '') + '&startTestDay=' + (queryParams.startTestDay || '') + '&endTestDay=' + (queryParams.endTestDay || ''); ajaxRequestGet( url, 'GET', true, function () { }, function (result) { console.log(result, '环境监测数据'); if (result && result.data && Array.isArray(result.data)) { updateAllCharts(result.data); } else { // 如果没有数据,使用空数组 updateAllCharts([]); } }, aqEnnable ); } // 获取环境监测预警列表 function getEnvironmentAlertList() { console.log('getEnvironmentAlertList 被调用'); const url = commonUrl + 'screen/environment/analysis/warnlist' + '?projectId=' + (bidCode || '') + '&startTestDay=' + (queryParams.startTestDay || '') + '&endTestDay=' + (queryParams.endTestDay || ''); console.log('预警列表请求URL:', url); ajaxRequestGet(url, 'GET', true, function () { }, function (result) { console.log('预警列表返回结果:', result); let data = []; if (result && result.data && Array.isArray(result.data)) { data = result.data; } else if (result && Array.isArray(result)) { data = result; } else if (result && result.rows && Array.isArray(result.rows)) { data = result.rows; } console.log('解析后的预警数据:', data); renderAlertTable(data); }, aqEnnable); } // 更新所有图表数据 function updateAllCharts(data) { if (!data || data.length === 0) { // 如果没有数据,保持图表为空或显示默认值 return; } // 提取数据 const temperatures = data.map(item => parseFloat(item.wd) || 0); const humidities = data.map(item => parseFloat(item.sd) || 0); const windSpeeds = data.map(item => parseFloat(item.speed) || 0); const noises = data.map(item => parseFloat(item.noise) || 0); const pm25Data = data.map(item => parseFloat(item.pm2Data) || 0); const pm10Data = data.map(item => parseFloat(item.pm1Data) || 0); // 生成时间轴,使用接口返回的 jcTime 字段 const times = data.map(item => { // 如果 jcTime 存在,使用 jcTime,否则使用空字符串 if (item.jcTime !== null && item.jcTime !== undefined) { // 如果 jcTime 是数字格式(如 "00"),格式化为时间格式(如 "00:00") const jcTimeStr = String(item.jcTime).padStart(2, '0'); return jcTimeStr + ':00'; } return ''; }); // 更新温湿度图表 updateTemperatureHumidityChart(times, temperatures, humidities); // 更新风速图表 updateWindSpeedChart(times, windSpeeds); // 更新噪声图表 updateNoiseChart(times, noises); // 更新空气质量图表 updateAirQualityChart(times, pm25Data, pm10Data); } // 更新温湿度图表 function updateTemperatureHumidityChart(times, temperatures, humidities) { if (!temperatureHumidityChart) return; temperatureHumidityChart.setOption({ xAxis: { data: times }, series: [ { name: '温度', data: temperatures }, { name: '湿度', data: humidities } ] }); } // 更新风速图表 function updateWindSpeedChart(times, windSpeeds) { if (!windSpeedChart) return; windSpeedChart.setOption({ xAxis: { data: times }, series: [ { data: windSpeeds } ] }); } // 更新噪声图表 function updateNoiseChart(times, noises) { if (!noiseChart) return; noiseChart.setOption({ xAxis: { data: times }, series: [ { data: noises } ] }); } // 更新空气质量图表 function updateAirQualityChart(times, pm25Data, pm10Data) { if (!airQualityChart) return; airQualityChart.setOption({ xAxis: { data: times }, series: [ { name: 'PM2.5', data: pm25Data }, { name: 'PM10', data: pm10Data } ] }); } // 获取温湿度 风速 噪声 空气质量 // function getTemperatureHumidityData() { // const url = commonUrl + 'screen/proEnvironment/selectProEnvironment'; // ajaxRequestGet(url, 'GET', true, function () { // console.log(result); // }); // } // 防抖函数 function debounce(fn, delay) { let t = null; return function () { clearTimeout(t); t = setTimeout(() => fn.apply(this, arguments), delay); }; } // 初始化日期范围选择器(与工程质量分析保持一致) function initDateRangePicker() { // 设置初始显示值为当天范围 const initialValue = queryParams.startTestDay + ' ~ ' + queryParams.endTestDay; $('#dateRange').val(initialValue); // 使用范围选择器,单个输入框显示日期范围 laydate.render({ elem: '#dateRange', type: 'date', range: true, // 启用范围选择 format: 'yyyy-MM-dd', theme: 'dark', // 默认值使用当天范围 value: queryParams.startTestDay + ' - ' + queryParams.endTestDay, done: function (value, date, endDate) { // 重置为当天日期的函数 const resetToToday = function () { const today = getTodayDate(); queryParams.startTestDay = today; queryParams.endTestDay = today; $('#dateRange').val(today + ' ~ ' + today); refreshAllModules(); }; if (value && value.trim() !== '') { const dates = value.split(' - '); if (dates.length === 2) { const startDate = dates[0].trim(); const endDateStr = dates[1].trim(); // 在单个输入框中显示日期范围(格式:2026-01-15 ~ 2026-01-15) $('#dateRange').val(startDate + ' ~ ' + endDateStr); // 更新查询参数 queryParams.startTestDay = startDate; queryParams.endTestDay = endDateStr; // 日期变化后,重新调用所有模块接口 refreshAllModules(); } else { // 如果格式不正确,重置为当天日期 resetToToday(); } } else { // 清空时,重置为当天日期 resetToToday(); } } }); } // 刷新所有模块数据 function refreshAllModules() { getEnvironmentAlertList(); getEnvironmentData(); } // 初始化温湿度图表 function initTemperatureHumidityChart() { temperatureHumidityChart = echarts.init(document.getElementById('temperatureHumidityChart')); const hours = ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00']; const temperature = [25, 26, 27, 28, 29, 30, 31]; const humidity = [60, 58, 56, 54, 52, 50, 48]; const option = { tooltip: { trigger: 'axis', axisPointer: { type: 'cross' }, backgroundColor: 'rgba(19, 51, 55, 0.9)', borderColor: 'rgba(0, 254, 252, 0.5)', borderWidth: 1, textStyle: { color: '#fff' }, formatter: function (params) { if (!params || !params.length) return ''; let html = `
${params[0].name}
`; params.forEach(p => { html += `
${p.seriesName} ${p.value}${p.seriesName === '温度' ? '°C' : '%'}
`; }); return html; } }, legend: { data: ['温度', '湿度'], top: 10, right: 20, textStyle: { color: '#fff', fontSize: 12 }, itemWidth: 12, itemHeight: 8, itemGap: 15 }, grid: { top: '18%', left: '8%', right: '8%', bottom: '15%' }, xAxis: { type: 'category', data: hours, axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, axisTick: { show: false } }, yAxis: [ { type: 'value', name: '°C', nameTextStyle: { color: '#fff', fontSize: 12 }, position: 'left', axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, splitLine: { lineStyle: { color: 'rgba(90, 110, 113, 0.3)', type: 'dashed' } } }, { type: 'value', name: '%', nameTextStyle: { color: '#fff', fontSize: 12 }, position: 'right', axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, splitLine: { show: false } } ], series: [ { name: '温度', type: 'bar', yAxisIndex: 0, data: temperature, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: '#4A90E2' }, { offset: 1, color: '#357ABD' } ]) }, barWidth: '30' }, { name: '湿度', type: 'line', yAxisIndex: 1, data: humidity, smooth: true, lineStyle: { width: 2, color: '#1CFFA3' }, itemStyle: { color: '#1CFFA3' }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(28, 255, 163, 0.3)' }, { offset: 1, color: 'rgba(28, 255, 163, 0.05)' } ]) } } ] }; temperatureHumidityChart.setOption(option); } // 初始化风速图表 function initWindSpeedChart() { windSpeedChart = echarts.init(document.getElementById('windSpeedChart')); const hours = ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00']; const windSpeed = [2.5, 2.8, 3.0, 3.2, 3.5, 3.3, 3.1]; const option = { tooltip: { trigger: 'axis', axisPointer: { type: 'line' }, backgroundColor: 'rgba(19, 51, 55, 0.9)', borderColor: 'rgba(28, 255, 163, 0.5)', borderWidth: 1, textStyle: { color: '#fff' } }, grid: { top: '15%', left: '10%', right: '8%', bottom: '15%' }, xAxis: { type: 'category', data: hours, axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, axisTick: { show: false } }, yAxis: { type: 'value', name: 'm/s', nameTextStyle: { color: '#fff', fontSize: 12 }, axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, splitLine: { lineStyle: { color: 'rgba(90, 110, 113, 0.3)', type: 'dashed' } } }, series: [ { type: 'line', data: windSpeed, smooth: true, lineStyle: { width: 2, color: '#1CFFA3' }, itemStyle: { color: '#1CFFA3' }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(28, 255, 163, 0.4)' }, { offset: 1, color: 'rgba(28, 255, 163, 0.05)' } ]) } } ] }; windSpeedChart.setOption(option); } // 初始化噪声图表 function initNoiseChart() { noiseChart = echarts.init(document.getElementById('noiseChart')); const hours = ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00']; const noise = [45, 48, 50, 52, 55, 53, 51]; const option = { tooltip: { trigger: 'axis', axisPointer: { type: 'line' }, backgroundColor: 'rgba(19, 51, 55, 0.9)', borderColor: 'rgba(0, 254, 252, 0.5)', borderWidth: 1, textStyle: { color: '#fff' } }, grid: { top: '15%', left: '8%', right: '6%', bottom: '15%' }, xAxis: { type: 'category', data: hours, axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, axisTick: { show: false } }, yAxis: { type: 'value', name: '分贝', nameTextStyle: { color: '#fff', fontSize: 12 }, axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, splitLine: { lineStyle: { color: 'rgba(90, 110, 113, 0.3)', type: 'dashed' } } }, series: [ { type: 'line', data: noise, smooth: true, lineStyle: { width: 2, color: '#00FEFC' }, itemStyle: { color: '#00FEFC' }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(0, 254, 252, 0.4)' }, { offset: 1, color: 'rgba(0, 254, 252, 0.05)' } ]) } } ] }; noiseChart.setOption(option); } // 初始化空气质量图表 function initAirQualityChart() { airQualityChart = echarts.init(document.getElementById('airQualityChart')); const hours = ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00']; const pm25 = [35, 38, 40, 42, 45, 43, 41]; const pm10 = [55, 58, 60, 62, 65, 63, 61]; const option = { tooltip: { trigger: 'axis', axisPointer: { type: 'line' }, backgroundColor: 'rgba(19, 51, 55, 0.9)', borderColor: 'rgba(28, 255, 163, 0.5)', borderWidth: 1, textStyle: { color: '#fff' }, formatter: function (params) { if (!params || !params.length) return ''; let html = `
${params[0].name}
`; params.forEach(p => { html += `
${p.seriesName} ${p.value}µg/m³
`; }); return html; } }, legend: { data: ['PM2.5', 'PM10'], top: 10, right: 20, textStyle: { color: '#fff', fontSize: 12 }, itemWidth: 12, itemHeight: 8, itemGap: 15 }, grid: { top: '18%', left: '10%', right: '8%', bottom: '15%' }, xAxis: { type: 'category', data: hours, axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, axisTick: { show: false } }, yAxis: { type: 'value', name: 'µg/m³', nameTextStyle: { color: '#fff', fontSize: 12 }, axisLabel: { color: '#fff', fontSize: 11 }, axisLine: { lineStyle: { color: '#5A6E71' } }, splitLine: { lineStyle: { color: 'rgba(90, 110, 113, 0.3)', type: 'dashed' } } }, series: [ { name: 'PM2.5', type: 'line', data: pm25, smooth: true, lineStyle: { width: 2, color: '#00FEFC' }, itemStyle: { color: '#00FEFC' }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(0, 254, 252, 0.3)' }, { offset: 1, color: 'rgba(0, 254, 252, 0.05)' } ]) } }, { name: 'PM10', type: 'line', data: pm10, smooth: true, lineStyle: { width: 2, color: '#1CFFA3' }, itemStyle: { color: '#1CFFA3' }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(28, 255, 163, 0.3)' }, { offset: 1, color: 'rgba(28, 255, 163, 0.05)' } ]) } } ] }; airQualityChart.setOption(option); } // 渲染环境预警表格 function renderAlertTable(alerts) { console.log(alerts, '环境预警列表'); const tbody = $('#alertTableBody'); tbody.empty(); if (!alerts || alerts.length === 0) { tbody.append('暂无数据'); return; } alerts.forEach((alert, index) => { // 字段映射:txType(预警类型)、txTime(预警时间)、content(预警内容) const serialNumber = index + 1; const warnType = alert.txType || ''; const warnTime = alert.txTime || ''; const content = alert.content || ''; const row = ` ${serialNumber} ${warnType} ${warnTime} ${content} `; tbody.append(row); }); } // 更新图表 function updateCharts() { // 这里可以重新加载图表数据 // 实际应该从API获取数据并更新图表 if (temperatureHumidityChart) temperatureHumidityChart.resize(); if (windSpeedChart) windSpeedChart.resize(); if (noiseChart) noiseChart.resize(); if (airQualityChart) airQualityChart.resize(); }