';
}
// $("#div-body").attr("style","height: 615px;");
$("#thead").html(thead);
$("#recordList").html(tbody);
}
//页码渲染
function renderPageInfo(page, total) {
laypage.render({
elem: 'pdgxq-page',
count: total,
theme: '#e45163',
layout: ['prev', 'page', 'next', 'skip'],
curr: page,
limit: 10,
jump: function (obj, first) {
if (!first) {
page = obj.curr;
queryRecord(page);
}
}
});
}
//时间格式处理,20210226101010-----2021-02-26 10:10:10
function timeStr(time) {
return time.substring(0, 4) + "-" + time.substring(4, 6) + "-" + time.substring(6, 8) + " " + time.substring(8, 10) + ":" + time.substring(10, 12) + ":" + time.substring(12, 14)
}
/*------------------ tableToExcel导出模块-start ----------------- */
//导出Excel点击事件
function generateClick(){
var request = {};
request.id = $("#deviceId").val();
if(!request.id)
{
request.id = '0';
layer.msg("请选择设备进行查询!");
return ;
}
request.beginTime = $("#start").val().replace('-', '').replace('-', '');
if (request.beginTime) {
request.beginTime += '000000';
}
request.endTime = $("#end").val().replace('-', '').replace('-', '');
if (request.endTime) {
request.endTime += '235959';
}
request.page = page;
console.log(request);
var html = queryAllRecord(request);
// var record = {};
// var data = new Array();
//
// var maxI = 5;
// var maxJ = 9;
//
// for(var i=1;i<=maxI;i++){
// var param = {};
// param.id = "设备id";
// param.name = "设备名称";
// param.time = "20220217101523";
// var value = "";
// value += "[";
// if(i == 1){
// for(var j=1;j<=4;j++){
// value += "{'name':'名称" + j +"','value':'数据" + i + "" + j + "'}";
// if(j < 4){
// value += ",";
// }
// }
// }else if(i == 3){
// for(var j=1;j<=15;j++){
// value += "{'name':'名称" + j +"','value':'数据" + i + "" + j + "'}";
// if(j < 15){
// value += ",";
// }
// }
// }else if(i == 2){
// for(var j=1;j<=18;j++){
// value += "{'name':'名称" + j +"','value':'数据" + i + "" + j + "'}";
// if(j < 18){
// value += ",";
// }
// }
// }else if(i == 4){
// for(var j=1;j<=7;j++){
// value += "{'name':'名称" + j +"','value':'数据" + i + "" + j + "'}";
// if(j < 7){
// value += ",";
// }
// }
// }else{
// for(var j=1;j<=maxJ;j++){
// value += "{'name':'名称" + j +"','value':'数据" + i + "" + j + "'}";
// if(j < maxJ){
// value += ",";
// }
// }
// }
//
// value += "]";
// param.value = value;
// data.push(param);
// }
//
// record.total = 10;
// record.data = data;
// // console.log(record);
// var html = getTable(record.data);
// tableToExcel(html);
}
function queryAllRecord(request){
var html = "";
$.ajaxSettings.async = false;
$.post("./cgi-bin/record-his/excel-his", JSON.stringify(request), function (data, status) {
if ("success" == status) {
console.log(data.data);
//渲染历史数据列表
var html = getTable(data.data);
tableToExcel(html);
}else {
window.parent.notify("数据查询出错,请重新操作!");
}
}, "json");
return html;
}
function getTable(data) {
var thead = "";
thead += "
ID
";
thead += "
设备名称
";
thead += "
时间
";
var tbody = '';
var theadData = [];
if (data != null && data.length > 0) {
//获取表头
$.each(data, function (index, item) {
var tempData = eval(item.value);
if(theadData.length < tempData.length){
theadData = tempData;
}
});
console.log(theadData);
for(var i=0;i"+ theadData[i].name +"";
}
thead += "
";
$.each(data, function (index, item) {
tbody += "
" + item.id + "
";
tbody += "
" + item.name + "
";
tbody += "
" + timeStr(item.time) + "
";
var tempData = eval(item.value);
for (var i = 0; i < theadData.length; i++) {
if(i < tempData.length){
tbody += "
"+ tempData[i].value +"
";
}else {
tbody += "
";
}
// tbody += "
"+ tempData[i].value +"
";
}
tbody += "
";
});
} else {
thead += "
数据
";
tbody += '
暂未查到数据
';
}
var html = thead + tbody;
// console.log(html);
return html;
}
function tableToExcel(html) {
var name = "历史记录";
var uri = 'data:application/vnd.ms-excel;base64,';
var template = '
{table}
';
if(!html){
layer.msg("没有获取到要导出的内容!");
}
var ctx = {worksheet: name || 'Worksheet', table: html};
window.location.href = uri + base64(format(template, ctx))
}
function format(s, c) {
return s.replace(/{(\w+)}/g,function(m, p) { return c[p]; });
}
function base64(s) {
return window.btoa(unescape(encodeURIComponent(s)))
};
/*------------------ tableToExcel导出模块-end ----------------- */
function detail(key) {
var items = dataMap[key];
var html = "";
$.each(items, function (index, item) {
html +="
"+item.name+"
"+item.value+"
";
});
$("#tbody").html(html);
var paramWH = getWH("detail");
layer.open({
skin: 'mypop',
type: 1,
title: false,
// area: ['40%', '65%'],
area: [paramWH.w, paramWH.h],
closeBtn: 0,
shade: 0,
scrollbar: false,
content: $('#editWarnDom')
});
}
function closepopBtn(){
layer.closeAll();
$("#tbody").html("");
}
function getWH(tag) {
var res = {
w:"50%",
h:"64%"
};
if(screen.width==1920 && screen.height==1080){
res = {w:"80%",h:"64%"};
if(tag == "batchHandle"){
res = {w:"80%",h:"64%"};
}
}else if(screen.width==1280 && screen.height==1024){
res = {w:"80%",h:"64%"};
if(tag == "detail"){
res = {w:"80%",h:"95%"};
}
if(tag == "batchHandle"){
res = {w:"80%",h:"64%"};
}
}else if(screen.width==1280 && screen.height==800){
res = {w:"80%",h:"64%"};
if(tag == "detail"){
res = {w:"80%",h:"95%"};
}
if(tag == "batchHandle"){
res = {w:"80%",h:"64%"};
}
}
return res;
}
function getWHNum() {
var res = 5;
if(screen.width==1920){
res = 5;
}else if(screen.width==1280){
res = 1;
}
return res;
}