hb_zhgd_screen/js/pages/dataAnalysisOctober/engineeringSafetyAnalysis.js

293 lines
12 KiB
JavaScript
Raw Normal View History

2025-10-18 15:55:58 +08:00
let table, layer, form, laydate;
2025-10-14 18:16:49 +08:00
let myChart = null, myChart2 = null;
2025-10-18 15:55:58 +08:00
layui.use(['layer', 'table', 'form', 'laydate'], function () {
2025-10-14 18:16:49 +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-14 18:16:49 +08:00
2025-10-18 15:55:58 +08:00
// 工程安全分析-一本账
initTable();
// 工程安全分析-球机列表
getBallSelect()
2025-10-14 18:16:49 +08:00
2025-10-18 15:55:58 +08:00
initTable2();
2025-10-14 18:16:49 +08:00
2025-10-18 15:55:58 +08:00
});
2025-10-14 18:16:49 +08:00
2025-10-18 15:55:58 +08:00
function initTable(startTime, endTime) {
const url = commonUrl + "screen/proSafety/selectProSafetyLedger";
2025-10-14 18:16:49 +08:00
table.render({
elem: '#demo1',
url: url,
id: 'demo1',
skin: 'line',
page: true,
height: 'full-505',
headers: {
"decrypt": "decrypt",
"Authorization": token
},
where: {
2025-10-18 15:55:58 +08:00
startTime: startTime,
endTime: endTime
2025-10-14 18:16:49 +08:00
},
cols: [[
{type: 'numbers', title: '序号', width: '10%'}, // 添加序号列
2025-10-18 15:55:58 +08:00
{field: 'riskCode', title: '风险编号', align: 'center', width: '15%'},
{field: 'riskSite', title: '作业部位', align: 'center', width: '15%'},
{field: 'riskLevel', title: '风险等级', align: 'center', width: '15%'},
{field: 'controller', title: '预控措施', align: 'center', width: '15%'},
{field: 'riskController', title: '风险控制关键因素', align: 'center', width: '20%'},
{field: 'startTime', title: '开始日期', align: 'center', width: '10%'},
2025-10-14 18:16:49 +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) {
2025-10-18 15:55:58 +08:00
2025-10-14 18:16:49 +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 = "";
}
initTable(startTime, endTime);
2025-10-14 18:16:49 +08:00
}
2025-10-18 15:55:58 +08:00
function getBallSelect() {
2025-10-14 18:16:49 +08:00
2025-10-18 15:55:58 +08:00
const url = commonUrl + "screen/proSafety/selectBallSelect"
ajaxRequestGet(
url,
"GET",
true,
function () {
2025-10-14 18:16:49 +08:00
},
2025-10-18 15:55:58 +08:00
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
);
2025-10-14 18:16:49 +08:00
2025-10-18 15:55:58 +08:00
/* 实时检测赋值 */
function setData(data) {
if (data) {
console.log(data)
const dynamicList = document.getElementById('dynamic-list');
dynamicList.innerHTML = ''; // 清空现有内容
2025-10-14 18:16:49 +08:00
2025-10-18 15:55:58 +08:00
data.forEach((item, index) => {
const listItem = document.createElement('li');
listItem.className = index === 0 ? 'layout check' : 'layout nocheck';
listItem.textContent = item.ballName;
listItem.onclick = function() {
changeDynamicData(this, index);
};
dynamicList.appendChild(listItem);
});
}
}
function changeDynamicData(element, index){
// 移除所有选中状态
const dynamicItems = document.querySelectorAll('#dynamic-list .layout');
dynamicItems.forEach(item => {
item.className = 'layout nocheck';
});
// 设置当前选中项
element.className = 'layout check';
// 显示选中项信息
const selectedItem = responseData.data[index];
const display = document.getElementById('selected-data');
let displayHTML = `
<div class="data-item"><strong>选中项:</strong> ${selectedItem.ballName}</div>
<div class="data-item"><strong>索引:</strong> ${index}</div>
`;
// 添加其他非空字段
Object.keys(selectedItem).forEach(key => {
if (selectedItem[key] !== null && key !== 'ballName') {
displayHTML += `<div class="data-item"><strong>${key}:</strong> ${selectedItem[key]}</div>`;
}
});
display.innerHTML = displayHTML;
}
// 页面加载完成后初始化
window.onload = function() {
// 默认选中第一个动态项
const firstDynamicItem = document.querySelector('#dynamic-list .layout');
if (firstDynamicItem) {
changeDynamicData(firstDynamicItem, 0);
}
};
}
function initTable2(startTime, endTime,ballName) {
const url = commonUrl + "screen/proSafety/selectProSafetyVideo";
2025-10-14 18:16:49 +08:00
// 获取数据
$.ajax({
url: url,
type: "get",
headers: {
"decrypt": "decrypt",
"Authorization": token
},
data: {
2025-10-18 15:55:58 +08:00
startTime:'2025-10-12',
endTime:'2025-10-17',
ballName:'测试球机',
2025-10-14 18:16:49 +08:00
page: '1',
limit: '10'
},
success: function (data) {
const container = document.getElementById('demo2-container');
container.innerHTML = ''; // 清空容器
if (data.data && data.data.length > 0) {
data.data.forEach(item => {
const card = document.createElement('div');
card.className = 'card';
2025-10-18 15:55:58 +08:00
card.style.cssText = ` width: calc(20% - 10px);height: 150px;background-color: #1a3a4c;border: none;border-radius: 8px;display: flex;flex-direction: column;overflow: hidden;`;
2025-10-14 18:16:49 +08:00
// 创建图片区域
const imgDiv = document.createElement('div');
2025-10-18 15:55:58 +08:00
imgDiv.style.cssText = ` flex: 1;background-color: #2a4a5c;display: flex;align-items: center;justify-content: center;color: #fff;font-size: 12px;`;
imgDiv.textContent = data.name;
2025-10-14 18:16:49 +08:00
card.appendChild(imgDiv);
// 创建信息区域
const infoDiv = document.createElement('div');
2025-10-18 15:55:58 +08:00
infoDiv.style.cssText = `padding: 5px;background-color: #1a3a4c;color: #fff;font-size: 12px;display: flex;justify-content: space-between;`;
2025-10-14 18:16:49 +08:00
const dateSpan = document.createElement('span');
2025-10-18 15:55:58 +08:00
dateSpan.textContent = item.createTime;
2025-10-14 18:16:49 +08:00
const statusSpan = document.createElement('span');
2025-10-18 15:55:58 +08:00
statusSpan.textContent = data.name;
2025-10-14 18:16:49 +08:00
infoDiv.appendChild(dateSpan);
infoDiv.appendChild(statusSpan);
card.appendChild(infoDiv);
container.appendChild(card);
});
// 添加 Layui 分页
2025-10-18 15:55:58 +08:00
layui.use('laypage', function () {
2025-10-14 18:16:49 +08:00
var laypage = layui.laypage;
laypage.render({
elem: 'demo2-pagination', // 分页容器ID
count: data.data.length, // 总条数
limit: 10, // 每页显示条数
curr: 1, // 当前页
2025-10-18 15:55:58 +08:00
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'], // 布局
2025-10-14 18:16:49 +08:00
prev: '<i class="layui-icon layui-icon-left"></i>', // 上一页图标
next: '<i class="layui-icon layui-icon-right"></i>', // 下一页图标
theme: '#3ACAB8', // 主题色
2025-10-18 15:55:58 +08:00
jump: function (obj, first) {
if (!first) { // 非首次触发
2025-10-14 18:16:49 +08:00
// 获取当前页码和每页条数
const currentPage = obj.curr;
const pageSize = obj.limit;
// 计算起始索引和结束索引
const startIndex = (currentPage - 1) * pageSize;
const endIndex = startIndex + pageSize;
// 重新获取数据这里需要根据实际API调整
$.ajax({
2025-10-18 15:55:58 +08:00
url: commonUrl + "screen/proSafety/selectProSafetyVideo",
2025-10-14 18:16:49 +08:00
type: "get",
headers: {
"decrypt": "decrypt",
"Authorization": token
},
data: {
2025-10-18 15:55:58 +08:00
startTime:startTime,
endTime:endTime,
ballName:ballName,
2025-10-14 18:16:49 +08:00
page: currentPage,
limit: pageSize
},
success: function (data) {
// 清空容器
const container = document.getElementById('demo2-container');
container.innerHTML = '';
// 渲染当前页的数据
if (data.data && data.data.length > 0) {
const pageData = data.data.slice(startIndex, endIndex);
pageData.forEach(item => {
const card = document.createElement('div');
card.className = 'card';
2025-10-18 15:55:58 +08:00
card.style.cssText = ` width: calc(20% - 10px);height: 150px;background-color: #1a3a4c;border: none;border-radius: 8px;display: flex;flex-direction: column;overflow: hidden;`;
2025-10-14 18:16:49 +08:00
// 创建图片区域
const imgDiv = document.createElement('div');
2025-10-18 15:55:58 +08:00
imgDiv.style.cssText = ` flex: 1;background-color: #2a4a5c;display: flex;align-items: center;justify-content: center;color: #fff;font-size: 12px;`;
2025-10-14 18:16:49 +08:00
imgDiv.textContent = '未带安全帽';
card.appendChild(imgDiv);
// 创建信息区域
const infoDiv = document.createElement('div');
2025-10-18 15:55:58 +08:00
infoDiv.style.cssText = ` padding: 5px;background-color: #1a3a4c;color: #fff;font-size: 12px;display: flex;justify-content: space-between;`;
2025-10-14 18:16:49 +08:00
const dateSpan = document.createElement('span');
dateSpan.textContent = item.date || 'XXX-XX-XX';
const statusSpan = document.createElement('span');
statusSpan.textContent = '未带安全帽';
infoDiv.appendChild(dateSpan);
infoDiv.appendChild(statusSpan);
card.appendChild(infoDiv);
container.appendChild(card);
});
}
}
});
}
}
});
});
}
}
});
}