let pageNum2 = 1, limitSize2 = 10; let tableName = '', pageName = ''; function pages2(pageNum, pageSize, typeNum) { let params = getReqParams2(pageNum, pageSize, typeNum); let url = dataUrl + "proteam/pot/todayTask/getTodayTaskList?token=" + token; if (tableName === 'resource-table') { // 资源监测通知-设备状态监测 url = dataUrl + "proteam/pot/resourceMonitor/getDeviceStatusMonitorList?token=" + token; } else if (tableName === 'video-table') { url = dataUrl + "proteam/pot/video/getVideoDiagnosis?token=" + token; } else if (tableName === 'alarm-table') { // 资源监测通知-服务器状态监测 url = dataUrl + "proteam/pot/resourceMonitor/getAlarmRecordList?token=" + token; } $.ajax({ headers: { "encrypt": sm3(JSON.stringify(params)) }, url: url, data: params, type: 'POST', async: false, success: function (result) { if (result.code === 200) { if (result.data) { initTable2(result.data, result.limit, result.curr) laypages2(result.count, result.curr, result.limit) } } else if (result.code === 500) { layer.alert(result.msg, {icon: 2}) } else if (result.code === 401) { logout(1); } }, error: function () { } }); } function laypages2(total, page, limit) { layui.use(['laypage'], function () { let laypage = layui.laypage; laypage.render({ elem: pageName, count: total, curr: page, limit: limit, limits: [10, 20, 50, 100, 200, 500], layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'], groups: 5, jump: function (obj, first) { if (!first) { pageNum2 = obj.curr, limitSize2 = obj.limit; pages2(obj.curr, obj.limit, null); } } }); }) } /*初始化表格*/ function initTable2(dataList, limit, page) { let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0,}); tableIns = table.render({ elem: "#" + tableName, height: "full-150", data: dataList, cols: [getCols(dataList, limit, page)], limit: limit, done: function (res, curr, count) { layer.close(loadingMsg); table.resize(tableName); }, }); } // 设置表格内容 function getCols(dataList, limit, page) { let cols = []; if (tableName === 'resource-table') { cols = [ //表头 { title: "序号", width: 100, unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } }, { field: "proName", title: "工程名称", unresize: false, align: "center", }, { field: "teamLeader", title: "班组长", unresize: false, align: "center", }, { field: "abnormalType", title: "异常类型", unresize: false, align: "center", }, { field: "createDate", title: "日期", unresize: false, align: "center", }, ]; } else if (tableName === 'alarm-table') { cols = [ //表头 { title: "序号", width: 100, unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } }, { field: "alarmType", title: "告警类型", sort: true, unresize: false, align: "center", }, { field: "proName", title: "工程名称", unresize: false, sort: true, align: "center", }, { field: "teamLeader", title: "班组长", unresize: false, sort: true, align: "center", }, { field: "abnormalType", title: "异常类型", unresize: false, sort: true, align: "center", }, { field: "createDate", title: "日期", unresize: false, sort: true, align: "center", }, ]; } else if (tableName === 'video-table') { cols = [ //表头 { title: "序号", width: 100, unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } }, { field: "proName", title: "工程名称", sort: true, unresize: false, align: "center", }, { field: "teamLeader", title: "班组长", unresize: false, sort: true, align: "center", }, { field: "abnormalDetail", title: "异常明细", unresize: false, sort: true, align: "center", }, { field: "createDate", title: "日期", unresize: false, sort: true, align: "center", }, { title: "操作", width: 200, unresize: true, align: "center", templet: function (d) { let html = ''; html += "修改" + "
|
删除"; return html; } } ]; } return cols; } // 获取参数 function getReqParams2(page, limit, type) { let obj = {}; // 设备网络监测 if (tableName === 'resource-table') { if (!type) { obj = { page: page + "", limit: limit + "", keyWord: $('#keyWord').val(), createDate: $('#workDay').val() }; } else { obj = { page: '1', limit: '10', keyWord: '', createDate: getNowTime() }; } } else if (tableName === 'alarm-table') { // if (!type) { obj = { page: page + "", limit: limit + "", keyWord: $('#keyWord6').val(), alarmType: $('#alarmType').val(), createDate: $('#workDay6').val() }; } else { obj = { page: '1', limit: '10', keyWord: '', alarmType: '', createDate: getNowTime() }; } } else if (tableName === 'video-table') { if (!type) { obj = { page: page + "", limit: limit + "", keyWord: $('#keyWord5').val(), createDate: $('#workDay5').val() }; } else { obj = { page: '1', limit: '10', keyWord: '', createDate: getNowTime() }; } } return obj; } // 查询/重置 function query(type) { let pattern = new RegExp("[%_<>]"); if (pattern.test($("#keyWord").val())) { $("#keyWord").val(''); return layer.msg('关键字查询包含特殊字符,请重新输入', { icon: 2, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); } pages2(1, limitSize2); } // 设置设备状态监测新增按钮 function setBtns() { let html = ''; if (user.nickName === '!jysp' || user.nickName === 'jysp') { html += '' } $('#btn-box button:not(:first)').remove(); $('#btn-box').append(html); } // 添加设备状态页面 function addResourceData() { let layerIndex = layer.open({ id: "addResourceData", title: ['
新增设备状态
', 'font-size:16px;background-color:#f0f0f0;display: flex;align-items: center;'], type: 2, maxmin: false, content: 'resourceForm.html', area: ['700px', '480px'], move: false, success: function (layero, index) { } }); } // 添加设备状态页面 function addVideoData(id) { let title = '新增视频诊断'; if(id){ title = '编辑视频诊断' } let layerIndex = layer.open({ id: "addVideoData", title: ['
'+title+'
', 'font-size:16px;background-color:#f0f0f0;display: flex;align-items: center;'], type: 2, maxmin: false, content: 'videoForm.html', area: ['700px', '480px'], move: false, success: function (layero, index) { let iframeWin = window["layui-layer-iframe" + layerIndex]; iframeWin.setParams(id); }, }); } // 刷新页面数据 function reloadData2() { pages2(pageNum2, limitSize2); } // 设置网络状态 function setInternetStatus() { var imgPath = "https://www.baidu.com/img/bd_logo1.png"; var timeStamp = Date.parse(new Date()); $("#img-test").attr("src", imgPath + "?timestamp=" + timeStamp); } function getImgSuccess() { let isOline = $("#img-test").attr("isOline"); if (isOline === "1") { $("#img-test").attr("src", "../../img/success.png"); $("#p-test").html("网络连接正常"); $("#p-div").removeAttr("style"); } } function getImgError() { $("#img-test").attr("isOline", "0").attr("src", "../../img/error.png"); $("#p-test").html("无法连接到网络,请检查后重试"); $("#p-div").removeAttr("style"); } function setHidden() { $('#p-div').css('display', 'none'); $("#img-test").removeAttr('src'); $("#p-test").empty(); } // 切换页面 function choosePage(that, type, value, value2) { $('.content_left ul li').each(function () { $(this).removeClass('checkBtn').addClass('unCheckBtn') }) $(that).removeClass('unCheckBtn').addClass('checkBtn') setHidden(); if (type !== 5) { $('#content-box').css('display', 'none'); $('#content-box2').removeAttr('style'); if (type === 2) { $('#zyjc').removeAttr('style') $('#spzd').css('display', 'none') $('#gjjl').css('display', 'none') setBtns(); // 默认选择设备状态监测 $('.ul-menu ul li').each(function () { $(this).removeClass('check-li'); }) $('.ul-menu ul li').eq(0).addClass('check-li') $('.zyjc-child').each(function () { $(this).css('display', 'none') }) $('#sbztjc').removeAttr('style'); tableName = 'resource-table', pageName = 'voi-page2'; $('#keyWord').val('') $('#workDay').val(getNowTime()) pages2(1, 10, 1); } else if (type === 3) { $('#spzd').removeAttr('style') $('#zyjc').css('display', 'none') $('#gjjl').css('display', 'none') $('#keyWord5').val('') $('#workDay5').val(getNowTime()) tableName = value, pageName = value2; pages2(1, 10, 1); } else if (type === 4) { $('#gjjl').removeAttr('style') $('#zyjc').css('display', 'none') $('#spzd').css('display', 'none') $('#keyWord6').val('') $('#workDay6').val(getNowTime()) $('#alarmType').val('') layui.form.render(); tableName = value, pageName = value2; pages2(1, 10, 1); } } else { $('#content-box').removeAttr('style'); $('#content-box2').css('display', 'none'); } } // 资源监测通知-切换页面 function checkChild(that, type, value, value2) { $('.ul-menu ul li').each(function () { $(this).removeClass('check-li'); }) $(that).addClass('check-li') emptyServerData(); pageNum2 = 1; limitSize2 = 10; tableName = value; pageName = value2; if (type === 1) { $('#keyWord').val('') $('#workDay').val(getNowTime()) $('#sbztjc').removeAttr('style'); $('#wlztjc').css('display', 'none'); $('#fwqztjc').css('display', 'none'); setHidden(); pages2(1, 10, 1); } else if (type === 2) { $('#sbztjc').css('display', 'none'); $('#wlztjc').removeAttr('style'); $('#fwqztjc').css('display', 'none'); setInternetStatus(); } else if (type === 3) { $('#sbztjc').css('display', 'none'); $('#wlztjc').css('display', 'none'); $('#fwqztjc').removeAttr('style'); setHidden(); getServerData(); } } // 服务器状态监测赋值 function setServerData(data) { if (data) { data.forEach(function (item, index) { $('.val').eq(index).html(item) }) } } // 服务器状态监测清空赋值 function emptyServerData(data) { for (let i = 0; i < 12; i++) { $('.val').eq(i).html('') } } // 导出数据 function exportData() { let alarmType = $('#alarmType').val(), keyWord = $('#keyWord6').val(), createDate = $('#workDay6').val(); let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,}); let url = dataUrl + "proteam/pot/resourceMonitor/exportData?alarmType=" + alarmType + "&keyWord=" + keyWord + "&createDate=" + createDate + "&token=" + token; let xhr = new XMLHttpRequest(); xhr.open("get", url, true); xhr.responseType = "blob"; // 转换流 xhr.setRequestHeader("encrypt", sm3(JSON.stringify({ alarmType: alarmType, keyWord: keyWord, createDate: createDate }))); xhr.onload = function () { layer.close(loadingMsg); if (this.status === 200) { let blob = this.response; var a = document.createElement("a"); var url = window.URL.createObjectURL(blob); a.href = url; a.download = "告警记录" + getNowDate() + ".xlsx"; // 文件名 } else { layer.msg("数据发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000}); } a.click(); window.URL.revokeObjectURL(url); }; xhr.send(); }