var layer; var testList = [ {"id":"1","name":"测试视频#1","type":"3004","type0":"0","username":"admin","pwd":"a1234567","ipIn":"192.168.0.200","portInC":"554","portInV":"80","ipOut":"192.168.0.123","portOutC":"0","portOutV":"0","chanNum":"1","chanNumOut":"1","brand":"测试品牌","vld":"0","address":"地址","mediaAddr":"rtsp://{username}:{pwd}@{ip}:{port}/MPEG-4/ch1/sub/av_stream","webUrl":"webUrl"}, {"id":"2","name":"测试视频#2","type":"3004","type0":"0","username":"username","pwd":"123456","ipIn":"192.168.1.123","portInC":"554","portInV":"1","ipOut":"192.168.1.123","portOutC":"1","portOutV":"1","chanNum":"1","chanNumOut":"1","brand":"测试品牌","vld":"0","address":"地址","mediaAddr":"rtsp://{username}:{pwd}@{ip}:{port}/MPEG-4/ch1/sub/av_stream","webUrl":"webUrl"}, {"id":"3","name":"测试视频#3","type":"3004","type0":"0","username":"username","pwd":"123456","ipIn":"192.168.1.123","portInC":"554","portInV":"1","ipOut":"192.168.1.123","portOutC":"1","portOutV":"1","chanNum":"1","chanNumOut":"1","brand":"测试品牌","vld":"0","address":"地址","mediaAddr":"rtsp://{username}:{pwd}@{ip}:{port}/MPEG-4/ch1/sub/av_stream","webUrl":"webUrl"}, {"id":"4","name":"测试视频#4","type":"3004","type0":"0","username":"username","pwd":"123456","ipIn":"192.168.1.123","portInC":"554","portInV":"1","ipOut":"192.168.1.123","portOutC":"1","portOutV":"1","chanNum":"1","chanNumOut":"1","brand":"测试品牌","vld":"0","address":"地址","mediaAddr":"rtsp://{username}:{pwd}@{ip}:{port}/MPEG-4/ch1/sub/av_stream","webUrl":"webUrl"}, {"id":"5","name":"测试视频#5","type":"3004","type0":"0","username":"username","pwd":"123456","ipIn":"192.168.1.123","portInC":"554","portInV":"1","ipOut":"192.168.1.123","portOutC":"1","portOutV":"1","chanNum":"1","chanNumOut":"1","brand":"测试品牌","vld":"0","address":"地址","mediaAddr":"rtsp://{username}:{pwd}@{ip}:{port}/MPEG-4/ch1/sub/av_stream","webUrl":"webUrl"}, {"id":"6","name":"测试视频#6","type":"3004","type0":"0","username":"username","pwd":"123456","ipIn":"192.168.1.123","portInC":"554","portInV":"1","ipOut":"192.168.1.123","portOutC":"1","portOutV":"1","chanNum":"1","chanNumOut":"1","brand":"测试品牌","vld":"0","address":"地址","mediaAddr":"rtsp://{username}:{pwd}@{ip}:{port}/MPEG-4/ch1/sub/av_stream","webUrl":"webUrl"}, {"id":"7","name":"测试视频#7","type":"3004","type0":"0","username":"username","pwd":"123456","ipIn":"192.168.1.123","portInC":"554","portInV":"1","ipOut":"192.168.1.123","portOutC":"1","portOutV":"1","chanNum":"1","chanNumOut":"1","brand":"测试品牌","vld":"0","address":"地址","mediaAddr":"rtsp://{username}:{pwd}@{ip}:{port}/MPEG-4/ch1/sub/av_stream","webUrl":"webUrl"}, {"id":"8","name":"测试视频#8","type":"3004","type0":"0","username":"username","pwd":"123456","ipIn":"192.168.1.123","portInC":"554","portInV":"1","ipOut":"192.168.1.123","portOutC":"1","portOutV":"1","chanNum":"1","chanNumOut":"1","brand":"测试品牌","vld":"0","address":"地址","mediaAddr":"rtsp://{username}:{pwd}@{ip}:{port}/MPEG-4/ch1/sub/av_stream","webUrl":"webUrl"} ]; var deviceList = []; layui.use(['layer'], function () { layer = layui.layer; }); if (TEST_TAG) { deviceList = testList; renderDeviceData(); }else{ //查询设备信息并渲染 queryDeviceList(); } //获取设备信息列表 function queryDeviceList() { $.get("./cgi-bin/device-vedio/query", function (data, status) { if ("success" == status) { deviceList = data; renderDeviceData(); } else { window.parent.notify("系统获取基础设备列表出错!"); } }, "json"); } //渲染设备列表 function renderDeviceData() { var html = ''; $.each(deviceList, function (index, item) { html += '' + item.name + ''; html += '' + item.id + ''; html += '' + item.ipIn + ''; html += '' + item.portInC + ''; html += '' + item.portInV + ''; html += '' + item.chanNum + ''; html += '' + item.brand + ''; html += '' + (item.vld == 0 ? '启用' : '停用') + ''; // html += ''; html += ''; html += ''; if (item.vld == 0) { html += ''; } else { html += ''; } html += ''; html += ''; }); $("#deviceList").html(html); } //新增设备 function add() { //表单重置 $("#device-video")[0].reset(); $("#device-id").attr("readOnly",false); $(".pop-btn").hide(); $("#add").show(); var widthPop = "85%"; var heightPop = "80%"; if(screen.width==1920 && screen.height==1080){ widthPop = "85%"; heightPop = "80%"; }else if(screen.width==1280 && screen.height==1024){ widthPop = "98%"; heightPop = "90%"; }else{ widthPop = "85%"; heightPop = "80%"; } //弹出框 layer.open({ skin: 'mypop', type: 1, title: false, area: [widthPop, heightPop], closeBtn: 0, shade: 0, scrollbar: false, content: $('#dialog-device') }); }; //设备编辑 function edit(index) { //表单重置 $("#device-video")[0].reset(); //赋值 -表单 var data = deviceList[index]; $("#device-name").val(data.name); $("#device-id").val(data.id); $("#device-type").val(data.type); $("#device-type0").val(data.type0); $("#device-brand").val(data.brand); $("#device-username").val(data.username); $("#device-pwd").val(data.pwd); $("#device-ipIn").val(data.ipIn); $("#device-portInC").val(data.portInC); $("#device-portInV").val(data.portInV); $("#device-ipOut").val(data.ipOut); $("#device-portOutC").val(data.portOutC); $("#device-portOutV").val(data.portOutV); $("#device-chanNum").val(data.chanNum); $("#device-chanNumOut").val(data.chanNumOut); $("#device-vld").val(data.vld); $("#device-address").val(data.address); $("#device-mediaAddr").val(data.mediaAddr); $("#device-webUrl").val(data.webUrl); $("#device-id").attr("readOnly",false); $(".pop-btn").hide(); $("#edit").show(); var widthPop = "85%"; var heightPop = "80%"; if(screen.width==1920 && screen.height==1080){ widthPop = "85%"; heightPop = "80%"; }else if(screen.width==1280 && screen.height==1024){ widthPop = "98%"; heightPop = "90%"; }else{ widthPop = "85%"; heightPop = "80%"; } //弹出框 layer.open({ skin: 'mypop', type: 1, title: false, area: [widthPop, heightPop], closeBtn: 0, shade: 0, scrollbar: false, content: $('#dialog-device') }); } //设备编辑 function copy(index) { //表单重置 $("#device-video")[0].reset(); //赋值 -表单 var data = deviceList[index]; // $("#device-id").attr("readOnly",true); $("#device-name").val(data.name); $("#device-id").val(data.id); $("#device-type").val(data.type); $("#device-type0").val(data.type0); $("#device-brand").val(data.brand); $("#device-username").val(data.username); $("#device-pwd").val(data.pwd); $("#device-ipIn").val(data.ipIn); $("#device-portInC").val(data.portInC); $("#device-portInV").val(data.portInV); $("#device-ipOut").val(data.ipOut); $("#device-portOutC").val(data.portOutC); $("#device-portOutV").val(data.portOutV); $("#device-chanNum").val(data.chanNum); $("#device-chanNumOut").val(data.chanNumOut); $("#device-vld").val(data.vld); $("#device-address").val(data.address); $("#device-mediaAddr").val(data.mediaAddr); $("#device-webUrl").val(data.webUrl); $(".pop-btn").hide(); $("#add").show(); var widthPop = "85%"; var heightPop = "80%"; if(screen.width==1920 && screen.height==1080){ widthPop = "85%"; heightPop = "80%"; }else if(screen.width==1280 && screen.height==1024){ widthPop = "98%"; heightPop = "90%"; }else{ widthPop = "85%"; heightPop = "80%"; } //弹出框 layer.open({ skin: 'mypop', type: 1, title: false, area: [widthPop, heightPop], closeBtn: 0, shade: 0, scrollbar: false, content: $('#dialog-device') }); } //数据删除 function del(index) { var data = deviceList[index]; var param = {"id": data.id}; layer.confirm('确定删除此条数据吗?', function (index) { $.post("./cgi-bin/device-vedio/delete", JSON.stringify(param), function (data, status) { if ("success" == status && "success" == data.code) { layer.close(index); window.parent.notify("数据删除成功,页面自动刷新!"); queryDeviceList(); } else { layer.close(index); window.parent.notify("数据删除失败"); } }, "json"); }); } //状态设置 function changeStatus(index) { var data = deviceList[index]; var param = {"id": data.id}; var msg = "确定要停用么?", url = "./cgi-bin/device-vedio/val-1"; if (1 == data.vld) { msg = "确定启用用么?"; url = "./cgi-bin/device-vedio/val-0"; } layer.confirm(msg, function (index) { $.post(url, JSON.stringify(param), function (data, status) { if ("success" == status && "success" == data.code) { layer.close(index); window.parent.notify("操作成功,页面自动刷新!"); queryDeviceList(); } else { layer.close(index); window.parent.notify("数据操作失败,请重新尝试!"); } }, "json"); }); } //关闭 function closeBtn() { //表单重置 $("#device-video")[0].reset(); layer.closeAll(); } //数据提交保存 function save(btn) { //获取设备信息 var data = { id: $("#device-id").val(), name: $("#device-name").val(), type: CATEGORY.D3004.code, type0: $("#device-type0").val(), brand: $("#device-brand").val(), username: $("#device-username").val(), pwd: $("#device-pwd").val(), ipIn: $("#device-ipIn").val(), portInC: $("#device-portInC").val(), portInV: $("#device-portInV").val(), ipOut: $("#device-ipOut").val(), portOutC: $("#device-portOutC").val(), portOutV: $("#device-portOutV").val(), chanNum: $("#device-chanNum").val(), chanNumOut: $("#device-chanNumOut").val(), vld: $("#device-vld").val(), address: $("#device-address").val(), mediaAddr: $("#device-mediaAddr").val(), webUrl: $("#device-webUrl").val() }; console.log("----------需要执行保存的数据信息--------"); console.log(JSON.stringify(data)); if (!data.id) { window.parent.notify("设备ID不能为空!"); return; } var r = /^\d{4}$/; if(!r.test(data.id)){ window.parent.notify("设备ID不是一个4位的正整数!"); return; } if (data.id<4000 || data.id>4999) { window.parent.notify("网络设备ID设置范围为4000~4999!"); return; } var url = "./cgi-bin/device-vedio/add"; if ("edit" == btn) { url = "./cgi-bin/device-vedio/edit"; } //执行保存 $.post(url, JSON.stringify(data), function (data, status) { if (data.code == "success") { layer.closeAll(); window.parent.notify("数据保存成功!"); queryDeviceList(); } else { window.parent.notify("数据保存出错,请重新操作!"+data.msg+"!"); } }, "json"); } //内网访问 function showWeb(index){ var data = deviceList[index]; if(!data.ipIn){ $alert("没有配置内部访问IP,无法访问。"); return; } if(!data.portInV){ $alert("没有配置内部访问端口,无法访问。"); return; } var url = "http://"+data.ipIn+":"+data.portInV; console.log(url); window.open(url); }