var layer;// 定义全局变量 var isShow = false; var default_top = 20;//默认上偏移 var default_left = 0;//默认左偏移 var listDevice; var deviceMap=[]; //定时轮询时间5s var INTERVAL = 5 * 1000; var intervalData; //定制, var thId1 = "-999"; var thId2 = "-999"; var thData1; var thData2; var imgData = {}; var testList = [ { "id":"2211", "name":"温湿度#1", "category":"3004", "type":"0", "leftV":"0.4040", "topV":"0.2515", "value":[{ "passcode":"2", "name":"温度", "value":"1" },{ "passcode":"3", "name":"温度", "value":"18" },{ "passcode":"4", "name":"湿度", "value":"60" }] },{ "id":"2221", "name":"温湿度#1", "category":"2002", "type":"0", "leftV":"0.4840", "topV":"0.2015", "value":[{ "passcode":"3", "name":"温度", "value":"18" },{ "passcode":"4", "name":"湿度", "value":"60" }] },{ "id":"3331", "name":"精密空调#1", "category":"2002", "type":"0", "leftV":"0.6840", "topV":"0.5015", "value":[{ "passcode":"1", "name":"温度", "value":"1" },{ "passcode":"2", "name":"温度", "value":"1" },{ "passcode":"3", "name":"湿度", "value":"60" }] }]; $(function () { layui.use(['layer'], function () { layer = layui.layer; }); window.onload = function () { if(TEST_TAG){ listDevice = testList; renderTips(listDevice); }else{ //初始页面 initImg(); //初始化数据 loadDevice(); //开始模块的自我循环数据 reLoadModelDataRecord(); } } }); function closepopBtn(){ layer.closeAll(); } // 循环执行页面数据的刷新 function reLoadModelDataRecord(){ // 首先停止执行原有的循环 if (intervalData) clearInterval(intervalData); intervalData = setInterval(function () { //监控信息渲染 loadDevice(); }, INTERVAL); } //获取2.5D图 function initImg() { $.ajaxSettings.async = false; $.get("./cgi-bin/img-data/query", function (data, status) { if ("success" == status) { // console.log("-------获取2.5D图接收的数据------"); // console.log(data); imgData = data.data; renderImg(); } else { window.parent.notify("系统获取2.5D图信息失败!"); } }, "json"); } //点击右侧操作按钮 function showEdit() { if (isShow) { $('.btn-edit').addClass('hide'); } else { $('.btn-edit').removeClass('hide'); } isShow = !isShow; }; function renderImg() { var bodyH = $(document.body).height(); var imgMin = $("#img-main"); var top = imgMin.offset().top; var imgHei = bodyH - top - default_top; imgMin.height(imgHei); //console.log(imgData); //调整展示图片地址 if(imgData){ $("#img-three").attr('src', imgData); } $("#img-three").css("height", imgHei); // $("#img-three").css("width", "100%"); $("#img-three").show(); }; //获取设备列表,渲染显示设备信息 function loadDevice() { $.ajaxSettings.async = false; $.get("./cgi-bin/detail/query-all", function (data, status) { if ("success" == status) { // console.log("-------获取设备列表接收的数据------"); // console.log(data); listDevice = data; renderTips(listDevice) } else { window.parent.notify("系统获取系统配置信息失败!"); } }, "json"); }; //开始渲染信息 function renderTips(listDevice) { //console.log(listDevice); var parent = $("#img-main"); var parentWidth = parent.width(); var parentHeight = parent.height(); var left = 50, top = 50; var temp; var id; var tagValue; var category; var recordMap; var warnState = 0; var i; var name; var warnStr = " warn-div "; // console.log("=========所有设备信息========="); // console.log(listDevice); $.each(listDevice, function (index, device) { i = index; left = (parentWidth * device.leftV).toFixed(4); top = (parentHeight * device.topV).toFixed(4); category = device.category;//设备类型 id = device.id;//设备ID name = device.name; if(category != CATEGORY.D3009.code){ if(id && category){ if(category != CATEGORY.D2090.code && category != CATEGORY.D2091.code){ recordMap = device.value;//设备监控属性集合 warnState = device.type; tagValue = addCurData(category, recordMap, warnState,device); warnState = tagValue.warnState; if(warnState == 0){ warnStr = ""; }else{ warnStr = " warn-div "; } temp = ""; if(device.id == thId1 || device.id == thId2){ if(device.id == thId1){ thData1 = device; }else{ thData2 = device; } temp += ""; }else{ if ("FULL" == tagValue.code) { temp += "
"; temp += "
"; temp += addCurImg(category,warnState); temp += "
"; temp += tagValue.htm; // temp += "
"; // temp += ""; // temp += name; // temp += ""; // temp += "
"; temp += "
"; } else { temp += "
"; temp += "
"; temp += addCurImg(category,warnState); temp += "
"; temp += tagValue.htm; // temp += "
"; // temp += ""; // temp += name; // temp += ""; // temp += "
"; temp += "
"; } // temp += "
"; // temp += addCurImg(category); // temp += "
"; // temp += tagValue.htm; // temp += ""; } // if(category == CATEGORY.D3001.code){ // console.log("=========门禁设备=========设备信息:"); // console.log(device); // } // if(device.id != "1001" && device.id != "1002"){ // //删除原有元素,在进行追加 // $("#"+device.id).remove(); // parent.append(temp); // // } //删除原有元素,在进行追加 $("#"+device.id).remove(); parent.append(temp); } }else{ console.log("=========没有获取到该设备的设备id(类型)=========设备信息:"); console.log(device); } } }); // if(thData1 && thData2){ // addhtml(parent,i); // } //添加图标的事件 $(".tip").click(function () { var id = $(this).attr("id"); var name = $(this).attr("name"); layer.msg("当前设备:" + name); }); //添加图标的事件 $(".tip").dblclick(function () { var deviceId = $(this).attr("id"); var name = $(this).attr("name"); var category = $(this).attr("category"); var url = ""; url = "./detail-ty.html?id="+deviceId+"&type="+category; if (category == CATEGORY.D2001.code) { url = "./detail-wsd.html?id="+deviceId+"&type=" + category; } if (category == CATEGORY.D3001.code) { url = "./detail-mj.html?id="+deviceId+"&type=" + category; } if (category == CATEGORY.D1004.code || category == CATEGORY.D1003.code) { url = "./detail-pd.html?id="+deviceId+"&type=" + category; } if (category == CATEGORY.D1001.code || category == CATEGORY.D1002.code) { url = "./detail-ups.html?id="+deviceId+"&type=" + category; } if (category == CATEGORY.D2002.code) { url = "./detail-jmkt.html?id="+deviceId+"&type=" + category; } if (category == CATEGORY.D1005.code) { url = "./detail-dcz.html?id="+deviceId+"&type=" + category; } //红外 if (category == CATEGORY.D3003.code) { url = "./detail-hw.html?id=999&type=" + category; name = "红外"; } //漏水 if (category == CATEGORY.D2005.code) { url = "./detail-ls.html?id=999&type=" + category; name = "漏水"; } //烟感 if (category == CATEGORY.D3002.code) { url = "./detail-yg.html?id=999&type=" + category; name = "烟感"; } if (category == CATEGORY.D3008.code) { url = "./detail-wg.html?id=999&type=" + category; name = "温感"; } if (category == CATEGORY.D3004.code) { url = "./detail-video.html?id=999&type=" + category; name = "视频"; // var html = ''; // html += '