IGD3000系列(一体屏)网关的app和文件系统的打包目录
朱浩东
2025-06-14 58d2e329d04aaf39b0ed00308de62bff47fa8ce8
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
var layer;// 定义全局变量
var form;
var element;
var upload;
 
var LIST = [{"libname":"libtest_ths.so","libnamezh":"温湿度","note":""}];
 
//定时轮询时间2s
var INTERVAL = 2 * 1000;
var intervalData;
 
var protocolfile;
var rootfile;
var protocolfileBase64;
var rootfileBase64;
 
var file002;
var file002Base64;
$(function () {
    layui.use(["layer", "form", "element", "upload"], function () {
        layer = layui.layer;
        form = layui.form;
        element = layui.element;
        upload = layui.upload;
 
        renderLib();
 
        //查询协议库
        queryLib();
        //查询软件版本
        query();
 
        uploadProtocolFile();
        uploadRootFile();
        uploadFile002();
 
    });
});
 
function queryLib() {
    $.get("./cgi-bin/libname/libname-list", function (data, status) {
        if ("success" == status) {
            LIST = data;
            renderLib();
        } else {
            window.parent.parent.notify("数据查询出错,请重新操作!!");
        }
    }, "json");
}
 
function renderLib() {
    $("#tbodyList").html('');
    if(LIST){
        $.each(LIST,function (index,it) {
            var html = '';
            html += '<tr>';
            html += '<td>'+it.libnamezh+'</td>';
            html += '<td>'+it.libname+'</td>';
            html += '<td>';
            html += '<a style="margin:0px 5px;width:30%;height: 29px;line-height: 29px;" class="layui-btn layui-btn-normal" ' +
                'href="/cgi-bin/download/download.cgi?filename='+it.libname+'" download="'+it.libname+'">下载';
            html += '</a>';
            html += '<button style="margin:0px 5px;width:30%;height: 29px;line-height: 29px;" class="layui-btn layui-btn-danger" ' +
                'lay-event="detail" onclick="delLib(\''+it.libname+'\');">删除';
            html += '</button>';
            html += '</td>';
            html += '</tr>';
            $("#tbodyList").append(html);
        });
    }
}
 
function delLib(name) {
    console.log(name);
    var obj = {name:name};
    $.post("./cgi-bin/libname/delete", JSON.stringify(obj), function (data, status) {
        if ("success" == status) {
            queryLib();
        } else {
            window.parent.parent.notify("数据查询出错,请重新操作!!");
        }
    }, "json");
}
 
 
//查询软件版本
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) {
    //赋值-软件版本
    $("#software").text(data.software);
}
 
function uploadProtocolFile(){
    var uploadListIns = upload.render({
        elem: '#protocolList'
        ,url: './cgi-bin/img-data/save'
        ,accept: 'file'
        // ,multiple: true
        ,auto: false
        // ,bindAction: '#protocolListAction'
        ,choose: function(obj){
            //将每次选择的文件追加到文件队列
            // var files = obj.pushFile();
 
            //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9)
            obj.preview(function(index, file, result){
                protocolfile = file;
                protocolfileBase64 = result;
                // console.log(protocolfileBase64);
                $("#protocolFileName").text(file.name);
                // console.log(index); //得到文件索引
                // console.log(file); //得到文件对象
                //     console.log(result); //得到文件base64编码,比如图片
            });
        }
    });
};
function uploadRootFile(){
    var uploadListIns = upload.render({
        elem: '#rootList'
        ,url: ''
        ,accept: 'file'
        ,auto: false
        ,choose: function(obj){
            //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9)
            obj.preview(function(index, file, result){
                rootfile = file;
                rootfileBase64 = result;
                $("#rootFileName").text(file.name);
                // console.log(index); //得到文件索引
                // console.log(file); //得到文件对象
                //     console.log(result); //得到文件base64编码,比如图片
            });
        }
    });
};
 
function uploadFile002(){
    var uploadListIns = upload.render({
        elem: '#file002'
        ,url: ''
        ,accept: 'file'
        ,auto: false
        ,choose: function(obj){
            //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9)
            obj.preview(function(index, file, result){
                file002 = file;
                file002Base64 = result;
                $("#file002Name").text(file.name);
                // console.log(index); //得到文件索引
                // console.log(file); //得到文件对象
                //     console.log(result); //得到文件base64编码,比如图片
            });
        }
    });
};
 
function uploadProtocol() {
    var index= protocolfile.name.lastIndexOf(".");
    var suffix = protocolfile.name.substr(index);
    if(suffix != ".so" && suffix != ".json"){
        // layer.msg("该文件不是协议文件!");
        window.parent.parent.notify("该文件不是协议文件!");
        return ;
    }
    var param = {"name": protocolfile.name,"data" : protocolfileBase64};
    console.log(param.name);
    $.ajaxSettings.async = false;
    $.post("./cgi-bin/file/upload", JSON.stringify(param), function (data, status) {
        if (data.code == "success") {
            query();
            layer.closeAll();
            window.parent.parent.notify("文件上传成功!");
        } else {
            window.parent.parent.notify("文件上传出错,请重新操作!"+data.msg+"!");
        }
    }, "json");
}
 
function uploadRoot() {
    upgradeRender("上传升级文件!");
    upgradeRender("文件上传中...");
 
    setTimeout(function () {
        uploadRootfile();// 这里就是处理的事件
    }, 2000);
}
 
function uploadRootfile(){
    var start = 0;
    var end = 0;
    for(var i = 0; i > -1; i++){
        start = i * 1024 * 1024 * 3;
        end = (i + 1) * 1024 * 1024 * 3;
        var b = false;
        if(start < rootfileBase64.length){
            end = end < rootfileBase64.length ? end : rootfileBase64.length;
            var name = rootfile.name;
            var data = rootfileBase64.slice(start,end);
            var param = {"index": i+"", "name": name, "data": data};
            console.log(JSON.stringify(param));
            $.ajaxSettings.async = false;
            $.post("./cgi-bin/file/upfile", JSON.stringify(param), function (data, status) {
                if (data.code == "success") {
                    b = false;
                } else {
                    upgradeRender("文件上传出错,请重新操作!");
                    upgradeRender("错误原因:"+data.msg+"!");
                    b = true;
                }
            }, "json");
            //上传过程出错,请重新上传
            if(b){
                return;
            }
        }else{
            upgradeRender("文件上传成功!");
            return ;
        }
    }
}
 
function downLibname() {
    $.ajaxSettings.async = false;
    $.get("./cgi-bin/file/run", function (data, status) {
        if (data.code == "success") {
 
            downfile(data.name,data.base64);
        } else {
            window.parent.parent.notify("协议备份出错,请重新操作!"+data.msg+"!");
        }
    }, "json");
}
 
function downfile(fileName,base64){
    // 对于<a>标签,只有 Firefox 和 Chrome(内核) 支持 download 属性
    if ('download' in document.createElement('a')) { // 支持a标签download的浏览器
        var link = document.createElement('a'); // 创建a标签
        link.download = fileName;// a标签添加属性
        link.style.display = 'none';
        // link.href = URL.createObjectURL(blob);
        link.href = base64;
        document.body.appendChild(link);
        link.click(); // 执行下载
        URL.revokeObjectURL(link.href); // 释放url
        document.body.removeChild(link); // 释放标签
    } else { // 其他浏览器
        navigator.msSaveBlob(base64, fileName);
    }
}
 
function downByType(type) {
    var url = '';
    if(type == "lib"){
        url = './cgi-bin/download/backup-userlib';
    }else{
        url = './cgi-bin/download/backup-config';
    }
    $.ajaxSettings.async = false;
    $.get(url, function (data, status) {
        if (data.code == "success") {
            downfileByType(type);
        } else {
            window.parent.parent.notify("打包出现错误,请重新操作!"+data.msg+"!");
        }
    }, "json");
}
 
function downfileByType(type){
    var fileName = "";
    var url = "";
    if(type == "lib"){
        fileName = 'userlib.tgz';
        url = '/cgi-bin/download/download.cgi?filename=/work/data/userlib.tgz'
    }else{
        fileName = "config.tgz";
        url = './cgi-bin/download/download.cgi?filename=/work/data/config.tgz'
    }
    // 对于<a>标签,只有 Firefox 和 Chrome(内核) 支持 download 属性
    if ('download' in document.createElement('a')) { // 支持a标签download的浏览器
        var link = document.createElement('a'); // 创建a标签
        link.download = fileName;// a标签添加属性
        link.style.display = 'none';
        // link.href = URL.createObjectURL(blob);
        link.href = url;
        document.body.appendChild(link);
        link.click(); // 执行下载
        URL.revokeObjectURL(link.href); // 释放url
        document.body.removeChild(link); // 释放标签
    } else { // 其他浏览器
        navigator.msSaveBlob(url, fileName);
    }
}
 
 
 
function upgradeAction() {
    $.ajaxSettings.async = false;
    $.get("./cgi-bin/file/upgrade", function (data, status) {
        if (data.code == "success") {
            upgradeRender("开始升级!");
            upgradeRender("升级包解压中。。。");
 
            //获取升级日志
            reLoadModelupgrade();
        } else {
            if (intervalData) clearInterval(intervalData);
        }
    }, "json");
}
 
function upgradeResult() {
    $.ajaxSettings.async = false;
    $.get("./cgi-bin/file/run", function (data, status) {
        if (data.code == "success") {
            upgradeRender(data.data);
        } else {
            if (intervalData) clearInterval(intervalData);
        }
    }, "json");
}
 
//渲染更新升级日志
function upgradeRender(data) {
    if(data){
        var html = "<p>" + data + "</p>";
        $(".log-box").append(html);
        //设置滚动条始终位于最底端
        $(".log-box").scrollTop($(".log-box")[0].scrollHeight);
    }
}
 
//固件升级日志
function reLoadModelupgrade() {
    //固件升级日志
    upgradeResult();
 
    // 首先停止执行原有的循环
    if (intervalData) clearInterval(intervalData);
 
    intervalData = setInterval(function () {
        //升级日志
        upgradeResult();
    }, INTERVAL);
}
 
 
 
//上传文件,并配置更新
function uploadfile002() {
    upgradeRender("上传配置升级文件!");
    upgradeRender("配置文件上传中...");
 
    setTimeout(function () {
        uploadfile002();// 这里就是处理的事件
    }, 2000);
}
 
function uploadfile002(){
    var start = 0;
    var end = 0;
    for(var i = 0; i > -1; i++){
        start = i * 1024 * 1024 * 3;
        end = (i + 1) * 1024 * 1024 * 3;
        var b = false;
        if(start < file002Base64.length){
            end = end < file002Base64.length ? end : file002Base64.length;
            var name = file002.name;
            var data = file002Base64.slice(start,end);
            var param = {"index": i+"", "name": name, "data": data};
            console.log(JSON.stringify(param));
            $.ajaxSettings.async = false;
            $.post("./cgi-bin/file/upfile", JSON.stringify(param), function (data, status) {
                if (data.code == "success") {
                    b = false;
                } else {
                    upgradeRender("文件上传出错,请重新操作!");
                    upgradeRender("错误原因:"+data.msg+"!");
                    b = true;
                }
            }, "json");
            //上传过程出错,请重新上传
            if(b){
                return;
            }
        }else{
            upgradeRender("文件上传成功!");
            return ;
        }
    }
}