| | |
| | | var form = layui.form; |
| | | var admin = layui.admin; |
| | | |
| | | // 颜色判断函数 |
| | | function applyColorStyles() { |
| | | // 使用更精确的选择器 |
| | | $('.layui-table-box .layui-table-body table tbody tr').each(function() { |
| | | var $tr = $(this); |
| | | // 跳过表头行 |
| | | if ($tr.hasClass('layui-table-header') || $tr.find('td').length === 0) return; |
| | | |
| | | var $tempCell = $tr.find('td').eq(3); // 第3列:温度 |
| | | var $humiCell = $tr.find('td').eq(4); // 第4列:湿度 |
| | | |
| | | if ($tempCell.length && $humiCell.length) { |
| | | var tempText = $tempCell.text().trim(); |
| | | var humiText = $humiCell.text().trim(); |
| | | |
| | | // console.log('温度:', tempText, '湿度:', humiText); // 调试用 |
| | | |
| | | // 重置样式 |
| | | $tempCell.css({ |
| | | 'background-color': '', |
| | | 'color': '', |
| | | 'font-weight': '' |
| | | }); |
| | | $humiCell.css({ |
| | | 'background-color': '', |
| | | 'color': '', |
| | | 'font-weight': '' |
| | | }); |
| | | |
| | | // 温度判断 |
| | | if (tempText) { |
| | | var temp = parseFloat(tempText); |
| | | if (!isNaN(temp)) { |
| | | if (temp > 25 || temp < 15) { |
| | | $tempCell.css({ |
| | | 'background-color': 'red', |
| | | 'color': 'white', |
| | | 'font-weight': 'bold' |
| | | }); |
| | | // console.log('温度超出范围:', temp); // 调试用 |
| | | }else { |
| | | $tempCell.css({ |
| | | 'background-color': 'green', |
| | | 'color': 'white', |
| | | 'font-weight': 'bold' |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 湿度判断 |
| | | if (humiText) { |
| | | var humi = parseFloat(humiText); |
| | | if (!isNaN(humi)) { |
| | | if (humi > 60) { |
| | | $humiCell.css({ |
| | | 'background-color': 'red', |
| | | 'color': 'white', |
| | | 'font-weight': 'bold' |
| | | }); |
| | | // console.log('湿度超出范围:', humi); // 调试用 |
| | | }else { |
| | | $humiCell.css({ |
| | | 'background-color': 'green', |
| | | 'color': 'white', |
| | | 'font-weight': 'bold' |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 数据渲染 |
| | | var timer = setInterval(function () { |
| | | var timer = setInterval(function () { |
| | | tableIns = table.render({ |
| | | elem: '#basSensor', |
| | | headers: {token: localStorage.getItem('token')}, |
| | |
| | | ,{field: 'location', align: 'center',title: '传感器位置'} |
| | | ,{field: 'temperature', align: 'center',title: '传感器温度(°c)'} |
| | | ,{field: 'humidity', align: 'center',title: '传感器湿度(%)'} |
| | | // ,{field: 'createTime', align: 'center',title: '创建时间'} |
| | | |
| | | // ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120} |
| | | ]], |
| | | request: { |
| | | pageName: 'curr', |
| | |
| | | } |
| | | pageCurr=curr; |
| | | limit(); |
| | | |
| | | // 应用颜色样式 - 使用多个setTimeout确保DOM完全渲染 |
| | | setTimeout(function() { |
| | | setTimeout(function() { |
| | | applyColorStyles(); |
| | | }, 200); |
| | | }, 100); |
| | | } |
| | | }); |
| | | },1000); |
| | | // clearInterval(timer); |
| | | },3000); |
| | | |
| | | // 监听排序事件 |
| | | table.on('sort(basSensor)', function (obj) { |
| | |
| | | showEditModel(); |
| | | break; |
| | | case 'deleteData': |
| | | if (checkStatus.length === 0) { |
| | | layer.msg('请选择要删除的数据', {icon: 2}); |
| | | return; |
| | | } |
| | | del(checkStatus.map(function (d) { |
| | | return d.id; |
| | | })); |
| | | break; |
| | | if (checkStatus.length === 0) { |
| | | layer.msg('请选择要删除的数据', {icon: 2}); |
| | | return; |
| | | } |
| | | del(checkStatus.map(function (d) { |
| | | return d.id; |
| | | })); |
| | | break; |
| | | case 'exportData': |
| | | admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){ |
| | | var titles=[]; |
| | |
| | | form.on('submit(search)', function (data) { |
| | | pageCurr = 1; |
| | | tableReload(false); |
| | | // 搜索后重新应用样式 |
| | | setTimeout(applyColorStyles, 500); |
| | | }); |
| | | |
| | | // 重置 |
| | |
| | | pageCurr = 1; |
| | | clearFormVal($('#search-box')); |
| | | tableReload(false); |
| | | // 重置后重新应用样式 |
| | | setTimeout(applyColorStyles, 500); |
| | | }); |
| | | |
| | | // 时间选择器 |
| | |
| | | ,type: 'datetime' |
| | | ,range: true |
| | | }); |
| | | |
| | | }, 300); |
| | | } |
| | | layDateRender(); |
| | |
| | | tableIns.reload({ |
| | | where: searchData, |
| | | page: {curr: pageCurr} |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | // let timer = setInterval(function () { |
| | | // $(".layui-laypage-btn")[0].click(); |
| | | // },1000); |
| | | clearInterval(timer); |
| | | clearInterval(timer); |