//初始化设备监控菜单获取所有的设备列表 var testList = [ {"id": "1", "name": "温湿度#1", "type": "2001", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "2", "name": "门禁#1", "type": "3001", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "3", "name": "烟感#1", "type": "3002", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "32", "name": "烟感#2", "type": "3002", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "33", "name": "烟感#3", "type": "3002", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "4", "name": "漏水#1", "type": "2005", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "42", "name": "漏水#2", "type": "2005", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "43", "name": "漏水#3", "type": "2005", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "5", "name": "红外#1", "type": "3003", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "52", "name": "红外#2", "type": "3003", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "53", "name": "红外#3", "type": "3003", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "6", "name": "配电#1", "type": "1004", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "7", "name": "电表#1", "type": "1003", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "8", "name": "精密空调#1", "type": "2002", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "9", "name": "UPS#1", "type": "1001", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "10", "name": "UPS#2", "type": "1002", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "11", "name": "电池组#1", "type": "1005", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "12", "name": "普通空调#1", "type": "2003", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "13", "name": "温感#1", "type": "3008", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "14", "name": "视频", "type": "3004", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "15", "name": "消防#1", "type": "3012", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "16", "name": "防雷#1", "type": "3013", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "17", "name": "PDU#1", "type": "1010", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "18", "name": "新风机#1", "type": "2004", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "19", "name": "照明开关", "type": "3014", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "20", "name": "灭火器#1", "type": "3015", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, {"id": "21", "name": "灭火器#2", "type": "3015", "port": "1", "address": "1", "libname": "abc", "libnamezh": "测试", "vld": "0"}, ]; var sysset = {"name":"机房监控管理 V3.0","opVendor":"运维厂商","opPhone":"180","contacter":"","usedTime":"","menu3DVld":"1"}; //检测授权是否过期 var timerFlush; var devAllWarn = false; window.LIST_DEVICE = []; window.SYS_SET = {}; var deviceMap = []; if (TEST_TAG) { //初始化菜单 LIST_DEVICE = testList; //初始化运维信息 // SYS_SET=sysset; // // $("#menu3DVld").hide(); // if(sysset.menu3DVld == 1){ // $("#menu3DVld").show(); // } renderMenu(); } else { //初始化菜单 initMenu(); //初始化获取系统配置 initSysSet(); //获取logo queryLogo(); //检测授权是否过期 empowerVerify(); openUrl(); } $(document).ready(function () { checkLogin(); }); //初始化菜单 function initMenu() { $.ajaxSettings.async = false; $.get("./cgi-bin/device/query-all", function (data, status) { if ("success" == status) { window.LIST_DEVICE = data; renderMenu(); // getDeviceWarn(); } else { window.parent.notify("系统获取监控设备信息失败!"); } }, "json"); }; //初始化获取系统配置 function initSysSet() { $.ajaxSettings.async = false; $.get("./cgi-bin/sys-set/query-info", function (data, status) { if ("success" == status) { window.SYS_SET = data; //系统名称 // $("#sys-name").text(window.SYS_SET.name); // $("#menu3DVld").hide(); if(window.SYS_SET.menu3DVld == 1){ $("#menu3DVld").show(); } if(window.SYS_SET.linkage == "1"){ $("#linkage").show(); } } else { window.parent.notify("系统获取系统配置信息失败!"); } }, "json"); }; //菜单渲染-设备监控菜单 function renderMenu() { if (window.LIST_DEVICE.length == 0) { return; } var list = []; $.each(LIST_DEVICE, function (index, data) { if(data.vld == "0"){ list.push(data); } deviceMap[data.id] = data; }); var parentEle = $("#menu-device"); var tag_yg = true, tag_ls = true, tag_hw = true, tag_wg = true, tag_sp = true, tag_xf = true, tag_fl = true, tag_mhq = true; $.each(list, function (index, data) { if ("2001" == data.type) {//温湿度 parentEle.append("
" + msg + "
"; layer.open({ id: 'id_sys_notify', title: "通知", offset: 'auto', icon: 1, anim: 2, content: msg }); }; /** * 从设备列表中获取设备基本信息 * @param id */ window.getDevice = function (deviceId) { var data = null; $.each(LIST_DEVICE, function (index, item) { if (item.id == deviceId) { data = item; return false; } }); return data; }; /** * 根据设备类型从设备列表中获取所有设备信息 * @param id */ window.getDeviceByType = function (type) { var list = new Array(); $.each(LIST_DEVICE, function (index, data) { if (data.type == type) { list.push(data); } }); return list; }; /** * 根据设备类型从设备列表中获取所有设备信息 * @param id */ window.getRegisterinfo = function () { $.ajaxSettings.async = false; $.get("./cgi-bin/register/query_register", function (data, status) { if ("success" == data.code) { if(data.msg < 1){ out(); } } else { window.parent.notify("获取授权信息出错,请重新操作!!"); } }, "json"); }; //每个小时检测一次授权是否过期 function empowerVerify() { if(timerFlush){ clearInterval(timerFlush); } //每个小时检测一次授权是否过期 timerFlush = setInterval(function() { getRegisterinfo(); }, 60 * 60 * 1000); }; // test001(); // function test001() { // var arr = ["1","1","1","1","1"]; // $.each(arr, function (index, item) { // console.log(index); // }); // // console.log("================ces============================="); // var msg = "金桥2楼漏水报警,尊敬的用户,您的设备金桥-2楼-A排机柜漏水于2023-06-29 11:37:12触发金桥2楼漏水报警,请及时处理。触发原因:出现漏水。"; // var param = {"actionCode":"30","content":msg,"repeat":"1"}; // $.post("http://127.0.0.1:8101/radio",JSON.stringify(param), function (result) { // // }, "json"); // } function openUrl() { //获取URL中的参数id var deviceId = getParam("id"); if(!deviceId){ return; } var cur = deviceMap[deviceId]; var name = cur.name; var str = "detail-ty.html?id=" + cur.id; if ("2001" == cur.type) {//温湿度 str = "detail-wsd.html?id=" + cur.id; } if ("3001" == cur.type) {//门禁 str = "detail-mj.html?id=" + cur.id; } if ("3002" == cur.type) {//烟感 str = "detail-yg.html?id=999&type=" + cur.type; } if ("2005" == cur.type) {//漏水 str = "detail-ls.html?id=999&type=" + cur.type; } if ("3003" == cur.type) {//紅外 str = "detail-hw.html?id=999&type=" + cur.type; } if ("3008" == cur.type) {//温感 str = "detail-wg.html?id=999&type=" + cur.type; } if ("3012" == cur.type) {//消防开关量 str = "detail-xf.html?id=999&type=" + cur.type; } if ("3013" == cur.type) {//防雷开关量 str = "detail-fl.html?id=999&type=" + cur.type; } if ("3004" == cur.type) {//视频 str = "detail-video.html?id=999&type=" + cur.type; } if ("1004" == cur.type) {//配电 str = "detail-pd.html?id=" + cur.id; } if ("1003" == cur.type) {//电表 str = "detail-pd.html?id=" + cur.id; } if ("2002" == cur.type || "20021" == cur.type || "20022" == cur.type ) {//精密空调 str = "detail-jmkt.html?id=" + cur.id; } if ("1001" == cur.type) {//UPS str = "detail-ups.html?id=" + cur.id; } if ("1002" == cur.type) {//UPS str = "detail-ups.html?id=" + cur.id; } if ("1005" == cur.type) {//电池组 str = "detail-dcz.html?id=" + cur.id; } if ("1010" == cur.type) {//PDU str = "detail-pdu.html?id=" + cur.id; } if ("2004" == cur.type) {//新风机 str = "detail-xfj.html?id=" + cur.id; } if ("3014" == cur.type){ str = "detail-zmkg.html?id=" + cur.id; } // var hostname = window.location.hostname; // var url = "http://"+hostname+"/" + str; $("#J_menuTab_name").text(name); $("#iframe0").attr("src",str); } /** * 获取URL中的参数 * @param name * @returns {string|null} */ function getParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } function getDeviceWarn() { if(window.LIST_DEVICE != null && window.LIST_DEVICE.length > 0){ var index = 0; var list = []; var listLs = []; var listYg = []; var listHw = []; var listWg = []; var listXf = []; var listFl = []; $.each(window.LIST_DEVICE,function (index,item) { if(item.type == "2005"){ listLs.push(item); } else if(item.type == "3002"){ listYg.push(item); } else if(item.type == "3003"){ listHw.push(item); } else if(item.type == "3008"){ listWg.push(item); } else if(item.type == "3012"){ listXf.push(item); } else if(item.type == "3013"){ listFl.push(item); } else if(item.type == "3004"){ //视频设备不做统计 } else{ list.push(item); } }); //定时器,每0.2秒查询一次;查询设备信息并渲染 setInterval(function () { if(index >= list.length){ index = 0; } var item = list[index]; var id = item.id; var type = item.type; getDevData(id,type); index++; },300); //定时器,每3秒查询一次;查询设备信息并渲染 setInterval(function () { if(listLs != null && listLs.length > 0){ getDevDatas(listLs,"2005") } if(listYg != null && listYg.length > 0){ getDevDatas(listYg,"3002") } if(listHw != null && listHw.length > 0){ getDevDatas(listHw,"3003") } if(listWg != null && listWg.length > 0){ getDevDatas(listWg,"3008") } if(listXf != null && listXf.length > 0){ getDevDatas(listXf,"3012") } if(listFl != null && listFl.length > 0){ getDevDatas(listFl,"3013") } },3000); } } function getDevData(id,type) { var data = {"id": id}; $.post("./cgi-bin/detail/query-data", JSON.stringify(data), function (data, status) { if ("success" == status) { renderDeviceWarn(data,type); } }, "json"); } function getDevDatas(list,type) { var warnTag = false; $.ajaxSettings.async = false; //遍历同类型设备集合,根据id查询数据后保存 for (var i = 0; i < list.length; i++) { if(warnTag){ break; } $.post("./cgi-bin/detail/query-data", JSON.stringify({id: list[i].id}), function (data, status) { if ("success" == status) { var values = data.value; for (var i = 1; i <= values.length; i++) { var cur = values[i - 1]; if(warnTag){ break; }else{ if(cur.passcode == 1 || cur.passcode == 2){ if(cur.value==1){ warnTag = true; } } } } } }, "json"); } var id = ""; if(type == "2005"){ id = "ls"; } else if(type == "3002"){ id = "yg"; } else if(type == "3003"){ id = "hw"; } else if(type == "3008"){ id = "wg"; } else if(type == "3012"){ id = "xf"; } else if(type == "3013"){ id = "fl"; } else{ //视频设备不做统计 return; } renderDivWarn(id,warnTag); } function renderDeviceWarn(data,type) { //实时数据 var id = data.id; var list = data.value; var warnTag = false; //报警状态 for (var i = 1; i <= list.length; i++) { var cur = list[i - 1]; if(warnTag){ break; }else{ if(cur.passcode == 1 || cur.passcode == 2){ if(cur.value==1){ warnTag = true; } } } } renderDivWarn(id,warnTag) } function renderDivWarn(id,warn) { if(warn){ $("#"+id).addClass("warn"); }else{ $("#"+id).removeClass("warn"); } }