-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapplication_config.html
More file actions
798 lines (761 loc) · 38.7 KB
/
application_config.html
File metadata and controls
798 lines (761 loc) · 38.7 KB
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<link rel="shortcut icon" href="/img/favicon.ico" />
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<link href="css/viccom.css" rel="stylesheet" />
<link href="css/animate.min.css" rel="stylesheet" />
<link rel="stylesheet" href="js/layui/css/layui.css" media="all">
<!-- 加载script start -->
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="js/crontab.js?v=20180706" type="text/javascript"></script>
<!--markdown start-->
<script src="js/editor.md-master/lib/marked.min.js"></script>
<script src="js/editor.md-master/lib/prettify.min.js"></script>
<script src="js/editor.md-master/lib/raphael.min.js"></script>
<script src="js/editor.md-master/lib/underscore.min.js"></script>
<script src="js/editor.md-master/lib/sequence-diagram.min.js"></script>
<script src="js/editor.md-master/lib/flowchart.min.js"></script>
<script src="js/editor.md-master/lib/jquery.flowchart.min.js"></script>
<script src="js/editor.md-master/editormd.js"></script>
<!--markdown end-->
<script src="js/ace/ace.js" charset="utf-8" type="text/javascript"></script>
<script src="js/ace/ext-language_tools.js" type="text/javascript"></script>
<script src="js/jquery.timeago.js"></script>
<script src="js/transport.js" type="text/javascript"></script>
<script src="js/jQuery.cookie.js" type="text/javascript"></script>
<script src="js/layui/layui.js" charset="utf-8"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="js/arrayFun.js" type="text/javascript"></script>
<script src="js/common.js" type="text/javascript"></script>
<script src="js/user.js" type="text/javascript"></script>
<script src="js/index.js" type="text/javascript"></script>
<title>应用配置</title>
<style>
.c_box th,.c_box td{ white-space:nowrap;line-height: 40px;padding: 0 20px;text-align: center;}
.c_box td{min-width: 120px;line-height: 40px;height: 40px;padding: 0 20px;}
.c_box td input{border:1px solid orange;border-radius:5px;position:absolute;left: 1%;top: 4px;padding: 0 10px;text-align:center;width:98%;height: 34px;font-size:14px;}
.c_box td.input{padding:0;position:relative;}
.c_box table{min-width:60%;max-width:90%;}
.checkbox{width: 50px;height: 30px;margin: 10px 0;}
.checkbox em{top: 7px!important;}
.addRows{width: 100px;height: 30px;line-height: 30px;margin: 10px 0;}
.btn-default {color: #000!important;width: 260px;}
.btn{text-align: left}
.caret{position: absolute;right: 10px;top: 14px;}
.dropdown-menu{width:260px}
.temp_list td:nth-child(4){display: none;}
.temp_list1 td:nth-child(3){display: none;background-color: red}
.no_config{display: none;width: 90%;height: 80%;z-index: 9999;position: absolute;top: 200px;left: 130px;}
@media screen and (max-width: 1200px) {
#code1{
height: 400px;}
}
@media screen and (min-width:1200px){
#code1{height: 600px;}
.c_content{
height: 800px;
}
}
</style>
</head>
<body>
<!-- 顶部导航 start -->
<nav class="nav_herder">
<div class="nav_left gate_hand" onClick="location='index.html'"><img src="img/cloud_thingslink_logo.png" class="logo"/>冬笋物联网</div>
<div class="pull-right nav_right">
<p class="J_getMembers hd"><img src="img/top_management.png"/><span>成员管理</span></p><em>|</em>
<p onclick="javascript:$('#messageBox').show()" style="position: relative;"><img src="img/top_news.png"/><span style="display:none" class="redDot"></span></p><em>|</em>
<p onClick="location='personal_info.html'"><img src="img/top_avatar.png"/><span class="J_nickname">昵称</span></p><em>|</em>
<p><img src="img/top_quit.png" id="J_logout"/></p>
</div>
</nav>
<!-- 顶部导航 end -->
<div class="down-main">
<!-- 左侧导航 start -->
<div class="left-main left-full">
<div class="sidebar-fold"><img src="img/nav_shrink.png"/></div>
<div class="subNav" onClick="location='index.html'">
<img src="img/nav_home.png" class="hd_img"/>
<img src="img/nav_home_hover.png" class="hover_img"/>
<p class="sublist-title">首页</p>
</div>
<div class="subNav" onClick="location='mine.html'">
<img src="img/nav_equipment.png" class="hd_img"/>
<img src="img/nav_equipment_hover.png" class="hover_img"/>
<p class="sublist-title">我的网关</p>
</div>
<div class="subNav" onClick="location='application_list.html'">
<img src="img/my_app.png" class="hd_img"/>
<img src="img/my_apps.png" class="hover_img"/>
<p class="sublist-title">我的应用</p>
</div>
<div class="subNav" onClick="location='template.html'">
<img src="img/my_app.png" class="hd_img"/>
<img src="img/my_apps.png" class="hover_img"/>
<p class="sublist-title">我的模板</p>
</div>
</div>
<!-- 左侧导航 start -->
<div class="right-product my-index right-full">
<ol class="breadcrumb">
<li><a href="index.html"><img src="img/icon_nav.png" />首页</a></li>
<li class="active"><a href="mine.html">我的网关</a></li>
<li class="active J_gate_name"></li>
<li class="active install_new"></li>
<li class="active j_get_app"></li>
<li class="active">应用配置</li>
</ol>
<!-- 标题 -->
<div class="details_title"><span class="version_name">应用配置</span><i id="goBack" onclick="history.go(-1)" class="glyphicon glyphicon-arrow-left"></i></div>
<!-- 内容 -->
<div class="c_content">
<div class="c_box">
<p></p>
<div class="routine">
<div>
<span>实例名称</span>
<div class="sel_inp">
<input class="sel_input" id="inst_name" type="text" value="" placeholder="请输入...">
</div>
</div>
</div>
</div>
<!--<div class="c_box">-->
<!--<p>应用常规</p>-->
<!--<div class="routine">-->
<!--<!–<div><span>名称</span>–>-->
<!--<!–<div class="sel_inp">–>-->
<!--<!–<input class="sel_input" type="text" value="">–>-->
<!--<!–<ul class="sel_ul">–>-->
<!--<!–<li>001</li>–>-->
<!--<!–<li>002</li>–>-->
<!--<!–</ul>–>-->
<!--<!–</div>–>-->
<!--<!–</div>–>-->
<!--</div>-->
<!--</div>-->
<!--<div class="c_box">-->
<!--<p>应用模板</p>-->
<!--<div>-->
<!--<table border="1" collapsing="0" borderColor="#e5e9ee">-->
<!--<tr>-->
<!--<th>名称</th>-->
<!--<th>平台名称</th>-->
<!--<th>描述</th>-->
<!--<th>版本</th>-->
<!--<th>创建时间</th>-->
<!--</tr>-->
<!--<tr>-->
<!--<td class="bj">1</td>-->
<!--<td>2</td>-->
<!--<td>3</td>-->
<!--<td>4</td>-->
<!--<td>5</td>-->
<!--</tr>-->
<!--</table>-->
<!--</div>-->
<!--</div>-->
<!--<div class="c_box">-->
<!--<p>设备列表</p>-->
<!--<div>-->
<!--<table border="1" collapsing="0" borderColor="#e5e9ee">-->
<!--<tr>-->
<!--<th>名称</th>-->
<!--<th>平台名称</th>-->
<!--<th>描述</th>-->
<!--<th>版本</th>-->
<!--<th>创建时间</th>-->
<!--</tr>-->
<!--<tr>-->
<!--<td class="bj">1</td>-->
<!--<td class="bj">2</td>-->
<!--<td class="bj">3</td>-->
<!--<td class="bj">4</td>-->
<!--<td class="bj">5</td>-->
<!--</tr>-->
<!--</table>-->
<!--</div>-->
<!--</div>-->
<button class="config_save">保存配置</button>
</div>
<p class="copyright">SymTech Application © 2008-2017</p>
</div>
<div class="no_config">
<div class="txt_main" style="height: 100%;">
<div>
<p>应用配置:</p>
<div id="code1" class="ace_editor" style=" border: 1px solid #e1e1e1;"><textarea rows=20 class="ace_text-input">{}</textarea></div>
<script>
//初始化对象
editor = ace.edit("code1");
//设置风格和语言(更多风格和语言,请到github上相应目录查看)
theme = "clouds"
language = "json"
editor.setTheme("ace/theme/" + theme);
editor.session.setMode("ace/mode/" + language);
//字体大小
editor.setFontSize(16);
//设置只读(true时只读,用于展示代码)
editor.setReadOnly(false);
//自动换行,设置为off关闭
editor.setOption("wrap", "free")
//启用提示菜单
ace.require("ace/ext/language_tools");
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
var session = editor.getSession();
//console.log('-------------------session1',session.getValue());
</script>
</div>
<div id="button" class="button">确定</div>
</div>
</div>
</div>
<div id="template_box">
<div id="select_template">
<p>模板列表 <span>×</span></p>
<div>
<table class="temp_list1">
<tr>
<th style="width: 40%">模板名称</th>
<th style="width: 45%">模板描述</th>
<th style="display: none;">版本</th>
<th style="width: 15%"></th>
</tr>
</table>
</div>
</div>
</div>
<script>
$(function () {
//获取token
//获取token
var token = $.cookie('DS_auth_token');
$.ajaxSetup({
headers: { // 默认添加请求头
"X-Frappe-CSRF-Token": token
}
});
//获取用户信息
var user = getCookie('usr');
var device_sn = getParam('device_sn');
var app = getParam('name');
$('.J_gate_name').html('<a href="http://localhost/collection.html?type=device&device_sn='+device_sn+'">'+device_sn+'</a>');
$('.install_new').html('<a href="shop.html?device_sn='+device_sn+'">安装新应用</a>')
$('.j_get_app').text(app);
//应用名称
var app_name;
//模板接口返回数据
var list;
//templates -- template
var template_list = [];
$.ajax({
url: "/apis/api/method/conf_center.api.list_app_conf",
type: "GET",
async: false,
data: {app:app,start:0,limit:100},
success: function (req) {
list = req.message;
console.log(list)
if(list){
for(var i=0;i<list.length;i++){
var html = '<tr>';
html += '<td>'+list[i].conf_name+'</td><td>'+list[i].description+'</td><td>'+list[i].name+'</td><td><button class="add_single">添加</button></td></tr>'
$('#select_template table').append(html);
}
}
}, error: function () {
console.log('error')
}
});
$.ajax({
url: "/apis/api/method/app_center.api.app_detail",
type: "GET",
async: false,
data: {app:app},
success: function (data) {
console.log(data)
app_name = data.message.app_name;
// console.log(data.message.conf_template);
if(data.message.has_conf_template){
var con_temp = $.parseJSON(data.message.conf_template);
for (var i=0;i<con_temp.length;i++){
if(con_temp[i].name == "protocol"){
inp = '<div class="btn-group" role="group">' +
'<button type="button" class="btn btn-default dropdown-toggle " data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' +
'<span class="search_keyword1" data-search_keyword="1">'+con_temp[i].value[0]+'</span>' +
'<input type="hidden" id="sel1" class="sel_input" value="'+con_temp[i].value[0]+'">' +
'<span class="caret"></span>' +
'</button>' +
'<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">' +
'</ul>' +
'</div>';
$('.c_content').append('<div class="c_box '+ con_temp[i].name +'">' +
'<div class="routine">' +
'<div><p style="width: 100%;height: 20px;"></p><span>'+con_temp[i].desc+'</span>' +
'<input type="hidden" value="">' +
'<div class="sel_inp" id="'+con_temp[i].name+'">' + inp+
'</div>' +
'</div>'+
'</div>'+
'</div>');
console.log($('#'+con_temp[i].name));
for(var w=0;w<con_temp[i].value.length;w++){
$('#'+con_temp[i].name+' ul').append('<li data-name=""><a style="cursor:pointer">'+ con_temp[i].value[w] +'</a></li>');
}
} else if(con_temp[i].type == "section"){
if(con_temp[i].depends){
var depend = con_temp[i].depends;
var ids = depend.substring(depend.lastIndexOf(' ')+1,depend.length-1);
$('.c_content').append('<div id="'+ids+'" class="c_box '+ con_temp[i].name +' "><p>'+con_temp[i].desc+'</p></div>');
}else{
$('.c_content').append('<div class="c_box '+ con_temp[i].name +' "><p>'+con_temp[i].desc+'</p></div>');
}
var child = con_temp[i].child;
for (var j=0;j<child.length;j++){
var inp;
if(child[j].type == "dropdown"){ //下拉
inp = '<div class="btn-group" role="group">' +
'<button type="button" class="btn btn-default dropdown-toggle " data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' +
'<span class="search_keyword1" data-search_keyword="1">'+child[j].value[0]+'</span>' +
'<input type="hidden" class="sel_input" value="'+child[j].value[0]+'">' +
'<span class="caret"></span>' +
'</button>' +
'<ul class="dropdown-menu '+ child[j].name +'" role="menu" aria-labelledby="dLabel">' +
'</ul>' +
'</div>';
$('.'+ con_temp[i].name +'').append('<div class="routine">' +
'<div><span>'+child[j].desc+'</span>' +
'<input type="hidden" value="">' +
'<div class="sel_inp" id="'+child[j].name+'">' + inp+
'<input type="hidden" class="name" value="'+child[j].name+'">'+
'<input type="hidden" class="type" value="'+child[j].type+'">'+
'</div>' +
'</div>'+
'</div>');
for(var w=0;w<child[j].value.length;w++){
$('.'+child[j].name).append('<li data-name=""><a style="cursor:pointer">'+ child[j].value[w] +'</a></li>');
}
}else if(child[j].type == "text"){
if(child[j].value ){
inp = "<input class='sel_input' type='text' value='"+ child[j].value +"'>";
}else{
inp = "<input class='sel_input' type='text' value='' placeholder='请输入...'>";
}
$('.'+ con_temp[i].name +'').append('<div class="routine">' +
'<div><span>'+child[j].desc+'</span>' +
'<div class="sel_inp">' + inp+
'<input type="hidden" class="name" value="'+child[j].name+'">'+
'<input type="hidden" class="type" value="'+child[j].type+'">'+
'</div>' +
'</div>'+
'</div>');
}else if(child[j].type == "boolean"){
if(child[j].value == true ){
inp = "<label class='checkbox'><input type='checkbox' class='sel_input box' value='true' checked><em></em></label>";
}else{
inp = "<label class='checkbox'><input type='checkbox' class='sel_input box' value='false'><em></em></label>";
}
$('.'+ con_temp[i].name +'').append('<div class="routine">' +
'<div><span>'+child[j].desc+'</span>' +
'<div class="sel_inp">' + inp+
'<input type="hidden" class="name" value="'+child[j].name+'">'+
'<input type="hidden" class="type" value="'+child[j].type+'">'+
'</div>' +
'</div>'+
'</div>');
}else if(child[j].type == "templates"){
//判断有没有模板
if(list){
inp = '<table class="temp_list" border="1" collspacing="0">' +
'<tr><th>模板名称</th><th>模板描述</th><th>关联应用</th><th style="display: none;">id</th><th>操作</th></tr>'+
'</table>' +
'<button class="add_temp temp">添加模板</button>'
}else{
inp = '<button class="temp">此应用暂时没有模板</button>'
}
$('.'+ con_temp[i].name +'').append('<div class="routine">' +
'<div><span>'+child[j].desc+'</span>' +
'<div class="sel_inp">' + inp+
'<input type="hidden" class="name" value="'+child[j].name+'">'+
'<input type="hidden" class="type" value="'+child[j].type+'">'+
'</div>' +
'</div>'+
'</div>'
);
var temp_list = $('.temp_list>tr>td:nth-child(1)')
console.log(temp_list)
// if(temp_list.message){
// for(var w=0;w<temp_list.message.length;w++){
// $('.'+child[j].type+'_sel').append('<li data-name="">' +
// '<a style="cursor:pointer">'+temp_list.message[w].conf_name+'</a>' +
// '<input type="hidden" value="'+temp_list.message[w].name+'"></li>');
// }
// }
}else if(child[j].type == "number"){
if(child[j].value){
inp = "<input class='sel_input' type='number' value='"+ child[j].value[0] +"'>";
}else{
inp = "<input class='sel_input' type='text' value='' placeholder='请输入...'>";
}
$('.'+ con_temp[i].name +'').append('<div class="routine">' +
'<div><span>'+child[j].desc+'</span>' +
'<div class="sel_inp">' + inp+
'<input type="hidden" class="name" value="'+child[j].name+'">'+
'<input type="hidden" class="type" value="'+child[j].type+'">'+
'</div>' +
'</div>'+
'</div>'
);
}else if(child[j].type == "table"){
inp = "<table border='1' collspacing='0' class='"+child[j].name+"'><tr></tr></table>" +
"<input type='button' class='addRows' value='添加行'>";
$('.'+ con_temp[i].name +'').append('<div class="routine">' +
'<div><span>'+child[j].desc+'</span>' +
'<div class="sel_inp">' + inp+
'</div>' +
'</div>'+
'</div>');
for (var a=0;a<child[j].cols.length;a++){
$('.'+child[j].name+'>tbody').append('<th id="'+child[j].cols[a].type+'">'+child[j].cols[a].desc+'<input type="hidden" value="'+child[j].cols[a].name+'"></th>')
}
$('.'+child[j].name+'>tbody').append('<th>操作</th>')
}
}
}
}
}else{
$('.no_config').show();
$('.config_save').hide();
}
}, error: function () {
console.log('no')
}, complete: function () {
if($('.temp_list tr').length <= 1){
$('.temp_list').hide();
}else{
$('.temp_list').show();
}
//判斷通訊協議
if($('#sel1').val() == "Modbus RTU"){
$('#RTU').show();
$('#TCP').hide();
}else if($('#sel1').val() == "Modbus TCP"){
$('#RTU').hide();
$('#TCP').show();
}
//表格添加行
$('.addRows').click(function () {
var table = $(this).parent().find($('table>tbody'));
var tr_len = $(this).parent().find($('table th')).length;
var html = '<tr class="sj">';
for (var n=0;n<tr_len-1;n++){
html += '<td class="bj '+$(this).parent().find($('table th:nth-child('+(n+2)+')>input')).val()+'" name="'+ $(this).parent().find($('table th:nth-child('+(n+2)+')')).attr('id') +'"></td>';
}
html += '<td><button class="delete_device_list">刪除</button></td></tr>';
table.append(html);
if(!list){
$('.tpl').text('————');
$('.tpl').addClass('disabled');
}
//点击td进行编辑
$('table>tbody .bj').click(function () {
if( !$(this).is('.input') ){
if( !$(this).is('.disabled') ){
var html;
if($(this).hasClass('tpl')){
html = '<div class="btn-group" role="group">' +
'<button type="button" class="btn btn-default dropdown-toggle " data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' +
'<span class="search_keyword1" data-search_keyword="1">请选择</span>' +
'<input type="hidden" class="sel_input" value="">' +
'<span class="caret"></span>' +
'</button>' +
'<ul class="dropdown-menu tpl_sel" role="menu" aria-labelledby="dLabel">' +
'</ul>' +
'</div>';
}else if(!$(this).hasClass('tpl')){
html = '<input type="'+ $(this).attr('name') +'" value="" />'
}
$(this).addClass('input')
.html(html)
.find('input').focus()
.blur(function(){
$(this).parent().removeClass('input').html($(this).val() );
$('.visualize').trigger('visualizeRefresh');
});
if($(this).hasClass('tpl')){
if(template_list){
for(var w=0;w<template_list.length;w++){
$(this).find($('.tpl_sel')).append('<li data-name="">' +
'<a style="cursor:pointer">'+template_list[w]+'</a>' +
'</li>');
}
var tpl_li = $('.tpl_sel>li');
tpl_li.each(function (i) {
tpl_li[i].index = i;
tpl_li.eq(i).click(function () {
$(this).parent().parent().find('.search_keyword1').text($(this).text());
})
})
}
}
}
}
});
//删除行
$('.delete_device_list').click(function () {
$(this).parent().parent().remove()
})
});
//这里是加载完,到这里已经有li了
var ali = $('ul>li'); //获取页面所有LI
ali.each(function (p) {
ali[p].index = p;
ali[p].onclick = function () {
$(this).parent().parent().find('.search_keyword1').text($(this).text());
$(this).parent().parent().find('.sel_input').val($(this).text());
if($(this).text() == "Modbus RTU"){
$('#RTU').show();
$('#TCP').hide();
}else if($(this).text() == "Modbus TCP"){
$('#RTU').hide();
$('#TCP').show();
}
}
})
}
});
$('.install_new').click(function () {
location.href = 'shop.html?device_sn='+device_sn;
})
/**
* 购买或安装(已添加监控)
*/
$("#button").click(function(){
console.log(111)
// var app = $('.J_app').val();
var inst = $('#inst_name').val(); // 手动填写的
var session = editor.getSession();
var devs = JSON.parse(session.getValue());
console.log('----------------------')
console.log(devs)
// if(devs==''){
// devs = {};
// }
if(inst==''){
err('应用实例不能为空');
return false;
}
var id = "install "+device_sn+"'s App "+app+ ' '+Date.parse(new Date());
var data = {
"device": device_sn,
"id": id,
"data": {
"inst": inst,
"name": app,
"version": localStorage.getItem('app_lastest_version_'+app),
"conf": devs
}
}
console.log(localStorage.getItem('app_lastest_version_'+app))
// // console.log('-------------------data',data);
Ajax.call('/api/method/iot.device_api.app_install', JSON.stringify(data), app_install, 'POST', 'JSON', 'JSON');
function app_install(req){
if(req.message!=''){
var idarr = {
'id':id,
'times':20,
'docid':'',
'type':'app_install',
'title':"应用安装",
'crontabDesc':inst+"安装",
}
addCrontab(idarr);
alt('命令已发送,等待结果返回',1);
}else{
err('命令执行失败');
}
setTimeout(function(){
window.location.href='collection.html?type=manage&device_sn='+device_sn;
}, 2000);
}
})
$('input[type=checkbox]').click(function () {
$(this).val($(this).prop('checked'));
});
$('.add_temp').click(function () {
$('#template_box').show();
document.body.style.overflow='hidden';
});
$('#select_template>p>span').click(function () {
$('#template_box').hide();
document.body.style.overflow='auto';
});
$('.add_single').click(function () {
var name = $(this).parent().parent().find($('td:nth-child(1)')).text();
var desc = $(this).parent().parent().find($('td:nth-child(2)')).text();
var id = $(this).parent().parent().find($('td:nth-child(3)')).text();
$('.temp_list').show();
$('.temp_list').append('<tr>' +
'<td>'+ name +'</td>' +
'<td>'+ desc +'</td>' +
'<td>'+ app_name +'</td>' +
'<td>'+ id +'</td>' +
'<td><button class="delete_device_list">删除</button></td>'+
'</tr>');
template_list.push(name);
$(this).text('已添加');
$(this).unbind('click')
$('.delete_device_list').click(function () {
$(this).parent().parent().remove();
if($('.temp_list tr').length <= 1){
$('.temp_list').hide();
}
})
});
//生成json
$('.config_save').click(function () {
//tcp数据
var tcp_data = [];
var tcp_s = $('.tcp_section .routine');
tcp_s.each(function (i) {
var a = {
name : tcp_s.eq(i).find($('.name')).val(),
value : tcp_s.eq(i).find($('.sel_input')).val()
};var obj = {};
var k = a.name;
var v = a.value;
obj[k] = v;
tcp_data.push(obj);
});
//串口数据
var serial_data = [];
var serial_s = $('.serial_section .routine');
serial_s.each(function (i) {
var a = {
name : serial_s.eq(i).find($('.name')).val(),
value : serial_s.eq(i).find($('.sel_input')).val()
};
var obj = {};
var k = a.name;
var v = a.value;
obj[k] = v;
serial_data.push(obj);
})
//采集设备列表
var device_data = [];
var device_s = $('.device_section table .sj');
for (var i=0;i<device_s.length;i++){
var a = {
tpl : device_s.eq(i).find($('.tpl .search_keyword1')).text(),
name : device_s.eq(i).find($('.name')).text(),
sn : device_s.eq(i).find($('.sn')).text(),
addr : device_s.eq(i).find($('.addr')).text()
};
device_data.push(a)
}
//通讯协议
var protocol = $('#sel1').val();
//模板数据
var templates = $('.temp_list tr');
var temp_data = [];
for (var i=1;i<templates.length;i++){
var a = {
name : templates.eq(i).find($('td:nth-child(1)')).text(),
id : templates.eq(i).find($('td:nth-child(4)')).text(),
}
temp_data.push(a)
}
//返回json
var return_data;
if(template_list.length == 0){
template_list = "";
}
if($('#sel1').val() == "Modbus TCP"){
return_data = {
temp_name : $('#inst_name').val(),
templates : template_list,
tcp : tcp_data,
dev : device_data,
protocol : protocol,
link_type : 'tcp'
}
}else if($('#sel1').val() == "Modbus RTU"){
return_data = {
temp_name : $('#inst_name').val(),
templates : template_list,
serial : serial_data,
dev : device_data,
protocol : protocol,
link_type : 'serial'
}
}
var data = {
device: device_sn,
id : app,
data : {
inst : $('#inst_name').val(),
conf : return_data
}
};
if(!$('#inst_name').val()){
alt('请填写实例名称',2);
}else{
console.log(return_data)
// Ajax.call('/apis/api/method/iot.device_api.app_conf', JSON.stringify(data), app_config, 'POST', 'JSON', 'JSON');
// function app_config(req) {
// if(req.message!=''){
// // addCrontab(idarr);
// alt('命令已发送,等待结果返回',1);
// }else{
// err('命令执行失败');
// }
// setTimeout(function () {
// window.location.href='collection.html?type=manage&device_sn='+device_sn;
// },2000)
// }
var inst = $('#inst_name').val(); // 手动填写的
var id = "install "+device_sn+"'s App "+app+ ' '+Date.parse(new Date());
var data = {
"device": device_sn,
"id": id,
"data": {
"inst": inst,
"name": app,
"version": localStorage.getItem('app_lastest_version_'+app),
"conf": return_data
}
}
Ajax.call('/api/method/iot.device_api.app_install', JSON.stringify(data), app_install, 'POST', 'JSON', 'JSON');
function app_install(req){
if(req.message!=''){
var idarr = {
'id':id,
'times':20,
'docid':'',
'type':'app_install',
'title':"应用安装",
'crontabDesc':inst+"安装",
}
addCrontab(idarr);
alt('命令已发送,等待结果返回',1);
}else{
err('命令执行失败');
}
setTimeout(function(){
window.location.href='collection.html?type=manage&device_sn='+device_sn;
}, 2000);
}
}
})
}); //$(function)
</script>
</body>
</html>