lookPicture.html
9.53 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
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
.picdiv{
width:45%;
height:200px;
margin: 15px;
border: 1px solid #ddd;
white-space: nowrap;
float: left;
}
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<div class="container-fluid">
<div class="row-fluid">
<div class="col-sm-12">
<ul class="thumbnails">
<li class="col-sm-6">
<div class="thumbnail">
<img alt="车辆入厂照片" id="carOut" >
<div class="caption">
<p>
<span>车辆出厂拍照</span><a class="btn btn-primary" onclick="scan(1)">拍照</a>
</p>
</div>
</div>
</li>
<li class="col-sm-6">
<div class="thumbnail">
<img alt="身份证拍照" id="file2">
<div class="caption">
<p>
<span>身份证拍照</span><button class="btn btn-primary" onclick="scan(2)">拍照</button>
</p>
</div>
</div>
</li>
</ul>
</div>
<div class="col-sm-12">
<ul class="thumbnails">
<li class="col-sm-6">
<div class="thumbnail">
<img alt="驾驶证拍照" id="file3">
<div class="caption">
<p>
<span>驾驶证拍照</span><button class="btn btn-primary" onclick="scan(3)">拍照</button>
</p>
</div>
</div>
</li>
<li class="col-sm-6">
<div class="thumbnail">
<img alt="行驶证拍照" id="file4">
<div class="caption">
<p>
<span>行驶证拍照</span><button class="btn btn-primary" onclick="scan(4)">拍照</button>
</p>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<!-- <form class="form-horizontal m" id="form-camera-cameraReset">-->
<!-- <input name="id" type="hidden" />-->
<!-- -->
<div class="form-group">
<div class="form-control-static col-sm-offset-9">
<!-- <input type="file" id="image">-->
<input id="vehicleName" name="vehicleName" class="form-control" type="hidden" th:value="${vehicleName}" >
<input id="cardNumber" name="cardNumber" class="form-control" type="hidden" th:value="${cardNumber}" >
<input id="carNumber" name="carNumber" class="form-control" type="hidden" th:value="${carNumber}" >
<input id="driverNumber" name="driverNumber" class="form-control" type="hidden" th:value="${driverNumber}" >
<button type="submit" class="btn btn-primary" onclick="select()">提交</button>
<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
</div>
</div>
<!-- </form>-->
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript">
$("#file2").attr("src", "http://127.0.0.1:38088/video=stream&camidx=0");
$("#file3").attr("src", "http://127.0.0.1:38088/video=stream&camidx=0");
$("#file4").attr("src", "http://127.0.0.1:38088/video=stream&camidx=0");
// $("#view2").attr("src", "http://127.0.0.1:38088/video=stream&camidx=1");
// 加载主头视频模式
view1_mode_data1 = { "camidx": "0", "mode": "0" };
view1_mode_data2 = { "camidx": "0", "mode": "1" };
$.post("http://127.0.0.1:38088/device=getresolution", JSON.stringify(view1_mode_data2), function(res){
})
// 加载副头视频模式
view2_mode_data1 = { "camidx": "1", "mode": "0" };
view2_mode_data2 = { "camidx": "1", "mode": "1" };
$.post("http://127.0.0.1:38088/device=getresolution", JSON.stringify(view2_mode_data2), function(res){
})
function getData(){
let url = "/wms/img/Capture/carOut.jpg?" + Date.parse(new Date());
if (!CheckImgExists(url)) {
window.setTimeout(function(){getData();},2000);
};
$("#carOut").attr('src',url);
}
//判断图片是否存在
function CheckImgExists(imgurl) {
var ImgObj = new Image(); //判断图片是否存在
ImgObj.src = imgurl;
//没有图片,则返回-1
if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
return true;
} else {
return false;
}
}
function scan(num){
if(num==1){
$.ajax({
cache : false,
type : "POST",
url : ctx + "API/WMS/v2/cameraLogin",
dataType: 'json',
data : {
"cameraId": "2"
},
async : false,
error : function(request) {
$.modal.alertError("请求失败!");
},
success : function(result) {
if (result.code == web_status.SUCCESS) {
getData();
}else{
$.modal.alertError(result.data);
}
}
});
}
if(num==2){
let filepath = $("#cardNumber").val()+".jpg";
var reader = new FileReader();
var file = $("#image")[0].files[0];
reader.readAsDataURL(file);
reader.onload = function (e) {
//var ImgFileSize = reader.result.substring(reader.result.indexOf(",") + 1).length;//截取base64码部分(可选可不选,需要与后台沟通)
downloadFile(reader.result,filepath)
}
$.post("http://127.0.0.1:38088/card=idcard", function(res){
if(res.code == '1'){
$.modal.msgError("请将证件放对位置!!!")
}else{
$("#file2").attr("src", "data:image/jpg;base64," + res.IDCardInfo.photoBase64_Z);
// let filepath = $("#cardNumber").val()+".jpg";
// var reader = new FileReader();
// var file = $("#image")[0].files[0];
// reader.readAsDataURL(file);
// reader.onload = function (e) {
// //var ImgFileSize = reader.result.substring(reader.result.indexOf(",") + 1).length;//截取base64码部分(可选可不选,需要与后台沟通)
// downloadFile(res.IDCardInfo.photoBase64_Z,filepath)
// }
}
})
}else if(num==3){
let filepath = "D:/"+$("#carNumber").val()+".jpg";
data = {
"filepath": filepath,
"rotate": "0",
"deskew": "0",
"camidx": "0",
"ColorMode": "0",
"quality": "0"
}
$.post("http://127.0.0.1:38088/video=grabimage", JSON.stringify(data), function(res){
// $("#file1").src = "data:image/jpg;base64," + res.photoBase64;
$("#file3").attr("src", "data:image/jpg;base64," + res.photoBase64);
})
}else if(num==4){
let filepath = "D:/"+$("#driverNumber").val()+".jpg";
data = {
"filepath": filepath,
"rotate": "0",
"deskew": "0",
"camidx": "0",
"ColorMode": "0",
"quality": "0"
}
$.post("http://127.0.0.1:38088/video=grabimage", JSON.stringify(data), function(res){
$("#file4").attr("src", "data:image/jpg;base64," + res.photoBase64);
})
}
}
function downloadFile(content, fileName) { //下载base64图片
var base64ToBlob = function(code) {
let parts = code.split(';base64,');
let contentType = parts[0].split(':')[1];
console.log(contentType)
console.log(parts)
let raw = window.atob(parts[1]);
let rawLength = raw.length;
let uInt8Array = new Uint8Array(rawLength);
for(let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {
type: contentType
});
};
let aLink = document.createElement('a');
let blob = base64ToBlob(content); //new Blob([content]);
let evt = document.createEvent("HTMLEvents");
evt.initEvent("click", true, true); //initEvent 不加后两个参数在FF下会报错 事件类型,是否冒泡,是否阻止浏览器的默认行为
aLink.download = fileName;
aLink.href = URL.createObjectURL(blob);
aLink.pathname="D:/";
aLink.click();
};
function select() {
$.modal.close();
}
</script>
</body>
</html>