-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplatform_message.html
More file actions
869 lines (835 loc) · 40.5 KB
/
platform_message.html
File metadata and controls
869 lines (835 loc) · 40.5 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
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
<!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/buttons.dataTables.min.css" rel="stylesheet" />
<link href="css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="css/select.dataTables.min.css" rel="stylesheet" />
<link href="css/scroller.dataTables.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">
<title>平台消息</title>
<style>
.table>tbody>tr td{
cursor: pointer;
}
.disabled{
cursor:not-allowed;
color: #CCCCCC!important;
}
</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><img src="img/top_news.png"/></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 bg-color" onClick="location='platform_message.html'"> <!-- 跳转页面 -->
<img src="img/platform1.png" style="width: 30px;" class="hd_img"/>
<img src="img/platform_select.png" style="width: 30px;" class="hover_img"/>
<p class="sublist-title">平台消息</p>
</div>
<div class="subNav" onClick="location='device_message.html'">
<img src="img/device2.png" style="width: 30px;" class="hd_img"/>
<img src="img/device_select.png" style="width: 30px;" class="hover_img"/>
<p class="sublist-title">设备消息</p>
</div>
</div>
<!-- 左侧导航 end -->
<div class="right-product my-index right-full">
<!-- 标题 -->
<p class="mes_title">平台消息 <span>(全部消息<span class="allMessage"></span>条,其中未确认消息 <span class="disposed_message"></span>条,<a class="isLook">查看未确认</a><input
type="hidden" name="isLook" value=""> )</span></p>
<div class="mes_content">
<!-- 功能栏 -->
<div class="mes_search">
<button class="confirmation">确认消息</button>
<button class="confirmationAll">确认所有消息</button>
<div>
<div class="btn-group search_filter1" 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" name="search_keyword1" value="">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li data-name=""><a style="cursor:pointer">全部消息类型</a></li>
<li data-name="Status"><a style="cursor:pointer">设备状态</a></li>
<li data-name="Action"><a style="cursor:pointer">设备操作</a></li>
<!--<li data-name="Owner"><a style="cursor:pointer">所有人变更</a></li>-->
</ul>
</div>
<div class="btn-group search_filter2" role="group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="search_keyword2" data-search_keyword="1">时间</span><input type="hidden" name="search_keyword2" value="">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li data-name="device_time1"><a style="cursor:pointer">1小时</a></li>
<li data-name="device_time2"><a style="cursor:pointer">24小时</a></li>
<li data-name="device_time3"><a style="cursor:pointer">三天</a></li>
</ul>
</div>
<div class="bs-example J_mineSearchForm">
<div class="input-group" style="width:300px;">
<div class="input-group-btn search_filter3">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="search_keyword3" data-search_keyword="1">序列号</span><input type="hidden" name="search_keyword3" value="">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="version">
<li data-name=""><a style="cursor:pointer">序列号</a></li>
<li data-name=""><a style="cursor:pointer">用户</a></li>
</ul>·
</div><!-- /btn-group -->
<input type="text" class="form-control J_keyword" placeholder="输入关键词">
<span class="input-group-addon search"></span>
</div><!-- /input-group -->
</div>
<i id="glyphicon-refresh" class="glyphicon glyphicon-repeat"></i>
</div>
</div>
</div>
<!-- 表格 -->
<div style="margin: 0 15px;border: 1px solid #E5E9EE;">
<table id="platform_message" class="table dataTable no-footer " style="background-color:#FFFFFF;">
<thead>
<tr>
<th><label class="checkbox"><input index="0" name="select_all" type="checkbox" class="box" id="select_all"><em></em></label></th>
<th>标题</th>
<th>设备号</th>
<th>发生时间</th>
<th>消息类型</th>
<th>用户</th>
<th>ID</th>
<th>状态</th>
<th>内容 </th>
</tr>
</thead>
</table>
</div>
</div>
<!--无内容状态-->
<div class="none hd">
<p><img src="img/photo_wdwg.png"/></p>
<p>很抱歉,您还没有消息,请先绑定新网关!</p>
<!--<button class="bind">绑定新网关</button>-->
</div>
<!--无内容状态end-->
<!--<div class="copyright">SymTech Application © 2008-2017</div>-->
</div>
<!-- 加载script start -->
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></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/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="js/dataTables.bootstrap.min.js" type="text/javascript"></script>
<script src="js/dataTables.buttons.js" type="text/javascript"></script>
<script src="js/dataTables.select.min.js" type="text/javascript"></script>
<script src="js/dataTables.scroller.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>
<script>
$(document).ready(function() {
var token = $.cookie('DS_auth_token');
$.ajaxSetup({
headers: { // 默认添加请求头
"X-Frappe-CSRF-Token": token
}
});
var myfilters = {
start: 0,
limit: 500
};
var myajax = function(data, callback, oSettings ) {
return $.ajax({
url: "/apis/api/method/iot.user_api.device_activity",
type: "POST",
contentType: "application/json",
data:JSON.stringify(myfilters),
success: function (data) {
callback(data);
console.log(data);
}
})
};
// datatables配置
var table = $('#platform_message').DataTable({
dom: 'rt<"#table_footer"Bp>',
buttons: [],
"bStateSave": false,
// stateSave: true,
"bFilter": true, //是否启动过滤,搜索功能
"sPaginationType": "full_numbers",
"iDisplayLength": 10,
"processing": false,
"ajax": myajax,
"sAjaxDataProp": "message",
"columns": [
{"data": null},
{"data": "subject"},
{"data": "device"},
{"data": "creation"},
{"data": "operation"},
{"data": "user"},
{"data": "name"},
{"data": "disposed"},
{"data": "message"}
],
"language": {
"sProcessing": "",
"sLengthMenu": "显示 _MENU_ 项结果",
"sZeroRecords": "没有匹配结果",
"sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
"sInfoEmpty": "显示第 0 至 0 项结果,共 0 项",
"sInfoFiltered": "(由 _MAX_ 项结果过滤)",
"sInfoPostFix": "",
"sSearch": "搜索:",
"sUrl": "",
"sEmptyTable": "表中数据为空",
"sLoadingRecords": "载入中...",
"sInfoThousands": ",",
"oPaginate": {
"sFirst": "首页",
"sPrevious": "上页",
"sNext": "下页",
"sLast": "末页"
},
"oAria": {
"sSortAscending": ": 以升序排列此列",
"sSortDescending": ": 以降序排列此列"
}
},
rowCallback: function (row, data, dataIndex) {
//时间截取----- 毫秒
var timeText = $(row).children('td').eq(3).text();
$(row).children('td').eq(3).text(timeText.substring(0,19));
//标题
var str = $(row).children('td').eq(8).text();
var obj = eval("("+str+")");
//设备状态
if(obj.hasOwnProperty('device_status')){
// $(row).children('td').eq(8).text(obj.device_status);
if(obj.device_status == "ONLINE"){
$(row).children('td').eq(1).html('<span>设备上线</span>');
}else if(obj.device_status == "OFFLINE"){
$(row).children('td').eq(1).html('<span>设备离线</span>');
}
//设备操作
}else if(obj.hasOwnProperty('action')){
// $(row).children('td').eq(8).text("ACTION");
if(obj.channel == "app"){
if(obj.action == "option"){ //开机自启动
if(obj.data.value == 1){
$(row).children('td').eq(1).html('<span>开启应用'+obj.data.inst+'开机自启动</span>');
}else if(obj.data.value == 0){
$(row).children('td').eq(1).html('<span>关闭应用'+obj.data.inst+'开机自启动</span>');
}
}else if(obj.action == "restart"){
$(row).children('td').eq(1).html('<span>重启应用'+obj.data.inst+'</span>');
}else if(obj.action == "start"){
$(row).children('td').eq(1).html('<span>启动应用'+obj.data.inst+'</span>');
}else if(obj.action == "stop"){
$(row).children('td').eq(1).html('<span>停止应用'+obj.data.inst+'</span>');
}else if(obj.action == "conf"){
$(row).children('td').eq(1).html('<span>更改应用'+obj.data.inst+'应用配置</span>');
}else if(obj.action == "upload_comm"){
if(obj.data.sec == 0){
$(row).children('td').eq(1).html('<span>停止上传应用'+obj.data.inst+'报文</span>');
}else if(obj.data.sec == 120){
$(row).children('td').eq(1).html('<span>上传应用'+obj.data.inst+'报文</span>');
}
}else if(obj.action == "install"){
$(row).children('td').eq(1).html('<span>安装应用'+obj.data.name+'实例名'+obj.data.inst+'</span>');
}else if(obj.action == "uninstall"){
$(row).children('td').eq(1).html('<span>卸载应用'+obj.data.inst+'</span>');
}else if(obj.action == "query_comm"){
$(row).children('td').eq(1).html('<span>应用'+obj.data.inst+'查询报文</span>');
}else if(obj.action == "query_log"){
$(row).children('td').eq(1).html('<span>应用'+obj.data.inst+'查询日志</span>');
}else if(obj.action == "list"){
$(row).children('td').eq(1).html('<span>刷新应用列表</span>');
}else if(obj.action == "upgrade"){
$(row).children('td').eq(1).html('<span>应用'+obj.data.inst+'升级到最新版本</span>');
}else if(obj.action == "rename"){
$(row).children('td').eq(1).html('<span>应用'+obj.data.inst+'重命名为'+obj.data.new_name+'</span>');
}
} //app
else if(obj.channel == "sys"){
if(obj.action == "enable/beta"){
if(obj.data == 0){
$(row).children('td').eq(1).html('<span>网关关闭beta模式</span>');
}else if(obj.data == 1){
$(row).children('td').eq(1).html('<span>网关开启beta模式</span>');
}
}else if(obj.action == "enable/data"){
if(obj.data == 0){
$(row).children('td').eq(1).html('<span>网关关闭数据上传</span>');
}else if(obj.data == 1){
$(row).children('td').eq(1).html('<span>网关开启数据上传</span>');
}
}else if(obj.action == "enable/log"){
if(obj.data == ""){
$(row).children('td').eq(1).html('<span>网关关闭日志上送</span>');
}else if(obj.data == 120){
$(row).children('td').eq(1).html('<span>网关开启日志上送</span>');
}
}else if(obj.action == "enable/comm"){
if(obj.data.sec == 0){
$(row).children('td').eq(1).html('<span>网关停止报文上送</span>');
}else if(obj.data.sec == 120){
$(row).children('td').eq(1).html('<span>网关开启报文上送</span>');
}
}else if(obj.action == "restart"){
$(row).children('td').eq(1).html('<span>网关IOT程序重启</span>');
}else if(obj.action == "reboot"){
$(row).children('td').eq(1).html('<span>网关设备重启</span>');
}else if(obj.action == "cloud_conf"){
$(row).children('td').eq(1).html('<span>网关云中心配置选项更新</span>');
}else if(obj.action == "enable/data_one_short"){
if(obj.data.sec == ""){
$(row).children('td').eq(1).html('<span>网关关闭临时上传数据</span>');
}else if(obj.data.sec == 120){
$(row).children('td').eq(1).html('<span>网关开启临时上传数据</span>');
}
}else if(obj.action == "ext/upgrade"){
$(row).children('td').eq(1).html('<span>网关更新扩展库'+obj.data.name+'</span>');
}else if(obj.action == "ext/list"){
$(row).children('td').eq(1).html('<span>网关上传扩展库列表 </span>');
}else if(obj.action == "cfg/download"){
$(row).children('td').eq(1).html('<span>网关IOT固件配置下载</span>');
}else if(obj.action == "cfg/upload"){
$(row).children('td').eq(1).html('<span>网关IOT固件配置上传</span>');
}else if(obj.action == "upgrade"){
$(row).children('td').eq(1).html('<span>网关升级到最新版本</span>');
}else if(obj.action == "enable/event"){
$(row).children('td').eq(1).html('<span>网关更改事件上传等级</span>');
}else if(obj.action == "enable/stat"){
$(row).children('td').eq(1).html('<span>网关开启统计数据上传</span>');
}else if(obj.action == "batch_script"){
$(row).children('td').eq(1).html('<span>网关执行批量操作</span>');
}else if(obj.action == "upgrade/ack"){
$(row).children('td').eq(1).html('<span>网关IOT固件升级确认</span>');
}
} //sys
else if(obj.channel == "command"){
$(row).children('td').eq(1).html('<span>网关应用设备执行'+obj.data.cmd+'指令</span>');
} //command
else if(obj.channel == "putput"){
$(row).children('td').eq(1).html('<span>网关设备应用'+obj.data.output+'数据输出</span>');
} //output
}
//判断是否确认消息
if($(row).children('td').eq(7).text() == 0 ){
$(row).children('td').eq(1).prepend('<i class="on disposed"></i>')
}else{
// console.log($(row).children('td').eq(1))
}
},
columnDefs: [
{
// 指定第第一列
targets: [0],
searchable: false,
orderable: false,
width: '5%',
render: function (data, type, row, meta) {
var gen_html = '<label class="checkbox"><input index="0" name="select_single" type="checkbox" class="box"><em></em></label>';
return gen_html;
}
}, {
// 指定第第2列
targets: [1],
width: '25%',
render: function (data, type, row, meta) {
return data;
}
}, {
// 指定第第3列
targets: [2],
class:'subject',
width: '25%'
}, {
// 指定第第4列
targets: [3],
width: '20%'
}, {
// 指定第第5列
className:"",
targets: [4],
width: '13%'
}, {
// 指定第第6列
className:"hide_column",
targets: [5],
width: '12%'
}, {
// 指定第第7列 ------ 事件id
className:"hide_column",
targets: [6]
}, {
// 指定第第8列 ------- 是否查看
className:"hide_column",
targets: [7]
}, {
// 指定第第9列 ------- 设备状态
className:"hide_column",
targets: [8]
}
],
"order" : [ [ 1, 'asc' ] ],
'order' : [3,'desc']
});
table.draw(true);
console.log('draw')
// 获取全部消息条数 ---- 平台
$.ajax({
url:"/apis/api/method/iot.user_api.count_device_activity",
type:"GET",
success:function (req) {
$('.allMessage').text(req.message);
}, error:function (error) {
console.log('error');
}
});
//获取未读信息条数
$.ajax({
url: "/apis/api/method/iot.user_api.device_activity",
type: "POST",
dataType: "json",
success: function (data) {
var a = 0;
var list = data.message;
for(var i=0;i<list.length;i++){
if(list[i].disposed == 0){
a++;
}
}
$('.disposed_message').text(a);
if(a == 0){
$('.confirmation').addClass('disabled');
$('.confirmationAll').addClass('disabled')
$('.confirmation').attr('disabled',true);
$('.confirmationAll').attr('disabled',true);
}
},
error: function (error) {
console.log(error)
}
});
//点击查看所有未读消息
$('.isLook').click(function () {
if($(this).text() == "查看未确认"){
$('input[name=isLook]').val(0); //查看未处理
table
.column(7)
.search(0)
.draw();
$(this).text("查看所有");
}else if($(this).text() == "查看所有"){
$('input[name=isLook]').val(''); //查看所有
table
.column(7)
.search("")
.draw();
$(this).text("查看未确认");
}
});
//点击行进入详情
$('#platform_message tbody').on('click','tr td:nth-child(2)',function() {
console.log($(this));
var name = $(this).parent('tr').find('td:nth-child(7)').text();
location.href = 'platform_details.html?name=' + name;
} );
//时间戳转换
function timestampToTime(timestamp) {
var date = new Date(timestamp);
var Y = date.getFullYear() + '-';
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
var D = (date.getDate() < 10 ? '0'+(date.getDate()) : date.getDate()) + ' ';
var h = date.getHours() + ':';
var m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':';
var s = '00';
return Y+M+D+h+m+s;
}
// 下拉框--- 时间
$('.search_filter2 li').on('click', function(){
$('.search_keyword2').text($(this).text());
var content = $('.search_keyword2').text();
// console.log(content);
if(content == "1小时"){
//获取当前时间前一小时
var an_hour_ago = Date.parse(new Date()) - 1 * 60 * 60 * 1000;
date1 = timestampToTime(an_hour_ago);
$('input[name=search_keyword2]').val(date1);
var param1 = {
start: 0,
limit: 500,
filters: {
creation:[">",date1]
}
};
var oneData;
var myajax1 = function(data, callback, oSettings ) {
return $.ajax({
url: "/apis/api/method/iot.user_api.device_activity",
type: "POST",
async: false,
contentType: "application/json",
data:JSON.stringify(param1),
success: function (data) {
oneData = data;
if(JSON.stringify(data) == "{}"){
alt('一小时之内暂时没有消息',2);
}else if(JSON.stringify(data) != "{}"){
console.log(data);
callback(data);
}
}
})
}
if(JSON.stringify(oneData) != "{}"){
table.settings()[0].ajax = myajax1;
table.ajax.reload();
}
}else if(content == "24小时"){
//获取当前时间前24小时
var dataSet2 = [];
var one_day_ago = Date.parse(new Date()) - 24 * 60 * 60 * 1000;
var date2 = timestampToTime(one_day_ago);
$('input[name=search_keyword2]').val(date2);
var param2 = {
start: 0,
limit: 500,
filters: {
creation:[">",date2]
}
};
var myajax2 = function(data, callback, oSettings ) {
return $.ajax({
url: "/apis/api/method/iot.user_api.device_activity",
type: "POST",
contentType: "application/json",
data:JSON.stringify(param2),
success: function (data) {
if(JSON.stringify(data) == "{}"){
alt('24小时之内暂时没有消息',2);
}else{
console.log(data);
callback(data);
}
}
})
}
table.settings()[0].ajax = myajax2;
table.ajax.reload();
}else if(content == "三天"){
//获取当前时间前72小时
var three_day_ago = Date.parse(new Date()) - 72 * 60 * 60 * 1000;
var date3 = timestampToTime(three_day_ago);
$('input[name=search_keyword2]').val(date3);
var param3 = {
start: 0,
limit: 400,
filters: {
creation:[">",date3]
}
};
console.log(param3)
var myajax3 = function(data, callback, oSettings ) {
return $.ajax({
url: "/apis/api/method/iot.user_api.device_activity",
type: "POST",
contentType: "application/json",
data:JSON.stringify(param3),
success: function (data) {
if(JSON.stringify(data) == "{}"){
alt('三天之内暂时没有消息',2);
}else{
console.log(data);
callback(data);
}
}
})
}
table.settings()[0].ajax = myajax3;
table.ajax.reload();
}
});
//下拉框--- 关键词
$('.search_filter3 li').on('click', function(){
$('.search_keyword3').text($(this).text());
var con = $('.search_keyword3').text();
if(con == "序列号"){
$('.search_keyword3').val('device')
}else if(con == "用户"){
$('.search_keyword3').val('user')
};
});
//下拉框--- 消息类型
$('.search_filter1 li').on('click', function(){
$('.search_keyword1').text($(this).text());
var content = $('.search_keyword1').text();
if(content == "设备操作"){
$('input[name=search_keyword1]').val("Action");
table
.column(4)
.search("Action")
.draw();
}else if(content == "设备状态"){
$('input[name=search_keyword1]').val("Status");
table
.column(4)
.search("Status")
.draw();
}else if(content != ""){
$('input[name=search_keyword1]').val("");
table
.column(4)
.search("")
.draw()
}
});
//下拉框--- 分类搜索
$('input.J_keyword').on( 'keyup click', function () { //点击搜索框
var key = $('input.J_keyword').val(); //搜索框内容
if($('.search_keyword3').text()=="序列号"){
table
.columns(2)
.search(key)
.draw(); }
if($('.search_keyword3').text()=="用户"){
table
.columns(5)
.search(key)
.draw();
}
} );
// 全选
var $selectAll = $('input[name=select_all]');
var $selectSingle = $('input[name=select_single]');
$selectAll.click(function () {
console.log('全选');
if ($selectAll.prop("checked") == true) {
// 上面的复选框已被选中
$(":checkbox[name='select_single']").prop("checked", true);
} else {
// 上面的复选框没被选中
$(":checkbox[name='select_single']").prop("checked", false);
}
});
//确认消息
$('.confirmation').click(function () {
var checkBox = $('input:checkbox[name=select_single]');
var eventId = $('#platform_message tbody tr td:nth-child(7)');
var title = $('#platform_message tbody tr td:nth-child(2)>i');
var dm = $('.disposed_message').text();
var arr = [];
console.log(checkBox.length);
console.log(eventId.length);
checkBox.each(function (i) {
if(checkBox[i].checked == true){
var ids = eventId.eq(i).text();
if(ids != 'undefined'){
arr.push(ids); //得到记录ID,放到arr数组中
}
}
})
console.log(arr);
//确认消息
var dataS = {
"disposed":1,
"activities": arr
};
console.log(dataS);
if( arr != 0 ){
$.ajax({
url:"/apis/api/method/iot.user_api.dispose_device_activities",
type:"POST",
data:JSON.stringify(dataS),
contentType:"application/json",
// dataType:'JSON',
success:function(data){
debugger;
$(":checkbox[name='select_all']").prop("checked", false);
checkBox.each(function (i) {
if(checkBox[i].checked == true){
checkBox[i].checked = false;
var a = title.eq(i);
a.removeClass('disposed');
}
if(dm>=10){
$(".disposed_message").text( dm - arr.length )
}else if(dm<=0){
$(".disposed_message").text("0")
}
})
},
error:function(error){
console.log('error')
}
});
}else{
alt("请选择需要确认的信息",2)
}
});
//点击确认所有消息
$('.confirmationAll').click(function () {
var title = $('#device_message tbody tr td:nth-child(2)>i');
$.ajax({
url: "/apis/api/method/iot.user_api.device_activity",
type: "POST",
data:{
'start':0,
'limit':500
},
dataType: "json",
success: function (data) {
var list = data.message; //所有消息
var aList = [];
for(var i=0;i<list.length;i++){
if(list[i].disposed == 0){
aList.push(list[i].name);
title.eq(i).removeClass('disposed');
}
}
//确认消息
if(aList.length != 0){
var dataS = {
"disposed":1,
"activities": aList
};
$.ajax({
url:"/apis/api/method/iot.user_api.dispose_device_activities",
type:"POST",
data:JSON.stringify(dataS),
contentType:"application/json",
dataType:'JSON',
success:function(data){
title.each(function (i) {
title.eq(i).removeClass('disposed');
});
$("#platform_message").dataTable().fnDraw(true);
},
error:function(error){
console.log('error')
}, complete: function () {
if(aList.length != 0){
var myfilters = {
start: 0,
limit: 500
};
var myajax11 = function(data, callback, oSettings ) {
return $.ajax({
url: "/apis/api/method/iot.user_api.device_activity",
type: "POST",
contentType: "application/json",
data:JSON.stringify(myfilters),
success: function (data) {
callback(data);
console.log(data);
}
})
};
table.settings()[0].ajax = myajax11;
table.ajax.reload();
}
}
});
$('.disposed_message').text(0);
}else{
alt("暂时没有未读消息",3)
}
},
error: function (error) {
console.log(error)
},
complete: function () {
if($('.disposed_message').text() == 0){
$('.confirmation').addClass('disabled');
$('.confirmationAll').addClass('disabled')
$('.confirmation').attr('disabled',true);
$('.confirmationAll').attr('disabled',true);
}
}
});
});
//刷新数据
$('#glyphicon-refresh').click(function () {
var is_look = $('input[name=isLook]').val(); //是否查看 isLook:0未查看
var mess_type = $('input[name=search_keyword1]').val(); //消息类型 search_keyword1
var sel_time = $('input[name=search_keyword2]').val(); //时间范围
var search_type = $('input[name=search_keyword3]').val(); //搜索类型(序列号、用户)
var search_text = $('.j_keyword').val(); //关键字
var param1 = {};
if(search_type == "user"){
param1 = {
start: 0,
limit: 100,
filters: {
"disposed" : is_look,
"operation" : mess_type, //消息类型
"user" : search_text,
"creation" :[">", sel_time]
}
};
}else if(search_type == "device"){
param1 = {
start: 0,
limit: 100,
filters: {
"disposed" : is_look,
"operation" : mess_type, //消息类型
"device" : search_text,
"creation" :[">", sel_time]
}
};
}
var oneData;
var myajax1 = function(data, callback, oSettings ) {
return $.ajax({
url: "/apis/api/method/iot.user_api.device_activity",
type: "POST",
async: false,
contentType: "application/json",
data:JSON.stringify(param1),
success: function (data) {
oneData = data;
if(JSON.stringify(data) == "{}"){
alt('一小时之内暂时没有消息',2);
}else{
console.log(data);
callback(data);
}
}
})
}
if(JSON.stringify(oneData) !== "{}"){
table.settings()[0].ajax = myajax1;
table.ajax.reload();
}
})
});//($)
</script>
</body>
</html>