var testList=[
|
{"passcode":"1","name":"通道号1","value":"0"},
|
{"passcode":"2","name":"通道号2","value":"1"},
|
{"passcode":"3","name":"通道号3","value":"0"},
|
{"passcode":"4","name":"通道号4","value":"0"},
|
{"passcode":"5","name":"通道号5","value":"1"},
|
{"passcode":"6","name":"通道号6","value":"0"},
|
{"passcode":"7","name":"通道号7","value":"1"},
|
{"passcode":"8","name":"通道号8","value":"0"}
|
];
|
|
var deviceList = [];
|
|
if (TEST_TAG) {
|
deviceList = testList;
|
|
renderDeviceData();
|
}else{
|
|
//定时器,每15秒查询一次;查询设备信息并渲染
|
queryData();
|
setInterval(queryData,15 * 1000);
|
}
|
|
|
//查询设备信息
|
function queryData() {
|
$.get("./cgi-bin/do/query", function (data, status) {
|
if ("success" == status) {
|
deviceList = data;
|
renderDeviceData();
|
} else {
|
window.parent.parent.notify("系统获取基础设备列表出错!");
|
}
|
}, "json");
|
}
|
|
//渲染设备列表
|
function renderDeviceData() {
|
var html = "";
|
$.each(deviceList, function (index, item) {
|
html += "<tr><td>" + item.passcode + "</td>";
|
html += "<td>输出量" + item.passcode + "</td>";
|
if(item.value==0){
|
html += "<td>断开</td>";
|
html += "<td><button style='height: 29px;line-height: 29px;'" +
|
" class='layui-btn layui-btn-normal' onclick='setData(" + index + ")'>" +
|
"闭合</button></td>";
|
}else{
|
html += "<td>闭合</td>";
|
html += "<td><button style='height: 29px;line-height: 29px;'" +
|
" class='layui-btn layui-btn-danger' onclick='setData(" + index + ")'>" +
|
"断开</button></td>";
|
}
|
html += "</td></tr>";
|
});
|
|
$("#deviceList").html(html);
|
}
|
|
//输出量控制
|
function setData(index) {
|
var param = {
|
passcode : deviceList[index].passcode,
|
value : deviceList[index].value == 0 ? 1 : 0
|
};
|
console.log(param);
|
$.post("./cgi-bin/do/set", JSON.stringify(param), function (data, status) {
|
if ("success" == data.code) {
|
queryData()
|
} else {
|
window.parent.parent.notify("操作失败!" + data.msg);
|
}
|
}, "json");
|
}
|
|