monitor.vue
30.4 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
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
<template>
<v-full-layout>
<template slot="breadcrumb">
<el-breadcrumb-item>车辆监控</el-breadcrumb-item>
</template>
<template slot="main">
<div class="map-wrap" v-loading="mapLoading">
<div id="map" class="map-container"></div>
<map-controll isShowFullsize="true"></map-controll>
<div class="controll-wrap">
<div class="menu-search">
<el-autocomplete
ref="autocomplete"
size="small"
:popper-class="'search_auto'+(autocompleteHide?' search_auto_hide':'')"
v-model.trim="searchText"
maxlength="50"
:fetch-suggestions="querySearch"
:trigger-on-focus="false"
:placeholder="'请输入'+['6位以上设备号','6位以上车架号','2位以上姓名'][searchType-1]"
@select="handleSelect">
<!-- <el-input placeholder="请输入对应条件值" v-model.trim="searchText" size="small" class="input-with-select" @keyup.enter.native='searchSubmit'> -->
<el-select v-model="searchType" slot="prepend" placeholder="请选择" size="small" >
<el-option label="设备号" value="1"></el-option>
<el-option label="车架号" value="2"></el-option>
<el-option label="姓名" value="3"></el-option>
<!-- <el-option label="工单号" value="4"></el-option> -->
</el-select>
<el-button icon="el-icon-search" size="mini" slot="append" :loading="isSearching" @click="searchSubmit" >
</el-button>
<template slot-scope="{ item }">
<div style="margin: 0 -20px; font-size: 12px; " class="auto_item">
<template v-if="item.tip">
{{item.tip}}
</template>
<template v-else>
<div class="name" style="line-height: 20px">姓名:{{ item.label1?item.label1:'--' }}</div>
<div class="sn" style="line-height: 20px">设备号:{{ item.label }}</div>
</template>
</div>
</template>
</el-autocomplete>
<!-- </el-input> -->
</div>
<el-row type="flex" class="filter-entrance" justify="space-between">
<!-- <el-button type="text" @click="importDialogHidden=false;listDialogHidden=true;resultDialogHidden=true;">导入查询</el-button> -->
<el-button type="text" @click="treeHidden=false;listDialogHidden=true;importDialogHidden=true;resultDialogHidden=true;">组织</el-button>
<el-button type="text" @click="listDialogHidden=false;treeHidden=true;importDialogHidden=true;resultDialogHidden=true;">监控列表({{getMonitorListVisibleCount}})</el-button>
</el-row>
<div class="filter-dialog-set">
<div class="filter-dialog animated " :class="importDialogHidden?'fadeOut':'active fadeIn'">
<div class="filter-dialog-header">
导入查询
<i class="el-icon-close pull-right" @click.stop="importDialogHidden=true"></i>
</div>
<div class="filter-dialog-body">
<el-form ref="form" :model="form" :rules="rules" :inline="false" size="mini">
<el-form-item label="" prop="filename">
<el-upload ref="upload" class="upload-wrap"
action="vehicle/importSerchDevice"
:on-change="changeFile"
:before-upload="beforeUpload"
:multiple="false"
:show-file-list="false"
:on-success="successUpload"
:on-error="errorUpload"
:data="uploadData"
accept=".xlsx"
:auto-upload="false">
<el-input v-model="form.filename" placeholder="未选取任何文件" class="input-with-select" size="small" >
<el-select v-model="form.uploadType" slot="prepend" placeholder="请选择" size="small" >
<el-option label="设备号" value="1"></el-option>
<el-option label="车架号" value="2"></el-option>
<el-option label="姓名" value="3"></el-option>
<el-option label="工单号" value="4"></el-option>
</el-select>
</el-input>
<div slot="tip" class="el-upload__tip">仅支持同时监控100台设备,还可导入{{100-monitorList.count}}台设备</div>
</el-upload>
</el-form-item>
<el-button type="primary" class="upload-sure-btn" size="small" @click="submitUpload" :loading="importing" :disabled="uploadDisabled">确认</el-button>
<el-button size="mini" type="text" @click="downloadTpl" style="margin-left: 0px;">下载模板</el-button>
</el-form>
</div>
</div>
<div class="filter-dialog animated " :class="listDialogHidden?'fadeOut':'active fadeIn'">
<div class="filter-dialog-header">
监控列表({{monitorList.count}})
<i class="el-icon-close pull-right" @click.stop="listDialogHidden=true"></i>
</div>
<div class="filter-dialog-body">
<el-row type="flex" class="sub-filter" justify="space-between">
<el-select v-model="monitorFilterType" placeholder="请选择" size="small" style="width: 100px;">
<el-option label="全部" value=""></el-option>
<el-option label="有线" value="1"></el-option>
<el-option label="无线" value="0"></el-option>
</el-select>
<!-- <el-button type="primary" plain size="small" @click="removeMonitorByGroup(monitorList.itemArr)">批量删除</el-button> -->
</el-row>
<ul class="monitor-list" style="max-height:calc(100vh - 380px);">
<li class="monitor-list-item"
v-for="(sn, key) in monitorList.itemArr"
:key="sn"
@click="openMapInfoWindow(sn, monitorList[sn].source)"
v-show="key!=='count' && (monitorList[sn].source==monitorFilterType||monitorFilterType=='')">
<span class="device-icon" :class="monitorList[sn].online?'':'offline'" v-show="monitorList[sn].online !== undefined"></span>
<div class="user-info">
<p>
<span class="name">{{monitorList[sn].name||'--'}}</span>
<span>{{sn}}({{monitorList[sn].sourceType}})</span>
</p>
<p>车架号:{{monitorList[sn].standNo}}</p>
</div>
<span class="none_tip" v-show="!monitorList[sn].isHasPosition">无定位信息</span>
<!-- <el-button type="text" @click.stop="removeMonitor(monitorList[sn], true)"><i class="fa fa-trash"></i></el-button> -->
</li>
</ul>
</div>
<div class="filter-dialog-footer">
<div class="device-icon-label"><span class="device-icon"></span> <span>在线</span></div>
<div class="device-icon-label"><span class="device-icon offline"></span> <span>离线</span></div>
</div>
</div>
<div class="filter-dialog animated " :class="resultDialogHidden?'fadeOut':'active fadeIn'">
<div class="filter-dialog-header">
查询结果
<i class="el-icon-close pull-right" @click.stop="resultDialogHidden=true"></i>
</div>
<div class="filter-dialog-body">
<el-row type="flex" class="sub-filter" justify="space-between">
<el-select v-model="resultFilterType" placeholder="请选择" size="small" style="width: 100px;">
<el-option label="全部" value=""></el-option>
<el-option label="有线" value="1"></el-option>
<el-option label="无线" value="0"></el-option>
</el-select>
<el-button type="primary" plain size="small" @click="addMonitorByGroup">批量监控</el-button>
</el-row>
<ul class="monitor-list">
<li class="monitor-list-item" v-for="item in resultList" :key="item.id" v-show="item.source==resultFilterType||resultFilterType==''">
<div class="user-info">
<p><span class="name">{{item.name}}</span><span>{{item.sn}}({{item.sourceType}})</span></p>
<p>车架号:{{item.standNo}}</p>
</div>
<el-button type="text" @click.prevent="addMonitor(item)">监控</el-button>
</li>
<li v-show="!resultList.length">
<p class="text-center">无数据</p>
</li>
</ul>
</div>
</div>
<div class="filter-dialog" :class="treeHidden?'fadeOut':'active fadeIn'">
<div class="filter-dialog-header">
组织
<i class="el-icon-close pull-right" @click.stop="treeHidden=true"></i>
</div>
<div class="filter-dialog-body">
<div class="monitor-list">
<el-tree
ref="tree"
:data="treeData"
:props="treeProps"
lazy
:load="loadNode"
show-checkbox
node-key="id"
:render-content="renderTreeContent"
:default-expanded-keys="expandedKeys"
:default-checked-keys="checkedKeys"
@check="handleCheck"
v-loading="treeLoading"
@check-change="handleCheckChange">
</el-tree>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
</v-full-layout>
</template>
<script>
import '../../assets/spritesmith-generated/sprite.css'
import store from '../../vuex/store.js'
import remoteLoad from 'utils/remoteLoad.js'
import mapService from 'utils/mapService.js'
import 'utils/mapEvent.js'
import EventBus from '../../event-bus'
import {services} from '../../api'
import mock from '../../mock'
const MONITOR_SERVICE = services.monitor;
import {CONSTANT} from '../../constant'
import MapControll from './MapControll.vue'
import {exportExcel} from 'utils'
export default{
data(){
let checkFilename = (rule, vaule, cb)=>{
if(this.form.filename === ''){
cb('')
}
cb()
}
return {
AMap: null,
mapObj: null,
mapLoading: false,
isInitMap: false,
flag:false,
searchText: '',//65MA08605HG349105 75108160001 1510112899
searchType: '2',
isSearching: false,
monitorFilterType: '',
resultFilterType: '',
importDialogHidden: true,
listDialogHidden: true,
resultDialogHidden: true,
resultList: [],
monitorList: {
count: 0,
itemArr: []
},
importing: false,
form: {
uploadType: '1',
filename: '',
},
rules: {
//filename: [{validator: checkFilename, trigger: 'change'}],
},
uploadData: {},
remainSearchSnStr: '',
refreshCount: 1,
resetRefreshCount: false,
autoOpenLastInfoWindow: false,
treeHidden: false,
treeProps: {
label: 'label',
children: 'children',
isLeaf: 'leaf',
['node-key']: 'id'
},
treeData: [],
expandedKeys: [],
isTreeChecked: false,
checkedKeys: [],
autocompleteHide: true,
treeLoading: true,
}
},
computed:{
'uploadDisabled'(){
return this.form.filename === ''
},
getMonitorListVisibleCount(){
if(this.monitorFilterType === ''){
return this.monitorList.count
}else{
let count = 0;
for(let key in this.monitorList){
if(key !== 'count' || key !== 'itemArr'){
if(this.monitorList[key].source == this.monitorFilterType){
count++;
}
}
}
return count;
}
}
},
watch: {
'monitorFilterType'(newVal){
EventBus.$emit('uiMap.monitor.changeSourceType', newVal);
},
searchType() {
if(this.searchText) {
this.searchSubmit()
}
}
},
methods: {
renderTreeContent(h, { node, data, store }) {
if(data.leaf) {
return h('div', {class: 'custom-tree-node'},[
h('div', {
domProps: {
innerHTML: '姓名:'+node.data.label1||'--'
}
}),
h('div', {
domProps: {
innerHTML: '设备号:'+node.data.label
}
}),
h('div', {
domProps: {
innerHTML: '车架号:'+node.data.label2
}
})
])
}
return h('span', {
domProps: {
innerHTML: node.data.label
}
})
},
getTreeData() {
MONITOR_SERVICE.getVehicleTree().then(({data})=>{
this.treeLoading = false
this.treeData = data
})
},
handleCheckChange(data, checked, indeterminate) {
//console.log(data, checked, indeterminate);
if(checked) {
//console.log(this.$refs.tree.getNode(data))
let node = this.$refs.tree.getNode(data)
console.log(indeterminate)
//this.getAllChild(node)
//this.$refs.tree.store.defaultExpandAll = true
//this.$refs.tree.setCheckedKeys(['u8121'])
}
this.isTreeChecked = checked
this.expandedKeys = []
},
handleCheck(data, node) {
console.log('node', data)
if(data.leaf) {
const item = {
sn: data.label,
name: data.label1,
standNo: data.label2,
online: data.online,
id: data.id,
source: data.source==='有线'?'1':'0',
sourceType: data.source
}
if(this.isTreeChecked) {
this.addMonitor(item)
}else{
this.removeMonitor(item)
}
} else {
if(this.isTreeChecked) {
this.$confirm('当所选分组包含车辆过多时,请尝试分多次查询,以防等待时间过久。', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.checkFlow(data,node)
})
}else{
this.checkFlow(data,node)
}
}
},
checkFlow(data, node) {
let action = MONITOR_SERVICE.getVehicleTreeUserIds
let params = {oId: data.id}
if(data.origin.type === 'u') {
action = MONITOR_SERVICE.getVehicleTreeUserList
params = {uId: data.id}
}
this.treeLoading = true
action(params).then((res)=>{
this.treeLoading = false
let items = []
if(!res.tips) {
items = res.data.map((item)=>{
return {
sn: item.label,
name: item.label1,
standNo: item.label2,
online: item.online,
id: item.id,
source: item.source==='有线'?'1':'0',
sourceType: item.source
}
})
}else {
if(this.isTreeChecked) {
this.$message({
type: 'info',
message: res.tips
});
this.$refs.tree.setChecked(data, false)
if (data.children !== undefined) {
data.children.forEach((item, i) => {
this.$refs.tree.setChecked(item, false, true)
})
}
}
}
if(items.length) {
if(this.isTreeChecked) {
this.addMonitorByGroup(items)
}else{
this.removeMonitorByGroup(items)
}
}
})
},
getAllChild(node) {
if(node.childNodes.length === 0 && !node.data.test) {
let nodeData = node.data
let origin = nodeData.origin
if(nodeData.children) {
if(nodeData.children.length) {
nodeData.children.forEach((item)=>{
this.$refs.tree.append(item, node)
let childNode = this.$refs.tree.getNode(item)
this.getAllChild(childNode)
})
node.data.test = true
}else {
if(origin.type === 'u') {
console.log('u')
MONITOR_SERVICE.getVehicleTreeUserList({uId: nodeData.id}).then(({data})=>{
if(data.length) {
data.map((item)=>{
item.leaf = true
this.$refs.tree.append(item, node)
})
}
})
node.data.test = true
}
}
}
}
},
loadNode(node, resolve) {console.log(node);
const nodeData = node.data
const origin = nodeData.origin
if(nodeData.children){
if(nodeData.children.length) {
return resolve(nodeData.children)
}else {
if(origin.type === 'u') {
console.log('u')
MONITOR_SERVICE.getVehicleTreeUserList({uId: nodeData.id}).then(({data})=>{
if(data.length) {
data.map((item)=>{
item.leaf = true
})
return resolve(data)
}
return resolve([])
})
return;
}
}
}
return resolve([])
if (node.level === 0) {
return resolve([{ name: 'region1' }, { name: 'region2' }]);
}
if (node.level > 3) return resolve([]);
var hasChild;
if (node.data.name === 'region1') {
hasChild = true;
} else if (node.data.name === 'region2') {
hasChild = false;
} else {
hasChild = Math.random() > 0.5;
}
setTimeout(() => {
var data;
if (hasChild) {
data = [{
name: 'zone' + this.count++
}, {
name: 'zone' + this.count++
}];
} else {
data = [];
}
resolve(data);
}, 500);
},
initMap(){
let check = ()=>{
this.checkLoadedTimeoutId && window.clearTimeout(this.checkLoadedTimeoutId);
return setTimeout(()=>{
if('AMap' in window && typeof AMap.Map == 'function' && !this.mapObj){
window.AMap = AMap;
this.mapObj = mapService.init('map');
//this.bindEvent();
this.isInitMap = true;
if(this.$route.query.snArr){
let routeQuery = JSON.parse(this.$route.query.snArr);
if(routeQuery.length>0){
/* this.addMonitor(routeQuery[0]);
this.autoOpenLastInfoWindow = true; */
routeQuery.forEach((item)=>{
this.addMonitor(item);
})
this.autoOpenLastInfoWindow = true;
this.listDialogHidden = false
}
}
if(this.$route.query.vin){
MONITOR_SERVICE.getVehicleTree({
termType: 2,
term: this.$route.query.vin,
returnTrees: true
}).then((res)=>{
const items = res.data
this.expandTreeItems(items)
})
this.treeHidden = true
}
}else{
this.checkLoadedTimeoutId = check()
}
}, 100)
}
this.checkLoadedTimeoutId = check();
},
keyupSubmit(){
document.onkeydown=e=>{
let _key=window.event.keyCode;
if(_key===13){
this.searchSubmit()
}
}
},
searchSubmit(){
/* this.addMonitor({
sn: '75108160001'
})
return */
//if(!this.searchText) return;
switch(this.searchType){
case '1':
case '2':
case '4':
let relObj = {
'1': '设备号',
'2': '车架号',
'4': '工单号'
}
if(this.searchText.length<6){
this.$message({
type: 'error',
message: `请输入至少6位的${relObj[this.searchType]}`
});
return;
}
break;
case '3':
if(this.searchText.length<2){
this.$message({
type: 'error',
message: '请输入至少2位的姓名'
});
return;
}
break;
}
this.isSearching = true;
this.$refs.autocomplete.activated = true
this.$refs.autocomplete.getData(this.searchText)
/* MONITOR_SERVICE.getVehicleDeviceList({
term: this.searchText,
type: this.searchType
}).then((res)=>{
//res = mock.getCriteriaTreeList
if(res.returnCode == 0){
const data = res.data;
this.resultList = data;
this.resultDialogHidden = false;
this.importDialogHidden = true;
this.listDialogHidden = true;
this.isSearching = false;
if(data.length === 1){
this.addMonitor(data[0]);
this.autoOpenLastInfoWindow = true;
}else if(this.hasSameStandNo(data)){
this.addMonitorByGroup()
this.autoOpenLastInfoWindow = true;
}
}
}); */
},
querySearch(queryString, cb) {
this.autocompleteHide = true
if(this.isSearching) {
MONITOR_SERVICE.getVehicleTree({
termType: this.searchType,
term: this.searchText,
}).then((res)=>{
this.isSearching = false;
cb(res.data)
if(!res.data.length) {
cb([{
tip: '无数据'
}])
}
this.autocompleteHide = false
})
}
},
handleSelect(item) {
if(!item.tip) {
MONITOR_SERVICE.getVehicleTree({
termType: 1,
term: item.label,
returnTrees: true
}).then((res)=>{
const items = res.data
this.expandTreeItems(items)
})
}
},
expandTreeItems(arr, isDevice) {
arr.forEach((item)=>{
if(isDevice) {
this.$refs.tree.setCheckedKeys(this.$refs.tree.getCheckedKeys().concat(item.id))
this.addMonitor({
sn: item.label,
name: item.label1,
standNo: item.label2,
online: item.online,
id: item.id,
source: item.source==='有线'?'1':'0',
sourceType: item.source
})
} else {
this.expandedKeys.push(item.id)
}
if(item.children &&item.children.length) {
this.expandTreeItems(item.children, item.origin.type === 'u'?true:false)
}
/* else{
if() {
this.checkedKeys.push(item.id)
}
} */
})
},
hasSameStandNo(arr){
let isSame = true;
for(let i=0,len=arr.length; i<len-2; i++){
if(arr[i].standNo !== arr[i+1].standNo){
isSame = false;
break;
}
}
return isSame
},
/*searchSubmit(){
console.log(mock.getMonitorDataByGroup)
EventBus.$emit('uiMap.monitor.draw', mock.getMonitorDataByGroup)
},*/
successUpload(res){
this.importing = false;
if(typeof res === 'object'){
if(res.returnCode == 0){
const data = res.data;
this.resultList = data;
this.resultDialogHidden = false;
this.importDialogHidden = true;
setTimeout(()=>this.form.filename = '', 0);
//this.$refs.upload.clearFiles();
}else{
this.$message({
type: 'error',
message: res.message
});
setTimeout(()=>this.form.filename = '', 0);
}
}else{
window.location.href = '../ots/login';
}
},
submitUpload() {
this.$refs.form.validate((valid) => {
if(valid){
this.uploadData.type = this.form.uploadType
this.$refs.upload.submit();
}
})
},
changeFile(file, filelist) {
this.form.filename = file.name;
},
beforeUpload(file){
/*if(!/^.*\.(?:xlsx)$/.test(file.name)){
this.$message({
type: 'info',
message: '只能导入后缀为.xlsx的文件'
});
return false
}*/
if(file.name == this.form.filename){
this.importing = true;
return true
}
return false
},
addMonitor(item){
if(this.monitorList.count === 100){
this.$message({
type: 'error',
message: '监控设备数最大100台,无法添加'
});
}else{
if(this.monitorList[item.sn]){
this.$message({
type: 'error',
message: '该列表中有设备正在监控中,请勿重复监控'
});
}else{
this.resetRefreshCount = true;
this.monitorList.count++;
item.eLocateType = 'gpsLocation'
this.monitorList[item.sn] = item;
this.monitorList.itemArr.unshift(item.sn)
this.getPositionData();
}
}
},
standNoMonitor(item){
this.resetRefreshCount = true;
this.monitorList.count++;
for (let i in item) {
this.monitorList[item.sn] = item[i].sn;
}
this.getPositionData();
},
addMonitorByGroup(items){
if(this.resultList.length>100-this.monitorList.count){
this.$message({
type: 'error',
message: '监控设备数最大100台,无法添加'
});
}else{
/* let findExistItem = this.resultList.find((item)=>this.monitorList[item.sn]);
if(findExistItem){
this.$message({
type: 'error',
message: '该列表中有设备正在监控中,请勿重复监控'
});
}else{
this.resetRefreshCount = true;
this.resultList.forEach((item)=>{
this.monitorList[item.sn] = item;
this.monitorList.count++;
//EventBus.$emit('uiMap.monitor.draw', item);
});
this.getPositionData(this.resultList)
} */
let filterList = items.filter((item)=>{
return !this.monitorList[item.sn]
});
filterList.forEach((item)=>{
item.eLocateType = 'gpsLocation'
this.monitorList[item.sn] = item;
this.monitorList.count++;
this.monitorList.itemArr.unshift(item.sn)
});
this.getPositionData()
}
},
removeMonitor(item, ifUpdateTreeKeys){
delete this.monitorList[item.sn];
this.monitorList.itemArr.splice(this.monitorList.itemArr.indexOf(item.sn), 1)
this.monitorList = Object.assign({}, this.monitorList);
this.monitorList.count--;
EventBus.$emit('uiMap.monitor.destroy', `${item.sn}:${item.source}`);
if(ifUpdateTreeKeys) {
console.log(item)
let checkedKeys = this.$refs.tree.getCheckedKeys()
let arr = checkedKeys.filter((id)=>id!==item.id)
console.log(arr)
this.$refs.tree.setCheckedKeys(arr)
}
},
removeMonitorByGroup(arr){
arr.forEach((item)=>{
if(this.monitorList[item.sn]) {
this.removeMonitor(item)
}
})
},
getPositionData(arr){
/* let _this = this;
arr = arr.filter((item)=>this.monitorList[item.sn]); */
let snStr = this.monitorList.itemArr.join(',');//arr.map((item)=>item.sn).join(',');
if(!snStr) return;
if(this.resetRefreshCount || this.remainSearchSnStr != snStr){
this.refreshCount = 1;
}else{
this.refreshCount++;
}
this.resetRefreshCount = false;
this.remainSearchSnStr = snStr;
MONITOR_SERVICE.getDevicesLocation({
sns: snStr,
deviceCode: 'gps',
//refreshCount: this.refreshCount
}).then((res)=>{
if(res.code == 200){
//this.monitorList['1570222001'].isOnLine = true;
const data = res.data;
if(data.length){
data.forEach((item)=>{
let relItem = this.monitorList[item.sn];
if(relItem){
relItem.isOnLine = item.status === 2? false: true;
relItem.isHasPosition = true;
item.name = relItem.name;
item.standNo = relItem.standNo;
}
item.eLocateType = relItem.eLocateType
item = this.filterGpsBase(item)
item.isSource = relItem.source
});
this.monitorList = Object.assign({}, this.monitorList);
let drawData = data.filter((item)=>(this.monitorList.itemArr.indexOf(item.sn)>-1)&&item.eLocateType)
this.monitorList.count && EventBus.$emit('uiMap.monitor.draw', drawData, this.autoOpenLastInfoWindow);
if(this.autoOpenLastInfoWindow){
this.autoOpenLastInfoWindow = false;
}
this.isSearching = false;
}else{
this.drawDoneCb();
}
}
});
},
filterGpsBase(item){
//item.bsLocation = {}
let gpsLocation = item.gpsLocation
let bsLocation = item.bsLocation
/* 如果基站,gps其中一个没数据,自动切换到另一个,如果都没有eLocateType为null */
if(item.eLocateType === 'gpsLocation' && (!gpsLocation || !gpsLocation.elng || !gpsLocation.elat)){
if(bsLocation && bsLocation.elng && bsLocation.elat){
item.eLocateType = 'bsLocation'
}else{
item.eLocateType = null
}
}else if(item.eLocateType === 'bsLocation' && (!bsLocation || !bsLocation.elng || !bsLocation.elat)){
if(gpsLocation && gpsLocation.elng && gpsLocation.elat){
item.eLocateType = 'gpsLocation'
}else{
item.eLocateType = null
}
}
if(item.eLocateType === 'gpsLocation' && (!bsLocation || !bsLocation.elng || !bsLocation.elat)){
item.eLocateSingle = true
}else if(item.eLocateType === 'bsLocation' && (!gpsLocation || !gpsLocation.elng || !gpsLocation.elat)){
item.eLocateSingle = true
}
if(!item.eLocateSingle){
if(moment(gpsLocation.dateTime).isAfter(moment(bsLocation.dateTime))){
item.eLocateType = 'gpsLocation'
}else{
item.eLocateType = 'bsLocation'
}
}
return item
},
errorUpload(err){
console.log(err)
//window.location.href = '../ots/login';
},
drawDoneCb(){
console.log('drawDoneCb')
this._drawTimeoutId && window.clearTimeout(this._drawTimeoutId);
/* let arr = [];
for(let key in this.monitorList){
if(key !== 'count'){
arr.push(this.monitorList[key])
}
} */
this._drawTimeoutId = setTimeout(()=>{
this.getPositionData()
}, 10*1000)
},
terminate(){
this._drawTimeoutId && window.clearTimeout(this._drawTimeoutId);
},
openMapInfoWindow(sn, source){
EventBus.$emit('uiMap.monitor.openInfoWindow', `${sn}:${source}`)
},
downloadTpl(){
exportExcel('vehicle/downLoadImportSearchModel')
},
changeELocate(item){
this.monitorList[item.sn].eLocateType = item.eLocateType
//item.eLocateType = item.eLocateType==='gpsLocation'?'bsLocation':'gpsLocation'
}
},
created () {
if(window.AMap){
this.initMap();
}else{
remoteLoad(`${CONSTANT.AMAP_URL}`).then(()=>{
remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(()=>{
this.initMap();
})
})
}
this.keyupSubmit();
EventBus.$on('uiMap.monitor.drawDone', this.drawDoneCb);
EventBus.$on('uiMap.monitor.changeELocate', this.changeELocate);
EventBus.$on('uiMap.monitor.terminate', this.terminate);
this.getTreeData()
},
beforeDestroy(){
EventBus.$emit('uiMap.monitor.destroy');
EventBus.$off('uiMap.monitor.drawDone', this.drawDoneCb);
this._drawTimeoutId && window.clearTimeout(this._drawTimeoutId);
this.checkLoadedTimeoutId && window.clearTimeout(this.checkLoadedTimeoutId);
},
components: {
MapControll
}
}
</script>
<style scoped>
/*样式写在 scss/monitor.scss*/
.none_tip{
align-self: center;
font-size: 12px;
color: red;
padding: 0 5px;
}
</style>
<style>
.el-tree-node__content{
height: auto;
padding: 2px;
}
.custom-tree-node {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
font-size: 12px;
padding-right: 8px;
line-height: 26px;
}
.map-wrap .el-tree-node > .el-tree-node__children {
overflow: visible;
}
.search_auto{
font-size: 12px;
}
.search_auto_hide{
display: none;
}
.search_auto .el-autocomplete-suggestion li{
padding: 0;
}
.search_auto .el-autocomplete-suggestion li div{
line-height: 20px;
}
.el-autocomplete-suggestion li{
border-bottom: 1px solid #eee;
padding-bottom: 4px;
}
.el-autocomplete-suggestion li:last-child{
border-bottom: none;
}
.full-width .main-wrap.full-width{
left: 0;
width: 100%;
}
</style>