lgq
2025-07-08 eea897aeac44a75e93fdc90939261f1b44711087
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var layer;// 定义全局变量
var data = {
    "firmware": "固件版本",
    "software": "软件版本",
    "hardware": "硬件版本",
    "operation": "系统运行时长",
    "time": new Date()
};
var form;
var laydate;
$(function () {
    layui.use(['layer', 'form', 'laydate'], function () {
        layer = layui.layer;
        form = layui.form;
        laydate = layui.laydate;
 
        laydate.render({
            elem: '#time'
            , type: 'datetime'
            , trigger: 'click'
            , theme: 'custom'
            ,value: new Date()
        });
 
        if(TEST_TAG){
            renderForm(data);
        }else{
            //默认查询
            query();
 
            //网关参数
            querySet();
        }
    });
});
 
//执行查询
function query() {
    $.get("./cgi-bin/device-ctrl/query-version", function (data, status) {
        if ("success" == status) {
            renderForm(data);
        } else {
            window.parent.parent.notify("数据查询出错,请重新操作!!");
        }
    }, "json");
}
 
//渲染表格
function renderForm(data) {
    // console.log(list);
    //赋值
    $("#firmware").val(data.firmware);
    $("#software").val(data.software);
    $("#hardware").val(data.hardware);
    //运行时长
    // renderDay(data.operation);
    $("#operation").val(data.operation);
    $("#time").val(data.time);
}
 
//渲染使用天数
function renderDay(dayTime) {
    if (dayTime) {
        dayTime = dayTime.substring(0, 4) + "/" + dayTime.substring(4, 6) + "/" +
            dayTime.substring(6, 8) + " 00:00:00";
        //获取开始使用时的毫秒数
        var timestamp = new Date(dayTime).getTime();
        //当前时间的毫秒数
        var timestampNow = new Date().getTime();
        var num = timestampNow - timestamp;
        var daytamp = 1000 * 60 * 60 * 24;
        var day = Math.ceil(num / daytamp);
        $("#operation").val(day);
    }
}
 
//重启设备
function rebootDevice(){
    if(confirm("是否进行重启设备?")){
        $.get("./cgi-bin/device-ctrl/reboot-device", function (data, status) {
            if ("success" == status) {
                window.parent.parent.notify("操作成功!");
            } else {
                window.parent.parent.notify("重启设备失败!");
            }
        }, "json");
    }
}
//重启服务器
function rebootService(){
    if(confirm("是否进行重启服务?")){
        $.get("./cgi-bin/device-ctrl/reboot-service", function (data, status) {
            if ("success" == status) {
                window.parent.parent.notify("操作成功!");
            } else {
                window.parent.parent.notify("重启服务失败!");
            }
        }, "json");
    }
}
 
//下载协议库备份
function downLibname() {
    // var $eleForm = $("<form method='get'></form>");
    //
    // $eleForm.attr("action","");
    //
    // $(document.body).append($eleForm);
    // //提交表单实现下载
    // $eleForm.submit();
}
 
 
//执行保存,网关设置
function saveSet() {
    var set = form.val("form-set");
    // console.log(JSON.stringify(set));
    $.post("./cgi-bin/sys-set/save-set", JSON.stringify(set), function (data, status) {
        if (data.code == "success") {
            window.parent.parent.notify("数据保存成功!");
        } else {
            window.parent.parent.notify("数据保存出错,请重新操作!!msg=" + data.msg);
        }
    }, "json");
}
 
//时间格式处理,2021-02-26 -----20210226
function timeStr(time) {
    return time.replace('-','').replace('-','');
}
 
//执行查询,网关参数
function querySet() {
    $.get("./cgi-bin/sys-set/query-set", function (data, status) {
        if ("success" == status) {
            renderSet(data);
        } else {
            window.parent.parent.notify("数据查询出错,请重新操作!!msg=" + data.msg);
        }
    }, "json");
}
 
function renderSet(data){
    form.val("form-set",data);
}