YtContronByVionVideo.js
66.6 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
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
var isNavigating = false; //球机是否在巡航
var CameraSpeed = 10
/**
* 云台操作类,这里方法为视频OCX提供
* @author tramp
* @dateTime 2016 08 10
* @version 0.0.1
*
*/
/**
* 球机可提供的操作
* @author tramp
* @type {Object}
*/
var pzOperateType = {
/* 云台以SS的速度上仰 */
"V_PANTILT_UP": 0,
/* 云台以SS的速度下俯 */
"V_PANTILT_DOWN": 1,
/* 云台以SS的速度左转 */
"V_PANTILT_LEFT": 2,
/* 云台以SS的速度右转 */
"V_PANTILT_RIGHT": 3,
/* 云台以SS的速度右上转*/
"V_PANTILT_RIGHT_UP": 4,
/* 云台以SS的速度右下转 */
"V_PANTILT_RIGHT_DOWN": 5,
/* 云台以SS的速度左上转 */
"V_PANTILT_LEFT_UP": 6,
/* 云台以SS的速度左下转 */
"V_PANTILT_LEFT_DOWN": 7,
/* 焦距以速度SS变大(倍率变大) */
"V_ZOOM_IN": 8,
/* 焦距以速度SS变小(倍率变小) */
"V_ZOOM_OUT": 9,
/*云台停止运动*/
"V_STOP": 10
};
/**
* 设置云台转速
* @param {*} val
*/
function setCameraSpeed(val){
CameraSpeed = val;
}
function getControlParam(code) {
var param;
switch (code) {
case "36":
param = "V_PANTILT_LEFT_UP";
break;
case "38":
param = "V_PANTILT_UP";
break;
case "33":
param = "V_PANTILT_RIGHT_UP";
break;
case "37":
param = "V_PANTILT_LEFT";
break;
case "12":
param = "V_PANTILT_LEFT"; //没有巡航,用想做运动代替
break;
case "39":
param = "V_PANTILT_RIGHT";
break;
case "35":
param = "V_PANTILT_LEFT_DOWN";
break;
case "40":
param = "V_PANTILT_DOWN";
break;
case "34":
param = "V_PANTILT_RIGHT_DOWN";
break;
case "109":
param = "V_ZOOM_IN";
break;
case "107":
param = "V_ZOOM_OUT";
break;
default:
param = "V_STOP";
break;
}
return param;
}
//操作设备的次数
var count = 0;
/**
* 控制设备
* @author tramp
* @DateTime 2016-09-13
* @param {[type]} var szCmd 控制参数
* @param {[type]} int speed 速度
* @param {[type]} string para_string 预留
* @return {[type]} [description]
*/
function controlDevice(szCmd) {
var re = controlDeviceOnce(szCmd);
if (re == 1) {
// count = 0;
return true;
} else {
return false;
// if (count < 5) {
// count++;
// return controlDevice(szCmd);
// }
// else {
// return false;
// }
}
}
/**
* 控制设备 单次
* @author tramp
* @DateTime 2016-09-13
* @param {[type]} var szCmd 控制参数
* @param {[type]} int speed 速度
* @param {[type]} string para_string 预留
* @return {[type]} [description]
*/
function controlDeviceOnce(szCmd) {
var i = VionVideo.PtzSendCmd(szCmd, CameraSpeed, "");
console.log(i)
return i;
}
/**
* 是否正在控制球机
* @type {Boolean}
*/
var controlIng = false;
/**
* 开始控制球机
* @author tramp
* @DateTime 2016-08-11
* @param {event} evt 鼠标事件
*/
function ControlCameraWithMouse(evt) {
if (!isUseYT) {
var controlCode = getControlParam($(this).attr("data-code"));
if (!enableAction(controlCode)) {
return null;
}
controlDevice(controlCode);
}
}
/**
* 停止控制球机
* @author tramp
* @DateTime 2016-08-11
* @param {event} evt 鼠标事件
*/
function StopControlCamera(evt) {
controlIng = false;
controlDevice("V_STOP");
}
/**
* 临时方法,如果为右上,左上,右下,左下,则返回false,
* 原因是,董文佳提供的云台控制控件不支持左上等;
* @author tramp
* @DateTime 2016-08-15
* @param {string} controlCode 操作码
* @return {bool} 是否支持操作
*/
function enableAction(controlCode) {
var enable = true;
// /* 云台以SS的速度右上转*/
// "V_PANTILT_RIGHT_UP": 4,
// /* 云台以SS的速度右下转 */
// "V_PANTILT_RIGHT_DOWN": 5,
// /* 云台以SS的速度左上转 */
// "V_PANTILT_LEFT_UP": 6,
// /* 云台以SS的速度左下转 */
// "V_PANTILT_LEFT_DOWN": 7,
// if (controlCode == "V_PANTILT_RIGHT_UP" || controlCode == "V_PANTILT_RIGHT_DOWN" ||
// controlCode == "V_PANTILT_LEFT_UP" || controlCode == "V_PANTILT_LEFT_DOWN") {
// enable = false;
// }
return enable;
}
/**
* 球机巡航
* @author tramp
* @DateTime 2016-09-13
* @return {[type]} [description]
*/
function toggleCameraNavigate() {
//alert(isNavigating);
//进行相应的控制
if (isNavigating) {
isNavigating = !StopControlCamera();
} else {
isNavigating = controlDevice("V_PANTILT_LEFT");
}
updateNavigateIcon();
}
/**
* 停止球机巡航
* @author tramp
* @DateTime 2016-09-13
* @return {[type]} [description]
*/
function stopCameraNavigate() {
if (isUseYT) {
isNavigating = !StopControlCamera();
updateNavigateIcon();
}
}
/**
* 更新球机巡航图标
* @author tramp
* @DateTime 2016-09-13
* @return {[type]} [description]
*/
function updateNavigateIcon() {
var navBtnObj = $(".cameraControl3");
//更新图标
if (isNavigating) {
navBtnObj.addClass("nav_activited");
} else navBtnObj.removeClass("nav_activited");
}
/**
* 对隐藏域中的相机信息进行赋值
* @author tramp
* @DateTime 2016-08-16
* @param String companyNum 公司代码
* @param {String} camIp 相机IP
* @param {String} port 相机端口号
* @param {String} nodeChannel 通道号
* @param {String} username 相机用户名
* @param {String} pwd 相机密码
* @param {String} id 相机标示
*/
function setCameraInfoForPTZ(companyNum, camIp, port, nodeChannel, username, pwd, id) {
$("#companyNum").val(companyNum);
$("#cameraIp").val(camIp);
$("#port").val(port);
$("#cameraChannel").val(nodeChannel);
$("#username").val(username);
$("#pwd").val(pwd);
$("#id").val(id);
}
/**
* 是否在控制云台
* @type {Boolean}
*/
var isUseYT = false;
/**
* 连接相机
* @author tramp
* @DateTime 2016-09-13
* @param {[type]} var szDeviceIp 相机IP
* @param {[type]} var szUser 用户名
* @param {[type]} var szPass 密码
* @return {[type]} [description]
*/
function connectCamera(szDeviceIp, szUser, szPass, camType) {
// $.ajax({
// url: '../../Ashx/Vion/Backstage/Video/pzControlHelp.ashx',
// type: 'POST',
// dataType: 'json',
// data: {
// companyNum: $("#companyNum").val(),
// camip: $("#cameraIp").val(),
// port: $("#port").val(),
// channel: $("#cameraChannel").val(),
// username: $("#username").val(),
// pwd: $("#pwd").val(),
// id: $("#id").val(),
// operation: "connect"
// }
// }).done(function() {
// console.log("success");
// }).fail(function() {
// console.log("error");
// }).always(function() {
// console.log("complete");
// });
var i = 0;
debugger
switch (camType) {
case "0":
console.log("");
break;
case "-1":
console.log("未找到目标相机");
break;
case "rifle":
console.log("枪机无云台操作");
break;
case "ball":
i = VionVideo.PtzRegistDev(szDeviceIp, szUser, szPass);
console.log('云台连接状态:'+i)
if (i == 1) {
return true;
} else {
console.log("连接云台失败");
return false;
}
break;
default:
i = VionVideo.PtzRegistDev(szDeviceIp, szUser, szPass);
if (i == 1) {
return true;
} else {
console.log("连接云台失败");
return false;
}
break;
}
}
//========================辅助公共方法====================================
/*
* 隐藏ocx
* @author tramp
*/
function hideVideoOcxDiv() {
$("#VionVideo").hide();
}
/**
* 打开OCX
* @author tramp
* @DateTime 2016-08-10
* @return {void}
*/
function showVideoOcxDiv() {
$("#VionVideo").show();
}
/*
* 隐藏ocx
* @author tramp
*/
function hideOcxDiv() {
$("#VionVideo").hide();
}
/**
* 打开OCX
* @author tramp
* @DateTime 2016-08-10
* @return {void}
*/
function showOcxDiv() {
$("#VionVideo").show();
}
/**
* 弹窗程序,封装的目的是:这里的弹窗都需要隐藏OCX
* @author tramp
* Date 2016 08 10
* @param {string} msg 弹窗中的信息
* @return {void}
*/
function showMessagerInfo(msg, callback) {
this.hideVideoOcxDiv();
$.messager.alert("提示", msg, "info", function () {
this.showVideoOcxDiv();
if (typeof callback === "function") {
callback();
}
});
}
/**
* 错误弹窗封装,目的是封装隐藏和显示OCX
* @author tramp
* date 2016 08 10
*/
function showMessageError(msg, callback) {
this.hideVideoOcxDiv();
$.messager.alert("错误", msg, "error", function () {
this.showVideoOcxDiv();
if (typeof callback === "function") {
callback();
}
});
}
//显示登录窗口,并调用注册权限的方法,30秒后超时
function showPermissionLoginWindow() {
//隐藏OCX插件
hideVideoOcxDiv();
//设置用户权限信息
var progressOptions = {
title: "提示",
msg: "权限申请中,请稍候..."
};
$.messager.progress(progressOptions);
var setPermission = SetPermission(pServerIP, pServerPort, loginedUserName, loginedUserPass);
regPermissionTimeoutTimer = setTimeout(showReloginConfirm, 30000, "连接超时,是否重试?");
}
/**
* 设置当前登录用户的权限信息
* @author tramp
* @DateTime 2016-08-11
* @param {string} serverIP 接收服务器IP
* @param {string} serverPort 接收服务器端口
* @param {string} loginedUserName 已登录用户的用户名
* @param {string} loginedUserPass 已登录用户的密码
* @return {number} 0 -- 失败,1 -- 成功
*/
function SetPermission(serverIP, serverPort, loginedUserName, loginedUserPass) {
return trafficOcxObj.PermissionLogin(serverIP, serverPort, loginedUserName, loginedUserPass) == 1;
}
/**
* 显示重新登录确认框
* @author tramp
* @DateTime 2016-08-11
* @param {[type]} msg [description]
* @return {[type]} [description]
*/
function showReloginConfirm(msg) {
try {
$.messager.progress("close");
} catch (e) { }
if (!msg) {
msg = "连接超时,是否重新连接?";
} else {
msg = "出现错误:" + msg + ",是否重新连接?";
}
$.messager.confirm("提示", msg, function (r) {
if (r) {
showPermissionLoginWindow();
} else {
this.hideVideoOcxDiv();
$.messager.alert('错误', '注册权限失败!', 'error', function () {
this.showVideoOcxDiv();
});
}
});
}
/**
* 处理登录返回的结果,在登录窗口中显示
* @author tramp
* @DateTime 2016-08-11
* @param {[type]} resultCode OCX返回值
* @return {[type]} [description]
*/
function processLoginResult(resultCode) {
var message;
//关闭登录提示窗口
$.messager.progress('close');
clearTimeout(regPermissionTimeoutTimer); //清空超时对话框定时器
switch (resultCode) {
case -1:
message = "网络连接超时!";
break;
case 0:
message = "申请成功!";
isRegPermissionSuccess = true;
this.showVideoOcxDiv(); //显示OCX控件
//设置默认的权限时间
SetPermissionTime(defaultKeepPermissionInterval);
break;
case 1:
message = "向中心注册失败!";
break;
case 2:
message = "登录服务器失败";
break;
case 3:
message = "查询设备个数失败";
break;
case 4:
message = "查询设备信息失败";
break;
default:
message = "";
break;
}
//regPermissionMessage = message;
//如果网络连接超时,提示重新登录
if (resultCode != 0) {
showReloginConfirm(message);
}
/*
方法说明:
*/
/**
* 设置默认的权限申请时间
* @author tramp
* @DateTime 2016-08-11
* @param {number} interval 默认的权限时间
*/
function SetPermissionTime(interval) {
try {
return trafficOcxObj.SetPermissionTime(interval) == 1;
} catch (e) { }
}
//=========================================================================================
//
}
/**
* 视频事件处理器
* @author tramp
* @DateTime 2016-10-11
* @return {[type]} [description]
*/
function VideoEventHandle() {
this.Screenshot = function (imgPath) {
if (imgPath == "" || imgPath == null) {
return;
}
captureFlowManager.captureImageHandle(imgPath);
}
}
/**
* 根据本地路径获取图片并存放到后台,返回后台路径
* @author tramp
* @DateTime 2016-10-13
* @param {[type]} imgPath [description]
* @return {[type]} [description]
*/
function saveImageBase64(imgPath, cameraId) {
var imgBase64 = VionVideo.GetBase64DataByPath(20480000, imgPath);
var serverPath = "";
$.ajax({
url: 'RealTimeVideoWithYT.aspx?param=saveImage',
type: 'post',
dataType: 'json',
async: false,
data: {
imgBase64: imgBase64,
cameraId: cameraId
},
success: function (data) {
if (data.success) {
serverPath = data.imgPath;
} else {
serverPath = "";
}
}
});
imgBase64 = null;
endTime();
startTime();
return serverPath;
}
/**
* 开始计时
* @author tramp
* @DateTime 2016-10-13
*/
function startTime() {
VionVideo.SetParam("VideoShowTimer", "ON")
}
/**
* 停止计时
* @author tramp
* @DateTime 2016-10-13
*/
function endTime() {
VionVideo.SetParam("VideoShowTimer", "OFF")
}
//================================类变量声明==============================================
//================================类变量声明==============================================
/**
* 抓拍流程管理类
* @author tramp
* @DateTime 2016-10-12
*/
function CaptureFlowManager() {
var isCaptureIng = true;
var videoRecordTimeoutTimer = null; //检查录像时间是否超时的定时器
var videoRecordTimeout = 60; //录像超时时间,单位秒
var nextCaptureFrameId = null; //下个抓拍框的ID
var timerTime = 20000; //定时器间隔时间
var ocxForCapture; //抓拍控件的引用,这里需要测试是否能够识别
this.outPutPath = "C:\\temp";
var captureResultMap = new Map(); //存储已经抓到的图片的信息,以相机的id作为索引,因为不同窗口中可能会播放同一个相机
var captureResultIndex = ""; //当前处理中的抓拍结果的索引
var captureCameraAttribute; //当前抓拍的相机的属性信息
var msgInfo; //信息弹出函数;
var msgError; //错误弹出函数;
var imgBase64Handle; //base64的图片进行处理,返回一个图片的http路径
var pictureHandle; //对获得的图片处理的函数,需要外部初始化;
var deletePictureHandle; //删除图片处理函数;
var submitHandle; //提交图片请求
var isAccept = true;
var attributeHandle; //属性信息输入函数
var uploadingHandle; //上传处理器
//==================================需要初始化的方法=================================================
/**
* 设置OCX控件,这里为了防止OCX控件的ID变化导致本类中所有的id都改变,但是这里需要测试是否可行
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} ocx [description]
*/
this.setOcxForCapture = function (ocx) {
ocxForCapture = ocx;
}
/**
* 设定录像超时时间
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} rtime [description]
*/
this.setVideoRecordTimeout = function (rtime) {
videoRecordTimeout = rtime;
}
/**
* 设置信息弹窗程序
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} fun [description]
*/
this.setMsgInfo = function (fun) {
msgInfo = fun;
}
/**
* 设置错误弹窗程序
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} fun [description]
*/
this.setMsgError = function (fun) {
msgError = fun;
}
/**
* 设置Base64图片处理器
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} handle [description]
*/
this.setImgBase64Handle = function (handle) {
imgBase64Handle = handle;
}
/**
* 图片处理器,主要用作显示或者影响其他标签的操作
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} handle [description]
*/
this.setPictureHandle = function (handle) {
pictureHandle = handle;
}
/**
* 设置删除图片程序
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} handle [description]
*/
this.setDeletePictureHandle = function (handle) {
deletePictureHandle = handle;
}
/**
* 设置提交函数
* @author tramp
* @DateTime 2016-10-14
* @param {[type]} handle [description]
*/
this.setSubmitHandle = function (handle) {
submitHandle = handle;
}
/**
* 设置上传函数
* @author tramp
* @DateTime 2016-10-14
* @param {[type]} handle [description]
*/
this.setUploadingHandle = function (handle) {
uploadingHandle = handle;
}
/**
* 设置属性输入处理器
* @author tramp
* @DateTime 2016-10-17
* @param {[type]} handle [description]
*/
this.setAttributeHandle = function (handle) {
attributeHandle = handle;
}
//==================================需要初始化的方法结束=================================================
//=====================外部调用操作类===============================
/**
* 开始抓图工作--作为备用
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
this.startCapture = function () {
isCaptureIng = true;
}
/**
* 停止抓图 -- 作为备用
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
this.stopCapture = function () {
isCaptureIng = false;
}
/**
* 提交
* @author tramp
* @DateTime 2016-10-14
* @param {[type]} submitType [description]
* @return {[type]} [description]
*/
this.submit = function (submitType) {
var captureResult = captureResultMap.get(captureResultIndex);
submitHandle(captureResult, submitType)
}
/**
* 上传
* @author tramp
* @DateTime 2016-10-14
* @param {[type]} submitType [description]
* @return {[type]} [description]
*/
this.uploading = function (submitType) {
var captureResult = captureResultMap.get(captureResultIndex);
return uploadingHandle(captureResult, submitType);
}
/**
* 执行抓图并返回存储的本地路径,js触发
* @author tramp
* @DateTime 2016-10-12
*/
this.capturePictureAndGetPath = function (channel) {
if (cameraid == null || cameraid == "") {
this.showMessageError("请选择相机");
return false;
}
var localPath = ocxForCapture.VideoCaptureAndGetPath(channel, "");
var imgSvrPath = imgBase64Handle(localPath);
this.showPicture(imgPath, imgSvrPath);
}
/**
* 响应截图事件
* @author tramp
* @DateTime 2016-10-13
* @param {[type]} imgPath [description]
* @param {[type]} channel [description]
* @return {Boolean} [description]
*/
this.captureImageHandle = function (imgPath) {
if (isAccept) {
var imgSvrPath = imgBase64Handle(imgPath, captureResultIndex);
showPicture(imgPath, imgSvrPath);
}
}
this.deleteImage = function (index) {
var captureResult = captureResultMap.get(captureResultIndex);
var serverPath;
var localPath;
if (captureResult != null && captureResult.cameraId != null) {
var imgPath = captureResult.deleteImage(index);
localPath = captureResult.getDeleteingImgLocalPath();
serverPath = captureResult.getDeleteingImgServerPath();
}
deletePictureHandle(localPath, serverPath, index);
this.setAccept();
}
/**
* 由得到图像的base64数据开始处理数据
* @author tramp
* @DateTime 2016-10-12
*/
function showPicture(localPath, svrPath) {
var captureResult = captureResultMap.get(captureResultIndex);
if (captureResult != null && captureResult.cameraId != null) {
// if (captureResult.cameraId == captureResultIndex) {
// //do nothing
// } else {
// this.Result.remove(captureResultIndex); //如果存储的通道号中的相机编号与新的不同,则直接置为空
// }
} else {
//开始在captureedMsgMap中创建新的内容
captureResult = new CaptureFlowSingle(captureResultIndex);
captureResult.cameraId = captureResultIndex;
captureResult.attribute = captureCameraAttribute;
captureResultMap.set(captureResultIndex, captureResult);
}
//开始添加
var re = captureResult.addImage(localPath, svrPath);
//captureResultMap.set(captureResultIndex, captureResult);
switch (re) {
case -1:
isAccept = false;
msgError("存储中已经存在图片,不能替换", this.setAccept);
break;
case -2:
isAccept = false;
msgError("图片数量总数最大值为:" + captureResult.maxPicture, this.setAccept);
break;
default:
pictureHandle(captureResult, "add", re, captureResultIndex);
break;
}
}
/**
* 设置可以接受图片信息
* @author tramp
* @DateTime 2016-10-14
*/
this.setAccept = function () {
isAccept = true;
}
/**
* 向管理器注册相机
* @author tramp
* @DateTime 2016-10-13
* @param {[type]} cameraid [description]
* @return {[type]} [description]
*/
this.registerCaptureFlow = function (cameraid, attribute) {
if (cameraid == null || cameraid == "undefined" || cameraid == "") {
return null;
}
var captureResult = captureResultMap.get(cameraid);
if (captureResult == null) {
captureResult = new CaptureFlowSingle(cameraid);
if (attribute != null) {
captureResult.attribute = attribute;
captureCameraAttribute = attribute;
}
}
pictureHandle(captureResult, "reset", "", cameraid);
captureResultIndex = cameraid;
captureResultMap.set(cameraid, captureResult);
this.setAccept();
return captureResult;
}
/**
* 改变显示窗口
* @author tramp
* @DateTime 2016-10-13
* @param {[type]} cameraId 相机ID
* @return {[type]} [description]
*/
this.changeChannel = function (cameraId, attribute) {
var captureResult = this.registerCaptureFlow(cameraId, attribute);
// pictureHandle(captureResult, "reset", "", cameraId);
// this.setAccept();
}
/**
* 取消某个相机的抓拍流程
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} channel [description]
* @return {[type]} [description]
*/
this.cancleFlow = function () {
var captureResult = captureResultMap.get(captureResultIndex);
if (captureResult != null && captureResult.cameraId != null) {
// for (var i = 1; i <= captureResult.getImagePathMap().size; i++) {
// var image = captureResult.getImagePathMap().get(i);
// deletePictureHandle(image.serverPath, i);
// };
captureResult.getImagePathMap().forEach(function (item, key) {
// var image = captureResult.getImagePathMap().get(i);
deletePictureHandle(item.localPath, item.serverPath, key);
});
//captureResultMap.delete(captureResultIndex);
captureResultMap.set(captureResultIndex, null);
}
this.setAccept();
endTime();
}
/**
* 取消单个流程中单个图片信息,俗称删除单个图片
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
this.cancleSinglePicture = function (channel, imgIndex) {
var captureResult = captureResultMap.get(channel);
if (captureResult != null && captureResult.cameraId != null) {
if (captureResult.nextCaptureImageIndex <= imgIndex) {
isAccept = false;
msgError("存储中未找到指定索引的图片", this.setAccept);
} else { }
} else {
isAccept = false;
msgError("并未存储本通道的信息!", this.setAccept);
}
this.setAccept();
}
/**
* 开始录像
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} cameraid 相机id
* @param {[type]} channel 播放器的播放通道号,即多屏状态下的屏幕号
* @return {[type]} [description]
*/
this.startVideoRecord = function (cameraid, channel) {
// body...
}
/**
* 停止录像
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} cameraid 相机id
* @param {[type]} channel 播放器的播放通道号,即多屏状态下的屏幕号
* @return {[type]} [description]
*/
this.stopVideoRecord = function (cameraid, channel) {
//333
}
/**
* 定时器处理程序,这里需要增加需要定时处理的任务
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} argument [description]
* @return {[type]} [description]
*/
//=====================外部调用操作类===============================
//=====================私有类===============================
function timerHandle(argument) {
// body...
//
// 超时的相机取消流程 需要提示;
// 超时的录像停止录像 不提示
}
/**
* 判断是否允许抓图
* @author tramp
* @DateTime 2016-10-12
* @return {Boolean} [description]
*/
function isEnableCapture() {
try {
if (!isCaptureIng) {
this.showMessagerInfo("未开启抓图功能");
return false;
} else {
return true;
}
} catch (e) {
alert("未设定信息处理函数");
}
}
/**
* 单个相机的抓拍流程关键信息类
* @author tramp
* @DateTime 2016-10-12
*/
function CaptureFlowSingle(cameraId) {
var obj = new Object();
var maxPictureCount = 4;
var isFull = false; //map是否已经满员;
obj.maxPicture = maxPictureCount;
obj.cameraId = cameraId; //流程相关的相机ID
//==========录像相关============
obj.isVideoRecordIng = false; //相机是否在录像;
obj.startTimeOfVideoRecord = null; //相机录像的开始时间
obj.attribute = null; //属性信息
/**
* 下一个需要抓拍的图片的序号,从1开始;
* @type {Number}
*/
var nextCaptureImageIndex = 1;
obj.imageCount = 0;
//===========图片相关============
var imagesPathMap = new Map();
/**
* 图像实体中存放的内容
* @author tramp
* @DateTime 2016-10-13
* @return {[type]} [description]
*/
function imgObj(localPath, serverPath) {
var o = {
localPath: localPath, //本地路径
serverPath: serverPath, //服务器路径
caputureTime: new Date() //抓拍时间
};
return o;
};
/**
* 获取图片操作
* @author tramp
* @DateTime 2016-10-13
* @return {[type]} [description]
*/
obj.getImagePathMap = function () {
// if (this.imagesPathMap.length == 0) {
// for (var i = 1; i <= this.maxPictureCount; i++) {
// imagesPathMap.put(i, new imgObj());
// }
// }
return imagesPathMap;
}
/**
* 对索引加1,如果返回错误,说明索引已经越界
* @author tramp
* @DateTime 2016-10-12
*/
function addIndex() {
if (nextCaptureImageIndex >= maxPictureCount) {
isFull = true;
} else {
var i = nextCaptureImageIndex + 1;
while (imagesPathMap.get(i) != null && i <= maxPictureCount) {
i++;
}
if (i > maxPictureCount) {
isFull = true;
} else {
isFull = false;
}
nextCaptureImageIndex = i;
}
}
/**
* 添加抓拍结果
* @author tramp
* @DateTime 2016-10-13
* @param {[type]} localPath [description]
* @param {[type]} serverPath [description]
*/
obj.addImage = function (localPath, serverPath) {
if (isFull) {
return -2;
} else {
var captureResult = new imgObj(localPath, serverPath);
if (imagesPathMap.get(nextCaptureImageIndex) == null) {
var thisIndex = nextCaptureImageIndex;
imagesPathMap.set(thisIndex, captureResult);
this.imageCount++;
addIndex();
return thisIndex;
} else {
return -1; //如果存储中已经存在图片,说明有问题,直接返回错误;
};
}
}
var deleteingImgLocalPath;
var deleteingImgServerPath;
obj.deleteImage = function (imageIndex) {
var index = Number(imageIndex);
if (imagesPathMap.get(index) != null) {
var path = imagesPathMap.get(index).serverPath;
deleteingImgLocalPath = imagesPathMap.get(index).localPath;
deleteingImgServerPath = imagesPathMap.get(index).serverPath;
//imagesPathMap.delete(index);
imagesPathMap.set(index, null);
if (nextCaptureImageIndex >= index) {
nextCaptureImageIndex = index;
}
this.imageCount--;
isFull = false;
return path;
}
return "";
}
obj.getDeleteingImgLocalPath = function () {
return deleteingImgLocalPath;
}
obj.getDeleteingImgServerPath = function () {
return deleteingImgServerPath;
}
return obj;
}
//=====================私有类结束===============================
}
/**
* ocx窗口管理程序;
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
function OcxWindowsManager() {
var windowsElementMap = new Map(); //窗口信息的集合,其中以窗口channel为索引
var windowSelectedIndex = 1; //选择的窗口索引
var getCameraModel;
/**
* 获取摄像机信息的方法,需要初始化
* @author tramp
* @DateTime 2016-10-13
* @param {[type]} fun [description]
*/
this.setGetCameraModelFunction = function (fun) {
this.getCameraModel = fun;
}
/**
* 获取正在播放的窗口的索引
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
this.getSelectedIndex = function () {
return this.windowSelectedIndex;
}
/**
* 根据播放窗口索引获取窗口实体数据
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} index [description]
* @return {[type]} [description]
*/
this.getElementByIndex = function (index) {
return this.windowsElementMap[index];
}
/**
* 根据摄像机ID获取窗口实体数据
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} cameraid [description]
* @return {[type]} [description]
*/
this.getElementByCameraId = function (cameraid) {
for (var key in this.windowsElementMap) {
if (this.windowsElementMap[key] == cameraid) {
return this.windowsElementMap[i];
}
}
}
/**
* 获取正在播放的窗口的数据
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
this.getElementSelected = function () {
this.getElementByIndex(this.windowSelectedIndex);
}
/**
* 播放视频时,在这里添加窗口信息
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} cameraid [description]
* @param {[type]} index [description]
* @return {[type]} [description]
*/
this.addElement = function (cameraid, channel) {
this.windowsElementMap[channel] = this.getCameraModel(cameraId);
}
/**
* 删除通道中信息,一般用在停止播放时
* @author tramp
* @DateTime 2016-10-13
* @param {[type]} channel [description]
* @return {[type]} [description]
*/
this.deleteElement = function (channel) {
this.windowsElementMap.remove(channel);
}
/**
* 选择窗口改变时
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} channel [description]
* @return {[type]} [description]
*/
this.changeWindow = function () {
var channel = this.getWindowsSelectedNowByOcx();
this.windowSelectedIndex = channel;
}
/**
* ocx窗口属性容器
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} cameraId [description]
* @param {[type]} channel [description]
* @return {[type]} [description]
*/
function windowsElement(cameraId, channel) {
var winSingle = new Object();
winSingle.cameraid = cameraid;
winSingle.channel = channel;
winSingle.attribute;
return winSingle;
}
/**
* 获取选中的窗口
* @author tramp
* @DateTime 2016-10-13
* @return {[type]} [description]
*/
function getWindowsSelectedNowByOcx() {
//这里需要等高略的接口
return 1;
}
}
/**
* 业务相关类管理,这里从流程管理类中提取出来的目的是,认为这里是可变的,而且与流程控制无关;这个类附属于流程类,不建议直接调用
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
function OperationManager() {
this.submitHandle = function (captureResult, submitType) {
endTime();
switch (submitType) {
case "illegal":
submitIllegal(captureResult);
break;
case "case":
submitCaseInfo(captureResult);
break;
default:
break;
}
}
/**
* 提交违法
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
function submitIllegal(captureResult) {
showSubmitWindow(captureResult);
}
/**
* 提交案件信息
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
function submitCaseInfo(captureResult) {
if (!captureResult) {
return null;
}
var urls = "";
captureResult.getImagePathMap().forEach(function (item, key) {
urls += item.serverPath + ";";
});
urls = urls.substring(0, urls.length - 1);
hideOcxDiv();
editCase(urls);
}
/**
* 上传处理器
* @author tramp
* @DateTime 2016-10-17
* @param {[type]} captureResult [description]
* @param {[type]} type [description]
* @return {[type]} [description]
*/
this.uploadingHandle = function (captureResult, type) {
switch (type) {
case "illegal":
return uploadingIllegal(captureResult);
break;
case "case":
return uploadingCaseInfo(captureResult);
break;
default:
break;
}
}
/**
* 上传违法
* @author tramp
* @DateTime 2016-10-17
* @param {[type]} captureResult [description]
* @return {[type]} [description]
*/
uploadingIllegal = function (captureResult) {
return submitCapturedInfo(captureResult);
}
/**
* 上传案件
* @author tramp
* @DateTime 2016-10-17
* @param {[type]} captureResult [description]
* @return {[type]} [description]
*/
uploadingCaseInfo = function (captureResult) { }
/**
* 图片处理业务
* @author tramp
* @DateTime 2016-10-12
* @return {[type]} [description]
*/
this.pictureHandle = function (captureResult, changeType, changedIndex, cameraid) {
switch (changeType) {
case "add":
addPictureHandle(captureResult.getImagePathMap().get(changedIndex).serverPath, changedIndex);
break;
case "reset":
initializationPicture(cameraid);
if (captureResult != null && captureResult.cameraId != null) {
// for (var i = 0; i < captureResult.getImagePathMap().size; i++) {
// try {
// addPictureHandle(captureResult.getImagePathMap().get(i + 1).serverPath, i + 1);
// } catch (e) {}
// }
captureResult.getImagePathMap().forEach(function (item, key) {
addPictureHandle(item.serverPath, key);
});
}
break;
default:
break;
}
}
/**
* 删除图片,并在后台删除
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} imgPath, imgIndex [description]
* @return {[type]} [description]
*/
this.deletePictureHandle = function (localPath, serverPath, imgIndex) {
deletePicture(serverPath, imgIndex);
cameraController.deleteLocalFile(localPath);
endTime();
$.ajax({
url: 'RealTimeVideoWithYT.aspx?param=deleteImage',
type: 'post',
dataType: 'json',
data: {
imgPath: serverPath
},
success: function (data) {
if (data.success) {
// this.showMessagerInfo()
//deletePicture();
} else {
//alert("写入后台错误");
}
}
});
}
/**
* 初始化显示框
* @author tramp
* @DateTime 2016-10-14
* @return {[type]} [description]
*/
function initializationPicture(cameraid) {
for (var i = 0; i < 4; i++) {
deletePicture("", i + 1);
}
// $("#cancelCapture").attr("data-code", cameraid);
// $("#submitCapturedInfo").attr("data-code", cameraid);
// captureIngCameraId = cameraid;
}
function deletePicture(imgPath, imgIndex) {
$("#picContainer" + imgIndex + " img").attr("src", "");
$("#picContainer" + imgIndex + " img").hide();
}
/**
* 向容器中添加图片
* @author tramp
* @DateTime 2016-10-12
* @param {[type]} imgPath, imgIndex [description]
*/
function addPictureHandle(imgPath, imgIndex) {
$("#picContainer" + imgIndex + " img").attr("src", imgPath);
$("#picContainer" + imgIndex + " img").show();
}
//---------------XML模板--------------
var xmlTemplate = "<?xml version=\"1.0\" encoding=\"GB2312\" ?><LPR><LogNo>{logID}</LogNo> <UserID>{UserID}</UserID><DepartmentID>{DepartmentID}</DepartmentID><DirectionNo>{directionID}</DirectionNo>" + "<DirectionName>{directionName}</DirectionName><LocationNo>{kakouID}</LocationNo><LocationName>{kakouName}</LocationName>" + "<DeviceNo>{deviceID}</DeviceNo><DeviceName>{deviceName}</DeviceName><DeviceIP>{deviceIP}</DeviceIP>" + "<PlateText>{carPlateNumber}</PlateText><PlateType>{carPlateType}</PlateType><PlateColor>{carPlateColor}</PlateColor>" + "<VehicleColor>{carColor}</VehicleColor><VehicleType>{carType}</VehicleType><ViolationTime>{ViolationTime}</ViolationTime><ViolationValue>{ViolationValue}</ViolationValue><ViolationType>{ViolationType}</ViolationType><DataSource>{DataSource}</DataSource><InputPeople>{InputPeople}</InputPeople><StartTime>{startTime}</StartTime>" + "<EndTime>{endTime}</EndTime><Record><RecordPath>{video}</RecordPath><StartTime>{videoStartTime}</StartTime>" + "<EndTime>{videoEndTime}</EndTime></Record><FullView1><ImagePath>{pic1}</ImagePath><CaptureTime>{picTime1}</CaptureTime>" + "</FullView1><FullView2><ImagePath>{pic2}</ImagePath><CaptureTime>{picTime2}</CaptureTime></FullView2>" + "<VehicleView><ImagePath>{pic3}</ImagePath><CaptureTime>{picTime3}</CaptureTime></VehicleView>" + "<SubView><ImagePath>{pic4}</ImagePath><CaptureTime>{picTime4}</CaptureTime></SubView></LPR>";
/**
* 获取页面的需要提交的违法信息,从之前的提交方法中抽取出来,为了其他的页面使用
* @author tramp
* @DateTime 2016-10-13
* @return {[type]} [description]
*/
function getIllegalResult(captureResult) {
var illegalResult = new Object();
//illegalResult.outPath = outPath;
illegalResult.xmlString = xmlTemplate.replace("{logID}", "12345678");
illegalResult.directionID = validate($("#txtDirection").combobox("getValue")); //$("#txtDirection").val();
illegalResult.directionName = validate($("#txtDirection").combobox("getText")); //$("#txtDirection option:selected").text();
//illegalResult.kakouID = $("#txtKakouID").val();
illegalResult.kakouID = $("#txtKakouID").combobox("getValue");
//illegalResult.kakouName = $("#txtKakouName").val();
illegalResult.kakouName = $("#txtKakouID").combobox("getText");
illegalResult.deviceID = $("#txtDeviceID").val();
illegalResult.deviceName = removePreValue($("#txtDeviceName").val());
illegalResult.deviceIP = $("#txtDeviceIP").val();
illegalResult.carPlateNumber = $("#txtCarPlateNumber").val().toUpperCase()
//号牌种类
illegalResult.carPlateType = validate($("#txtCarPlateType").combobox("getValue"));
//getPreValue($("#txtCarPlateType option:selected").text());
//号牌颜色,车身颜色,车辆类型
illegalResult.carPlateColor = validate($("#txtCarPlateColor").combobox("getValue")); //getPreValue($("#txtCarPlateColor option:selected").text());
//车身颜色
illegalResult.carColor = validate($("#txtCarColor").combobox("getValue")); //removePreValue($("#txtCarColor option:selected").text());
//车辆类型
illegalResult.carType = validate($("#txtCarType").combobox("getValue")); //getPreValue($("#txtCarType option:selected").text());
illegalResult.startTime = undefined;
illegalResult.videoFile = "";
illegalResult.videoStopTime;
illegalResult.userID = $("#userID").val();
illegalResult.departmentID = $("#departmentID").val();
illegalResult.violationTime = $("#txtViolationTime").val();
illegalResult.violationValue = $("#txtViolationValue").val();
illegalResult.violationType = validate($("#txtViolationType").combobox("getValue")); //removePreValue($("#txtViolationType option:selected").val());
illegalResult.dataSource = removePreValue($("#dataSource option:selected").text());
illegalResult.userName = $("#userName").val();
captureResult.getImagePathMap().forEach(function (item, key) {
illegalResult["pic" + key] = item.localPath;
illegalResult["picTime" + key] = item.caputureTime;
if (illegalResult.startTime == undefined || illegalResult.startTime > item.caputureTime) {
illegalResult.startTime = item.caputureTime;
}
});
// illegalResult.pic1 = captureResult.getImagePathMap().get("1").localPath; //本地路径
// illegalResult.picTime1 = captureResult.getImagePathMap().get("1").caputureTime;
// illegalResult.pic2 = captureResult.getImagePathMap().get("2").localPath; //本地路径
// illegalResult.picTime2 = captureResult.getImagePathMap().get("2").caputureTime;
// illegalResult.pic3 = captureResult.getImagePathMap().get("3").localPath; //本地路径
// illegalResult.picTime3 = captureResult.getImagePathMap().get("3").caputureTime;
// illegalResult.pic4 = captureResult.getImagePathMap().get("4").localPath; //本地路径
// illegalResult.picTime4 = captureResult.getImagePathMap().get("4").caputureTime;
return illegalResult;
}
function validate(value) {
if (value == null || value == "-1" || value == "全部") {
return "";
}
else {
return value;
}
}
//根据抓拍的图片等信息,生成基本的XML文件
function getCapturedXmlString(caputureResult) {
var illegalResult = getIllegalResult(caputureResult)
var xmlString = xmlTemplate;
xmlString = xmlString.replace("{directionID}", illegalResult.directionID).replace("{directionName}", illegalResult.directionName); //方向id 方向名称
xmlString = xmlString.replace("{kakouID}", illegalResult.kakouID).replace("{kakouName}", illegalResult.kakouName);
xmlString = xmlString.replace("{deviceID}", illegalResult.deviceID).replace("{deviceName}", illegalResult.deviceName);
xmlString = xmlString.replace("{deviceIP}", illegalResult.deviceIP);
xmlString = xmlString.replace("{carPlateNumber}", illegalResult.carPlateNumber);
xmlString = xmlString.replace("{carPlateType}", illegalResult.carPlateType);
xmlString = xmlString.replace("{carPlateColor}", illegalResult.carPlateColor);
xmlString = xmlString.replace("{carColor}", illegalResult.carColor);
xmlString = xmlString.replace("{carType}", illegalResult.carType);
//设置开始,结束时间
xmlString = xmlString.replace("{startTime}", formatTimeString(illegalResult.startTime)).replace("{endTime}", formatTimeString(new Date()));
//录像文件,如果没有录像文件则设为空
if (illegalResult.videoFile && illegalResult.videoFile != "") {
xmlString = xmlString.replace("{video}", illegalResult.videoFile);
xmlString = xmlString.replace("{videoStartTime}", formatTimeString(illegalResult.startTime));
xmlString = xmlString.replace("{videoEndTime}", formatTimeString(illegalResult.videoStopTime));
} else {
xmlString = xmlString.replace("{video}", " ");
xmlString = xmlString.replace("{videoStartTime}", " ");
xmlString = xmlString.replace("{videoEndTime}", " ");
}
// //图片信息
if (illegalResult.pic1 != null && illegalResult.pic1 != "" && illegalResult.pic1 != undefined) {
xmlString = xmlString.replace("{pic1}", changePath(illegalResult.pic1));
xmlString = xmlString.replace("{picTime1}", formatTimeString(illegalResult.picTime1));
} else {
xmlString = xmlString.replace("{pic1}", "");
xmlString = xmlString.replace("{picTime1}", "");
}
if (illegalResult.pic2 != null && illegalResult.pic2 != "" && illegalResult.pic2 != undefined) {
xmlString = xmlString.replace("{pic2}", changePath(illegalResult.pic2));
xmlString = xmlString.replace("{picTime2}", formatTimeString(illegalResult.picTime2));
} else {
xmlString = xmlString.replace("{pic2}", "");
xmlString = xmlString.replace("{picTime2}", "");
}
if (illegalResult.pic3 != null && illegalResult.pic3 != "" && illegalResult.pic3 != undefined) {
xmlString = xmlString.replace("{pic3}", changePath(illegalResult.pic3));
xmlString = xmlString.replace("{picTime3}", formatTimeString(illegalResult.picTime3));
} else {
xmlString = xmlString.replace("{pic3}", "");
xmlString = xmlString.replace("{picTime3}", "");
}
if (illegalResult.pic4 != null && illegalResult.pic4 != "" && illegalResult.pic4 != undefined) {
xmlString = xmlString.replace("{pic4}", changePath(illegalResult.pic4));
xmlString = xmlString.replace("{picTime4}", formatTimeString(illegalResult.picTime4));
} else {
xmlString = xmlString.replace("{pic4}", "");
xmlString = xmlString.replace("{picTime4}", "");
}
//替换违法时间,违法数值,违法行为,数据来源,录入人
xmlString = xmlString.replace("{UserID}", illegalResult.userID);
xmlString = xmlString.replace("{DepartmentID}", illegalResult.departmentID);
xmlString = xmlString.replace("{ViolationTime}", illegalResult.violationTime);
xmlString = xmlString.replace("{ViolationValue}", illegalResult.violationValue);
xmlString = xmlString.replace("{ViolationType}", illegalResult.violationType);
xmlString = xmlString.replace("{DataSource}", illegalResult.dataSource);
xmlString = xmlString.replace("{InputPeople}", illegalResult.userName);
return xmlString;
}
function changePath(path) {
//path.replace('\\','\\');
var re = "";
var p = path.split('\\');
for (var i = 0; i < p.length; i++) {
re += p[i] + "\\\\";
}
re = re.substring(0, re.length - 2);
return re;
}
//清除选项前的数字
function removePreValue(stringWithValue) {
return stringWithValue.replace(/\w+:/, "");
}
//获取前置的Key值
function getPreValue(stringWithValue) {
var key = stringWithValue.split(":")[0];
//去掉前面的"0",比如:"00"->"0","01"->"1"
if (/^0.+$/.test(key)) {
var keyStringLength = key.length;
return key.substr(1, keyStringLength - 1);
} else {
return key;
}
}
//判断同一天同一路段是否重复提交
function isCommonValidate() {
var carPlateNumber = $("#txtCarPlateNumber").val().toUpperCase(); //获取号牌号码
var currentNode = $("#ctree").tree("getSelected");
var postAllCameraId = "";
if (currentNode != null) {
var parentNode = $("#ctree").tree("getParent", currentNode.target);
var getAllCameraId = $("#ctree").tree("getChildren", parentNode.target);
for (var i = 0; i < getAllCameraId.length; i++) {
postAllCameraId += encodeURIComponent(getAllCameraId[i].attributes.cameraID) + ",";
}
}
//判断同一天同一路段是否重复提交
var url = "../../Ashx/Vion/Kakou/CheckSameCarPlateNumber.ashx?carPlateNumber= " + encodeURIComponent(carPlateNumber) + "&allCameraId=" + postAllCameraId + "&violationType= " + encodeURIComponent($("#txtViolationType").find("option:selected").text().split(':')[0].toString());
var result = 0;
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
cache: false,
async: false,
success: function (data) {
if (data > 0) {
result = data;
} else {
result = 0;
}
},
error: function (error) {
result = 0;
}
});
return result; //在ajax之外执行return
}
//测试信息是否填完整
function isInfoValidate() {
var direction = $("#txtDirection").val();
if (direction == "-1") {
showAlert("提示", "请选择方向!");
return false;
}
var carPlateNumber = $("#txtCarPlateNumber").val();
if (carPlateNumber == "" || carPlateNumber == $("#carPlateNumberPrefix").val()) {
alert("请填写号牌!");
return false;
}
// if (checkPlateNumber(carPlateNumber)) {
// // Successful match
// } else {
// showAlert("提示", "请确认号牌号码是否正确!");
// return false;
// }
var carPlateType = $("#txtCarPlateType").val();
if (carPlateType == "-1") {
showAlert("提示", "请选择号牌类型!");
return false;
}
return true;
}
/**
* 显示提交窗口
* @author tramp
* @DateTime 2016-10-13
*/
function showSubmitWindow(illegalResult) {
if (illegalResult.imageCount == 0) {
// hideOcxDiv();
// $.messager.alert("提示", "", "info", function() {
// showOcxDiv();
// });
this.showMessagerInfo("必须抓拍全景图1才能提交!");
return false;
}
//停止录像 captureFlowManager.stopVideoRecord();
//
//
this.hideVideoOcxDiv(); //隐藏OCX
var options = {
title: "数据审核",
height: 590,
width: 1000,
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
closable: false,
draggable: false,
shadow: false,
border: false,
onClose: showVideoOcxDiv
};
//停止录像
captureFlowManager.stopVideoRecord();
//显示提交窗口
showCapturedInfo(illegalResult);
$("#CaptureSubmitWindow").css("visibility", "visible").window(options);
//显示图片字符
showPicNameString();
}
this.hideSubmitWindow = function () {
$("#CaptureSubmitWindow").window("close");
showOcxDiv();
}
/*
方法说明:抓拍并识别号牌号
参数: 要识别的图片路径
返回值:
-1 服务器未连接
0 图片打开失败
1 成功
2 识别失败,(不会有事件)
*/
function CloseUpRecog(picPath) {
var returnCode = trafficOcxObj.CloseUpRecog(picPath);
return returnCode == 1;
}
/**
* 在弹出窗显示抓拍信息
* @author tramp
* @DateTime 2016-10-13
*/
function showCapturedInfo(illegalResult) {
//进行号牌识别
recognizeCarPlateNumber(illegalResult);
//显示图片
showCapturedImgInSubmitWindow(illegalResult, this.outPutPath);
//显示地点及设备信息
// $("#txtKakouID").val(illegalResult.attribute.attributes.relatedKakouId);
$("#txtKakouID").combobox('select', illegalResult.attribute.attributes.relatedKakouId);
$("#txtKakouName").val(illegalResult.attribute.attributes.relatedKakouName);
//球机ID已经是设备ID
$("#txtDeviceID").val(illegalResult.attribute.id);
$("#txtDeviceName").val(illegalResult.attribute.text);
$("#txtDeviceIP").val(illegalResult.attribute.attributes.camIp);
//显示当前的时间
var nowTime = formatTimeString(new Date());
$("#txtViolationTime").val(nowTime);
//绑定默认值
$('#txtViolationType').combobox('select', "04");
$('#txtCarPlateType').combobox('select', "02");
}
var defaultPlateImageIndex; //默认需要识别号牌的图片的索引,
/**
* 号牌识别
* @author tramp
* @DateTime 2016-10-13
* @return {[type]} [description]
*/
function recognizeCarPlateNumber(illegalResult) {
if (illegalResult.imageCount <= 0) {
return;
}
var isRecognizedSuccess = false;
illegalResult.getImagePathMap().forEach(function (item, key) {
var picPath = item.localPath;
if (!isRecognizedSuccess) {
isRecognizedSuccess = CloseUpRecog(picPath);
}
});
}
/**
* 在提交窗口显示抓拍图片
* @author tramp
* @DateTime 2016-10-13
* @param {[type]} outPath [description]
* @return {[type]} [description]
*/
function showCapturedImgInSubmitWindow(illegalResult, outPath) {
//清除掉滤镜
$("#leftPicWindow .showImg").css("filter", "");
illegalResult.getImagePathMap().forEach(function (item, key) {
if (item.serverPath) {
showPicByFilter("Img" + key, item.serverPath);
}
});
}
/**
* 使用IE滤镜的方式显示图片(优化频繁显示很多图片时的内存占用)
* @author tramp
* @DateTime 2016-10-17
* @param {[type]} containerId [description]
* @param {[type]} picPath [description]
* @return {[type]} [description]
*/
function showPicByFilter(containerId, picPath) {
var containerObj = document.getElementById(containerId);
if (containerObj) {
if (!-[1,]) {
containerObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src='" + picPath + "')";
} else {
picPath = picPath.replace(/\\/g, "\\\\");
$(containerObj).attr("style", "background:url('" + picPath + "') no-repeat 0 0;background-size:100% 100%;display:block;");
}
//保存图片地址,以备后用
containerObj.setAttribute("data-pic", picPath);
}
}
//this.cameraAttribute = null; //相机的属性信息
// this.setCameraAttribute = function(node) {
// //this.cameraAttribute = node;
// return node;
// }
//提交审核后的抓拍信息
function submitCapturedInfo(caputureResult) {
//首先判断用户信息是否填写完整
var isValidate = isInfoValidate();
if (isValidate) {
var result = isCommonValidate();
var xmlFileString; //要传给Ocx的XML字符串
if (result > 0) {
$.messager.progress("close");
var confirmCapture = confirm("今天该号牌已经抓拍过" + result + "次,再次抓拍?");
if (confirmCapture) {
xmlFileString = getCapturedXmlString(caputureResult);
return UploadData(xmlFileString) == "1";
} else return -1;
} else {
xmlFileString = getCapturedXmlString(caputureResult);
return UploadData(xmlFileString) == "1";
}
}
return -1;
}
/*
方法说明:上传抓拍信息到接收中心
参数:
captureXmlInfo : 抓拍车辆信息,包括图片及录像
返回值:
1--成功,0--失败
*/
function UploadData(captureXmlInfo) {
return trafficOcxObj.UploadData(captureXmlInfo);
}
}
//格式化日期
function formatTimeString(datetime) {
if (!datetime) {
return "";
}
var dateString = datetime.format("yyyy-MM-dd hh:mm:ss");
return dateString;
}
//根据录入的各项信息获取图片的字符串
function getPictureNameString() {
var deviceID = $("#txtDeviceID").val();
//var locationID = $("#txtKakouID").val();
var locationID = $("#txtKakouID").combobox("getValue");
var directionID = $("#txtDirection").combobox("getValue");
var violationTime = $("#txtViolationTime").val();
violationTime = getShortTimeString(violationTime);
var violationValue = $("#txtViolationValue").val();
var carPlateType = $("#txtCarPlateType").combobox("getValue");
var carPlateNumber = $("#txtCarPlateNumber").val();
var violationType = $("#txtViolationType").combobox("getValue");
var departmentID = $("#departmentID").val();
var userID = $("#userID").val();
var dataSource = $("#dataSource").val();
var returnString = deviceID + "_" + locationID + "_" + directionID + "_" + violationTime;
returnString = returnString + "_" + violationValue + "_" + carPlateType + "_" + carPlateNumber;
returnString = returnString + "_" + violationType + "_" + departmentID + "_" + userID + "_" + dataSource;
returnString = returnString + "_3_0.JPG";
// var returnString = "";
return returnString;
}
function getShortTimeString(longTimeString) {
//return longTimeString.replace("-", "").replace(":", "");
return longTimeString.replace(/[-:\s]/g, "");
}
/**
* 显示图片的名称
* @author tramp
* @DateTime 2016-10-13
* @return {[type]} [description]
*/
function showPicNameString() {
var picString = getPictureNameString();
$("#picName").val(picString);
}
/**
* 初始化车身颜色
* @author tramp
* @DateTime 2016-10-17
* @return {[type]} [description]
*/
function initCarColor() {
var carColorObj = $("#txtCarColor");
var options = {
valueField: "id",
textField: "text",
width: 180,
url: "../../Ashx/Vion/SystemManager/TrafficDicSysTemCode.ashx?SysCode=ExteriorColor",
value: "-1",
editable: false
};
carColorObj.combobox(options);
}
/**
* 卡口方向
* @author tramp
* @DateTime 2016-10-17
* @return {[type]} [description]
*/
function initKaKouDirction() {
var carColorObj = $("#txtDirection");
var options = {
valueField: "id",
textField: "text",
width: 180,
url: "../../Ashx/Vion/SystemManager/TrafficDicSysTemCode.ashx?SysCode=KaKouDirction",
value: "-1",
editable: false
};
carColorObj.combobox(options);
}
/**
* 车辆类型
* @author tramp
* @DateTime 2016-10-17
* @return {[type]} [description]
*/
function initCarType() {
var carColorObj = $("#txtCarType");
var options = {
valueField: "id",
textField: "text",
width: 180,
url: "../../Ashx/Vion/SystemManager/TrafficDicSysTemCode.ashx?SysCode=CarType",
value: "-1",
editable: false
};
carColorObj.combobox(options);
}
/**
* 号牌种类
* @author tramp
* @DateTime 2016-10-17
* @return {[type]} [description]
*/
function initHapPaiType() {
var carColorObj = $("#txtCarPlateType");
var options = {
valueField: "id",
textField: "text",
width: 180,
url: "../../Ashx/Vion/SystemManager/TrafficDicSysTemCode.ashx?SysCode=HapPaiType",
value: "-1",
editable: false
};
carColorObj.combobox(options);
}
/**
* 号牌颜色
* @author tramp
* @DateTime 2016-10-17
* @return {[type]} [description]
*/
function initCarNumColor() {
var carColorObj = $("#txtCarPlateColor");
var options = {
valueField: "id",
textField: "text",
width: 180,
url: "../../Ashx/Vion/SystemManager/TrafficDicSysTemCode.ashx?SysCode=CarNumColor",
value: "-1",
editable: false
};
carColorObj.combobox(options);
}
/**
* 违法类型
* @author tramp
* @DateTime 2016-10-17
* @return {[type]} [description]
*/
function initTrafficViolationType() {
var carColorObj = $("#txtViolationType");
var options = {
valueField: "id",
textField: "text",
width: 180,
url: "../../Ashx/Vion/SystemManager/TrafficDicSysTemCode.ashx?SysCode=TrafficViolationType",
value: "-1",
editable: false
};
carColorObj.combobox(options);
}
function getUserInfo() {
$.ajax({
url: 'RealTimeVideoWithYT.aspx?param=userInfo',
type: 'post',
dataType: 'json',
data: {},
success: function (data) {
if (data.success) {
$("#departmentID").val(data.user.OrgNUM);
$("#userID").val(data.user.UserNUM);
$("#userNameCaputre").val(data.user.TrueName);
} else {
//alert("写入后台错误");
}
}
});
}
/**
* 编辑case
* @author tramp
* @DateTime 2016-09-08
*/
function editCase(urls) {
document.getElementById("editIFrame").src = "../CriminalInvestigation/edit.aspx?pageType=addCaseByVideo&urls=" + urls + "&recorder=" + $("#userID").val() + "&recorderName=" + $("#userNameCaputre").val();
$('#divShowEdit').dialog({
title: "编辑",
buttons: [{
text: '添加',
iconCls: 'icon-add',
handler: function () {
try {
//showOcxDiv()
editIFrame.add();
} catch (e) { }
}
}, {
text: '取消',
iconCls: 'icon-cancel',
handler: function () {
//showOcxDiv() ;
$('#divShowEdit').dialog('close');
}
}],
onBeforeClose: function () {
try {
showOcxDiv();
editIFrame.clear();
} catch (e) { }
return true;
}
});
$('#divShowEdit').dialog('open');
}
//function hideOcxDiv()
//function showOcxDiv()
export {
setCameraSpeed,
controlDevice,
StopControlCamera,
getControlParam,
connectCamera
}