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
(function () {
    //获取URL中的参数id
    var deviceId = getParam("id");
 
    console.log("------获取URL中的参数-----deviceId=" + deviceId);
 
    if (!deviceId) {
        window.parent.notify("没有获取到设备ID,无法查看监控信息");
        return false;
    }
    //根据设备ID从缓存中获取设备基本信息
    var device = window.parent.getDevice(deviceId);
 
    //根据设备ID从接口中获取实时监控
    queryData(deviceId,device);
    //定时器,每5秒查询一次;查询设备信息并渲染
    setInterval(function () {
        queryData(deviceId,device);
    },5000);
 
}).call(this);
 
 
function queryData(deviceId,device) {
    var data = {id: deviceId};
    $.post("./cgi-bin/detail/query-data", JSON.stringify(data), function (data, status) {
        if ("success" == status) {
            console.log('---------获取到的设备实时数据-----' + data);
            renderInfo(data,device);
        } else {
            console.log("数据查询出错,请重新操作!");
            window.parent.notify("数据查询出错,请重新操作!");
        }
    }, "json");
};
 
 
/**
 * 获取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;
}