wuwei
2025-05-28 7c16e785d2ece656fb0822f7b2514f59dd23e91d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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");
}