vue2-client 1.10.16 → 1.10.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,572 +1,572 @@
1
- <template>
2
- <a-modal
3
- :visible="show"
4
- :dialogStyle="{ top: '1vh' }"
5
- width="50vw"
6
- :footer="null"
7
- :zIndex="1050"
8
- @cancel="handleCancel"
9
- :maskClosable="false"
10
- >
11
- <div class="scanner-container">
12
- <a-row>
13
- <a-space>
14
- <a-button type="primary" @click="capturePhoto">拍照</a-button>
15
- <a-button type="primary" @click="switchCamera('0')">文档</a-button>
16
- <a-button type="primary" @click="switchCamera('1')">人像</a-button>
17
- <a-button type="primary" @click="getVideoStatus">设备状态</a-button>
18
- <a-button type="primary" @click="closeVideo">关闭设备</a-button>
19
- <a-button type="primary" @click="openApp">开启程序</a-button>
20
- <a-button v-if="showid" type="primary" @click="startReadCard">读身份证</a-button>
21
- <a-button v-if="showid" @click="stopReadCard">停止读卡</a-button>
22
- </a-space>
23
- </a-row>
24
- <a-row>
25
- <a-col :span="12">
26
- <div
27
- style="display: flex; justify-content: center; align-items: center; height: 300px;">
28
- <img
29
- v-if="previewImage"
30
- id="Base64IMG"
31
- :src="previewImage"
32
- height="300"
33
- alt=""
34
- style="display: block;margin: auto;"
35
- />
36
- <a-empty v-else/>
37
- </div>
38
- </a-col>
39
- <a-col :span="12">
40
- <a-textarea
41
- id="Console"
42
- style=" height: 300px; width: 100%; resize: none;border-radius: 0"
43
- :disabled="true"></a-textarea>
44
- </a-col>
45
- <a-col :span="24">
46
- <img
47
- id="cam"
48
- :src="cameraurl"
49
- width="100%"
50
- height="540"
51
- alt=""/>
52
- </a-col>
53
- <a-col :span="24" v-if="showid">
54
- <a-form layout="horizontal">
55
- <a-form-item label="姓名">
56
- <a-input v-model="idCardForm.name" disabled/>
57
- </a-form-item>
58
- <a-form-item label="性别">
59
- <a-input v-model="idCardForm.sex" disabled/>
60
- </a-form-item>
61
- <a-form-item label="民族">
62
- <a-input v-model="idCardForm.nation" disabled/>
63
- </a-form-item>
64
- <a-form-item label="出生日期">
65
- <a-input v-model="idCardForm.birthday" disabled/>
66
- </a-form-item>
67
- <a-form-item label="地址">
68
- <a-textarea v-model="idCardForm.address" :rows="2" disabled/>
69
- </a-form-item>
70
- <a-form-item label="身份证号">
71
- <a-input v-model="idCardForm.cardID" disabled/>
72
- </a-form-item>
73
- <a-form-item label="签发机关">
74
- <a-input v-model="idCardForm.issueOrgan" disabled/>
75
- </a-form-item>
76
- <a-form-item label="有效期">
77
- <a-input v-model="idCardForm.validStart" disabled/>
78
- <a-input v-model="idCardForm.validEnd" disabled/>
79
- </a-form-item>
80
-
81
- <div class="id-photo-section">
82
- <div class="photo-preview">
83
- <img
84
- id="PhotoDisplay"
85
- :src="idCardForm.photoUrl"
86
- class="id-photo"
87
- alt=""/>
88
- </div>
89
- <a-button type="primary" @click="confirmIdCard">确认信息</a-button>
90
- </div>
91
- </a-form>
92
- </a-col>
93
- </a-row>
94
- </div>
95
- <template #title>
96
- <a-row>
97
- <a-col :span="24">
98
- <a-space>
99
- 高拍仪
100
- <a-button @click="handleOk">上传截图</a-button>
101
- <a-button @click="handleCancel">取消</a-button>
102
- </a-space>
103
- </a-col>
104
- </a-row>
105
- </template>
106
- <div id="result"></div>
107
- </a-modal>
108
- </template>
109
-
110
- <script>
111
- import axios from 'axios'
112
-
113
- let ws
114
- const SERVER_ADDR = 'ws://127.0.0.1:38088'
115
-
116
- export default {
117
- name: 'HeightScanner',
118
-
119
- props: {
120
- show: Boolean,
121
- showid: Boolean
122
- },
123
-
124
- data () {
125
- return {
126
- SERVER_ADDR,
127
- cameraurl: 'http://127.0.0.1:38088/video=stream&camidx=0',
128
- connected: false,
129
- clicked: false,
130
- iswaiting: false,
131
- previewImage: '',
132
- consoleText: '',
133
- idCardForm: {
134
- name: '',
135
- sex: '',
136
- nation: '',
137
- birthday: '',
138
- address: '',
139
- cardID: '',
140
- issueOrgan: '',
141
- validStart: '',
142
- validEnd: '',
143
- photoBuffer: '',
144
- photoUrl: ''
145
- },
146
- callback: {},
147
- context: 0,
148
- base_offset: 0,
149
- orgdrawwidth: 0,
150
- orgdrawheight: 0,
151
-
152
- CLT_MSG: {
153
- // 打开相机 cap:相机ID
154
- BEGIN_CAP: 1,
155
- // 关闭相机 cap:相机ID
156
- STOP_CAP: 2,
157
- // 获取PID
158
- GET_PID: 3,
159
- // 获取分辨率
160
- GET_FBL: 4,
161
- // 设置分辨率
162
- SET_FBL: 5,
163
- // 设置MJPG格式
164
- SET_MJPG: 6,
165
- // 设置视频旋转
166
- SET_TURN: 7,
167
- // 设置视频截图保存的jpg质量
168
- SET_QUALITY: 8,
169
- // 设置自动裁边
170
- SET_AUTOCROP: 9,
171
- // 设置预设框选
172
- SET_PREST: 10,
173
- // 获取当前预设框选
174
- GET_PREST_INFO: 11,
175
- // 视频格式弹窗
176
- FORMAT_DLG: 12,
177
- // 视频属性弹窗
178
- PROPERTY_DLG: 13,
179
- // 设置截图颜色模式 彩色 黑白 灰度
180
- SET_COLOR_MODEL: 14,
181
- // 截图
182
- GET_PICTURE: 15,
183
- // 设置去底色参数
184
- SET_CLEAN_PARAM: 16,
185
- // 内存截图
186
- GET_PICTURE_MEM: 17,
187
- // base64测试
188
- TEST_BASE64: 18,
189
- // 制作PDF的临时目录
190
- SET_TEMPDIR: 19,
191
- // 开始制作PDF
192
- BEGIN_PDF: 20,
193
- // PDF截图 保存到PDF临时目录
194
- GET_PDF_PICTURES: 21,
195
- // 结束制作PDF
196
- END_PDF_PICTURES: 22,
197
- // PDF文件转为文件里的BASE64码
198
- PDF_TO_BASE64: 23,
199
- // 文件里的BASE64码转为PDF文件
200
- BASE64_TO_PDF: 24,
201
- // PDF文件转为BASE64字符串
202
- PDF_TO_BASE64_STR: 25,
203
- // 删除制作PDF的图片文件
204
- DEL_PICTURE_PDF: 26,
205
- // 打印图片
206
- PRINT_IMAGE: 27,
207
- // 设置显示错误弹窗
208
- SHOW_ERROR_BOX: 28,
209
- // 获取视频连接事件
210
- GET_EVENT: 29,
211
- // 预设框选鼠标消息
212
- PRESET_MOUSEDOWN: 30,
213
- PRESET_MOUSEMOVE: 31,
214
- PRESET_MOUSEUP: 32,
215
- // 人证对比
216
- IDCARD_COMPARE: 40,
217
- // 读卡
218
- READ_IDCARD: 51,
219
- // 开始循环读卡
220
- BEGIN_READ_IDCARD: 52,
221
- // 停止循环读卡
222
- STOP_READ_IDCARD: 53,
223
- // 水平
224
- HCOPY_IDCARD: 54,
225
- // 垂直
226
- VCOPY_IDCARD: 55,
227
-
228
- PCOPY_IDCARD: 56,
229
- // 反面
230
- NCOPY_IDCARD: 57
231
- },
232
- SVR_BIN_MSG: {
233
- CAP_FRAME: 1, // 后台帧消息
234
- }
235
- }
236
- },
237
-
238
- methods: {
239
- // handleImgError (e) {
240
- // e.target.style.display = 'none'
241
- // },
242
- // 页面load消息
243
- onLoad () {
244
- return new Promise((resolve, reject) => {
245
- // 添加重试计数器
246
- let retryCount = 0
247
- const maxRetries = 5
248
-
249
- const tryConnect = () => {
250
- if (ws) {
251
- resolve()
252
- return
253
- }
254
-
255
- ws = new WebSocket(this.SERVER_ADDR)
256
-
257
- ws.onopen = (evt) => {
258
- if (this.connected) {
259
- resolve()
260
- }
261
- this.connected = true
262
- this.output('已经连接到服务器')
263
- this.switchCamera(0)
264
- }
265
-
266
- ws.onclose = (evt) => {
267
- if (!this.connected) {
268
- // 检查重试次数
269
- if (retryCount < maxRetries) {
270
- retryCount++
271
- this.output(`连接失败,正在进行第${retryCount}次重试...`)
272
- window.location.href = 'FLShell://'
273
- setTimeout(tryConnect, 3 * 1000)
274
- } else {
275
- this.output('连接失败,已达到最大重试次数')
276
- reject(new Error('连接失败,已达到最大重试次数'))
277
- }
278
- } else {
279
- this.output('已断开服务器连接')
280
- this.connected = false
281
- }
282
- ws = null
283
- }
284
-
285
- ws.onerror = (evt) => {
286
- this.output('高拍仪连接错误')
287
- reject(new Error('连接错误'))
288
- }
289
- ws.onmessage = (evt) => {
290
- if (evt.data.length === 0) {
291
- return
292
- }
293
- if (typeof evt.data === 'string') {
294
- const msg = JSON.parse(evt.data)
295
- console.log('msg1:', msg)
296
- if (msg.err && msg.err !== 0) {
297
- this.output('错误 - ' + msg.err + ', ' + msg.msg)
298
- reject(new Error('错误 - ' + msg.err + ', ' + msg.msg))
299
- } else if (msg.msg) {
300
- console.log('msg2:', msg)
301
- this.output(msg.msg)
302
- }
303
- if (msg.user_data) {
304
- this.callback[msg.user_data](msg)
305
- if (typeof msg.user_data === 'number') {
306
- this.callback[msg.user_data] = undefined
307
- }
308
- }
309
- } else {
310
- const file = new FileReader()
311
- file.onload = (evt) => {
312
- if (evt.target.readyState == FileReader.DONE) {
313
- const data = new Uint8Array(evt.target.result)
314
- if (data[0] == this.SVR_BIN_MSG.CAP_FRAME) {
315
- return this.drawImage(data)
316
- }
317
- }
318
- }
319
- file.readAsArrayBuffer(evt.data)
320
- }
321
- }
322
- const canvas = document.getElementById('cam')
323
- canvas.onmousedown = (e) => {
324
- canvas.style.cursor = 'crosshair'
325
- this.clicked = true
326
- this.sendMsg(this.CLT_MSG.PRESET_MOUSEDOWN, { origX: e.layerX, origY: e.layerY }, (msg) => {
327
- if (msg.err !== 0) {
328
- console.warn('鼠标按下事件出错:', msg.err)
329
- }
330
- })
331
- }
332
- canvas.onmousemove = (e) => {
333
- if (!this.clicked) {
334
- canvas.style.cursor = 'default'
335
- return
336
- }
337
- canvas.style.cursor = 'crosshair'
338
- this.sendMsg(this.CLT_MSG.PRESET_MOUSEMOVE, { offx: e.layerX, offy: e.layerY }, (msg) => {
339
- if (msg.err !== 0) {
340
- console.warn('鼠标移动事件出错:', msg.err)
341
- }
342
- })
343
- }
344
- onmouseout = canvas.onmouseup = (e) => {
345
- canvas.style.cursor = 'default'
346
- if (!this.clicked) {
347
- return
348
- }
349
- this.sendMsg(this.CLT_MSG.PRESET_MOUSEUP, { offx: e.layerX, offy: e.layerY }, (msg) => {
350
- if (msg.err !== 0) {
351
- console.warn('鼠标抬起事件出错:', msg.err)
352
- }
353
- })
354
- this.clicked = false
355
- }
356
- }
357
-
358
- tryConnect() // 开始首次连接
359
- })
360
- },
361
- newInstancePost (url, data) {
362
- // 重新创建是为了 避免axios的拦截器影响写卡读卡请求
363
- // 请求 如果携带了 Cookie,token到卡服务 会导致请求失败
364
- // 需要注意的是因为没有增加响应拦截器 所以返回结果的res里面会多一层data
365
- const instance = axios.create()
366
- return instance.post(url, data, {
367
- withCredentials: false,
368
- headers: {
369
- 'Content-Type': 'text/plain;charset=UTF-8',
370
- Accept: '*/*',
371
- }
372
- })
373
- },
374
- // 打开视频
375
- switchCamera (data) {
376
- this.cameraurl = 'http://127.0.0.1:38088/video=stream&camidx=' + data + '&tid=' + Date.parse(new Date())
377
- },
378
- // 关闭视频
379
- async closeVideo () {
380
- const params = ''
381
- const url = this.cameraurl.replace('stream', 'close')
382
- this.cameraurl = ''
383
- const msg = await this.newInstancePost('http://127.0.0.1:38088/card=idcard', params)
384
- if (msg.data.code != '0') {
385
- document.getElementById('result').innerHTML = msg.data.message
386
- }
387
- },
388
- // 获取设备状态
389
- async getVideoStatus () {
390
- document.getElementById('result').innerHTML = ''
391
- const params = ''
392
- const url = 'http://127.0.0.1:38088/video=status'
393
- this.cameraurl = ''
394
- const msg = await this.newInstancePost(url, params)
395
- if (msg.data.code != '0') {
396
- document.getElementById('result').innerHTML = '获取设备状态失败,返回代码 = ' + msg.data.code + ',返回信息 = ' + msg.data.message
397
- } else {
398
- document.getElementById('result').innerHTML = '文档摄像头:' + msg.data.video0 +
399
- ', 人像1:' + msg.data.video1
400
- }
401
-
402
- },
403
- openApp () {
404
- window.location.href = 'cameraServicetis:0' // 启动 CameraService 服务程序
405
- },
406
- async capturePhoto () {
407
- // if (!this.name) {
408
- // return this.$showMessage('请输入照片名称')
409
- // }
410
- // if (!this.useType) {
411
- // return this.$showMessage('请选择文件使用类型')
412
- // }
413
- let camidx = 0
414
- if (this.cameraurl.indexOf('http://127.0.0.1:38088/video=stream&camidx=0') != -1) {
415
- camidx = 0
416
- } else if (this.cameraurl.indexOf('http://127.0.0.1:38088/video=stream&camidx=1') != -1) {
417
- camidx = 1
418
- } else {
419
- this.$message.info('请先打开视频')
420
- return
421
- }
422
- const param = {
423
- camidx: camidx
424
- }
425
- const msg = await this.newInstancePost('http://127.0.0.1:38088/video=grabimage',param)
426
- if (msg.data.code != '0') {
427
- this.$message.info(msg.data.message)
428
- return
429
- }
430
- this.previewImage = 'data:image/jpg;base64,' + msg.data.photoBase64
431
- this.output('base64 长度 : ' + this.previewImage)
432
- this.$emit('photo-finish', { img: this.previewImage })
433
- this.name = ''
434
- // post('http://127.0.0.1:38088/video=grabimage', param)
435
- },
436
- // 读身份证
437
- async startReadCard () {
438
- const msg = await this.newInstancePost('http://127.0.0.1:38088/card=idcard', param)
439
- if (msg.data.code != '0') {
440
- this.$message.info(msg.data.message, 2000)
441
- return
442
- } else {
443
- this.updateIdCardInfo(msg.data.IDCardInfo)
444
- }
445
- this.output('读取身份证')
446
- this.output('开始读卡')
447
- },
448
- // 停止读身份证
449
- stopReadCard () {
450
- this.sendMsg(this.CLT_MSG.STOP_READ_IDCARD, (msg) => {
451
- if (msg.err !== 0) {
452
- return
453
- }
454
- this.output('停止读卡')
455
- })
456
- },
457
- // 视频帧绘制函数
458
- drawImage (data) {
459
- // 校验视频是否在一定时间内的
460
- if (!this.checkTimestamp(data[2] * 256 + data[1])) {
461
- return
462
- }
463
- // 视频帧头有时间戳 注意偏移 和 大小端处理
464
- const width = data[this.base_offset + 1] * 256 + data[this.base_offset]
465
- const height = data[this.base_offset + 3] * 256 + data[this.base_offset + 2]
466
-
467
- const cam = document.getElementById('cam')
468
- const context = cam.getContext('2d')
469
- if (this.orgdrawwidth != width || this.orgdrawheight != height) {
470
- this.orgdrawwidth = width
471
- this.orgdrawheight = height
472
- }
473
-
474
- const image = context.createImageData(width, height)
475
- for (let n = 0; n != height; ++n) {
476
- for (let m = 0; m != width; ++m) {
477
- const imageOffset = ((height - n - 1) * width + m) * 4
478
- const dataOffset = (n * width + m) * 3 + this.baseOffset + 4
479
- image.data[imageOffset] = data[dataOffset + 2]
480
- image.data[imageOffset + 1] = data[imageOffset + 1]
481
- image.data[imageOffset + 2] = data[imageOffset]
482
- image.data[imageOffset + 3] = 255
483
- }
484
- }
485
- context.putImageData(image, 0, 0)
486
- },
487
- checkTimestamp (svrTime) {
488
- const myDate = new Date()
489
- let cltTime = myDate.getSeconds() * 1000 + myDate.getMilliseconds()
490
- if (cltTime < svrTime) {
491
- cltTime += 60 * 1000
492
- }
493
- return cltTime - svrTime < 3000
494
- },
495
- sendMsg (proto, msg, cb) {
496
- if (!ws) {
497
- return
498
- }
499
-
500
- if (typeof msg !== 'object') {
501
- if (typeof msg === 'function') {
502
- cb = msg
503
- msg = {}
504
- } else {
505
- msg = {}
506
- }
507
- }
508
-
509
- msg.proto = proto
510
- if (typeof cb === 'function') {
511
- this.callback[++this.context] = cb
512
- msg.user_data = this.context
513
- }
514
-
515
- ws.send(JSON.stringify(msg))
516
- },
517
- output (content) {
518
- if (content.length == 0) {
519
- return
520
- }
521
- const console = document.getElementById('Console')
522
- console.value += content
523
- console.value += '\r'
524
- console.scrollTop = console.scrollHeight
525
- },
526
- // 显示读到的身份证信息
527
- updateIdCardInfo (msg) {
528
- document.getElementById('Name').value = msg.name
529
- document.getElementById('Sex').value = msg.sex
530
- document.getElementById('Nation').value = msg.nation
531
- document.getElementById('Born').value = msg.birthday
532
- document.getElementById('Address').value = msg.address
533
- document.getElementById('CardNo').value = msg.cardID
534
- document.getElementById('Police').value = msg.issueOrgan
535
- document.getElementById('ActivityLFrom').value = msg.validStart
536
- document.getElementById('ActivityLTo').value = msg.validEnd
537
- // document.getElementById('DeviceNo').value = msg.validEnd
538
- document.getElementById('PhotoBuffer').value = msg.fingerBase64
539
- document.getElementById('PhotoDisplay').src = 'data:image/jpg;base64,' + msg.photoBase64
540
- this.IdCardInfo = msg
541
- },
542
- confirmIdCard () {
543
- const param = this.IdCardInfo
544
- if (this.IdCardInfo) {
545
- this.$emit('confirm-info', param)
546
- this.IdCardInfo = {}
547
- }
548
- },
549
- handleOk () {
550
- this.$emit('confirmPhoto', this.previewImage)
551
- },
552
- handleCancel () {
553
- this.show = false
554
- }
555
- },
556
-
557
- mounted () {
558
- this.onLoad().then(() => {
559
- this.$emit('ready')
560
- }).catch(error => {
561
- this.$emit('error', error)
562
- })
563
- },
564
-
565
- beforeDestroy () {
566
- if (ws) {
567
- ws.close()
568
- ws = null
569
- }
570
- }
571
- }
572
- </script>
1
+ <template>
2
+ <a-modal
3
+ :visible="show"
4
+ :dialogStyle="{ top: '1vh' }"
5
+ width="50vw"
6
+ :footer="null"
7
+ :zIndex="1050"
8
+ @cancel="handleCancel"
9
+ :maskClosable="false"
10
+ >
11
+ <div class="scanner-container">
12
+ <a-row>
13
+ <a-space>
14
+ <a-button type="primary" @click="capturePhoto">拍照</a-button>
15
+ <a-button type="primary" @click="switchCamera('0')">文档</a-button>
16
+ <a-button type="primary" @click="switchCamera('1')">人像</a-button>
17
+ <a-button type="primary" @click="getVideoStatus">设备状态</a-button>
18
+ <a-button type="primary" @click="closeVideo">关闭设备</a-button>
19
+ <a-button type="primary" @click="openApp">开启程序</a-button>
20
+ <a-button v-if="showid" type="primary" @click="startReadCard">读身份证</a-button>
21
+ <a-button v-if="showid" @click="stopReadCard">停止读卡</a-button>
22
+ </a-space>
23
+ </a-row>
24
+ <a-row>
25
+ <a-col :span="12">
26
+ <div
27
+ style="display: flex; justify-content: center; align-items: center; height: 300px;">
28
+ <img
29
+ v-if="previewImage"
30
+ id="Base64IMG"
31
+ :src="previewImage"
32
+ height="300"
33
+ alt=""
34
+ style="display: block;margin: auto;"
35
+ />
36
+ <a-empty v-else/>
37
+ </div>
38
+ </a-col>
39
+ <a-col :span="12">
40
+ <a-textarea
41
+ id="Console"
42
+ style=" height: 300px; width: 100%; resize: none;border-radius: 0"
43
+ :disabled="true"></a-textarea>
44
+ </a-col>
45
+ <a-col :span="24">
46
+ <img
47
+ id="cam"
48
+ :src="cameraurl"
49
+ width="100%"
50
+ height="540"
51
+ alt=""/>
52
+ </a-col>
53
+ <a-col :span="24" v-if="showid">
54
+ <a-form layout="horizontal">
55
+ <a-form-item label="姓名">
56
+ <a-input v-model="idCardForm.name" disabled/>
57
+ </a-form-item>
58
+ <a-form-item label="性别">
59
+ <a-input v-model="idCardForm.sex" disabled/>
60
+ </a-form-item>
61
+ <a-form-item label="民族">
62
+ <a-input v-model="idCardForm.nation" disabled/>
63
+ </a-form-item>
64
+ <a-form-item label="出生日期">
65
+ <a-input v-model="idCardForm.birthday" disabled/>
66
+ </a-form-item>
67
+ <a-form-item label="地址">
68
+ <a-textarea v-model="idCardForm.address" :rows="2" disabled/>
69
+ </a-form-item>
70
+ <a-form-item label="身份证号">
71
+ <a-input v-model="idCardForm.cardID" disabled/>
72
+ </a-form-item>
73
+ <a-form-item label="签发机关">
74
+ <a-input v-model="idCardForm.issueOrgan" disabled/>
75
+ </a-form-item>
76
+ <a-form-item label="有效期">
77
+ <a-input v-model="idCardForm.validStart" disabled/>
78
+ <a-input v-model="idCardForm.validEnd" disabled/>
79
+ </a-form-item>
80
+
81
+ <div class="id-photo-section">
82
+ <div class="photo-preview">
83
+ <img
84
+ id="PhotoDisplay"
85
+ :src="idCardForm.photoUrl"
86
+ class="id-photo"
87
+ alt=""/>
88
+ </div>
89
+ <a-button type="primary" @click="confirmIdCard">确认信息</a-button>
90
+ </div>
91
+ </a-form>
92
+ </a-col>
93
+ </a-row>
94
+ </div>
95
+ <template #title>
96
+ <a-row>
97
+ <a-col :span="24">
98
+ <a-space>
99
+ 高拍仪
100
+ <a-button @click="handleOk">上传截图</a-button>
101
+ <a-button @click="handleCancel">取消</a-button>
102
+ </a-space>
103
+ </a-col>
104
+ </a-row>
105
+ </template>
106
+ <div id="result"></div>
107
+ </a-modal>
108
+ </template>
109
+
110
+ <script>
111
+ import axios from 'axios'
112
+
113
+ let ws
114
+ const SERVER_ADDR = 'ws://127.0.0.1:38088'
115
+
116
+ export default {
117
+ name: 'HeightScanner',
118
+
119
+ props: {
120
+ show: Boolean,
121
+ showid: Boolean
122
+ },
123
+
124
+ data () {
125
+ return {
126
+ SERVER_ADDR,
127
+ cameraurl: 'http://127.0.0.1:38088/video=stream&camidx=0',
128
+ connected: false,
129
+ clicked: false,
130
+ iswaiting: false,
131
+ previewImage: '',
132
+ consoleText: '',
133
+ idCardForm: {
134
+ name: '',
135
+ sex: '',
136
+ nation: '',
137
+ birthday: '',
138
+ address: '',
139
+ cardID: '',
140
+ issueOrgan: '',
141
+ validStart: '',
142
+ validEnd: '',
143
+ photoBuffer: '',
144
+ photoUrl: ''
145
+ },
146
+ callback: {},
147
+ context: 0,
148
+ base_offset: 0,
149
+ orgdrawwidth: 0,
150
+ orgdrawheight: 0,
151
+
152
+ CLT_MSG: {
153
+ // 打开相机 cap:相机ID
154
+ BEGIN_CAP: 1,
155
+ // 关闭相机 cap:相机ID
156
+ STOP_CAP: 2,
157
+ // 获取PID
158
+ GET_PID: 3,
159
+ // 获取分辨率
160
+ GET_FBL: 4,
161
+ // 设置分辨率
162
+ SET_FBL: 5,
163
+ // 设置MJPG格式
164
+ SET_MJPG: 6,
165
+ // 设置视频旋转
166
+ SET_TURN: 7,
167
+ // 设置视频截图保存的jpg质量
168
+ SET_QUALITY: 8,
169
+ // 设置自动裁边
170
+ SET_AUTOCROP: 9,
171
+ // 设置预设框选
172
+ SET_PREST: 10,
173
+ // 获取当前预设框选
174
+ GET_PREST_INFO: 11,
175
+ // 视频格式弹窗
176
+ FORMAT_DLG: 12,
177
+ // 视频属性弹窗
178
+ PROPERTY_DLG: 13,
179
+ // 设置截图颜色模式 彩色 黑白 灰度
180
+ SET_COLOR_MODEL: 14,
181
+ // 截图
182
+ GET_PICTURE: 15,
183
+ // 设置去底色参数
184
+ SET_CLEAN_PARAM: 16,
185
+ // 内存截图
186
+ GET_PICTURE_MEM: 17,
187
+ // base64测试
188
+ TEST_BASE64: 18,
189
+ // 制作PDF的临时目录
190
+ SET_TEMPDIR: 19,
191
+ // 开始制作PDF
192
+ BEGIN_PDF: 20,
193
+ // PDF截图 保存到PDF临时目录
194
+ GET_PDF_PICTURES: 21,
195
+ // 结束制作PDF
196
+ END_PDF_PICTURES: 22,
197
+ // PDF文件转为文件里的BASE64码
198
+ PDF_TO_BASE64: 23,
199
+ // 文件里的BASE64码转为PDF文件
200
+ BASE64_TO_PDF: 24,
201
+ // PDF文件转为BASE64字符串
202
+ PDF_TO_BASE64_STR: 25,
203
+ // 删除制作PDF的图片文件
204
+ DEL_PICTURE_PDF: 26,
205
+ // 打印图片
206
+ PRINT_IMAGE: 27,
207
+ // 设置显示错误弹窗
208
+ SHOW_ERROR_BOX: 28,
209
+ // 获取视频连接事件
210
+ GET_EVENT: 29,
211
+ // 预设框选鼠标消息
212
+ PRESET_MOUSEDOWN: 30,
213
+ PRESET_MOUSEMOVE: 31,
214
+ PRESET_MOUSEUP: 32,
215
+ // 人证对比
216
+ IDCARD_COMPARE: 40,
217
+ // 读卡
218
+ READ_IDCARD: 51,
219
+ // 开始循环读卡
220
+ BEGIN_READ_IDCARD: 52,
221
+ // 停止循环读卡
222
+ STOP_READ_IDCARD: 53,
223
+ // 水平
224
+ HCOPY_IDCARD: 54,
225
+ // 垂直
226
+ VCOPY_IDCARD: 55,
227
+
228
+ PCOPY_IDCARD: 56,
229
+ // 反面
230
+ NCOPY_IDCARD: 57
231
+ },
232
+ SVR_BIN_MSG: {
233
+ CAP_FRAME: 1, // 后台帧消息
234
+ }
235
+ }
236
+ },
237
+
238
+ methods: {
239
+ // handleImgError (e) {
240
+ // e.target.style.display = 'none'
241
+ // },
242
+ // 页面load消息
243
+ onLoad () {
244
+ return new Promise((resolve, reject) => {
245
+ // 添加重试计数器
246
+ let retryCount = 0
247
+ const maxRetries = 5
248
+
249
+ const tryConnect = () => {
250
+ if (ws) {
251
+ resolve()
252
+ return
253
+ }
254
+
255
+ ws = new WebSocket(this.SERVER_ADDR)
256
+
257
+ ws.onopen = (evt) => {
258
+ if (this.connected) {
259
+ resolve()
260
+ }
261
+ this.connected = true
262
+ this.output('已经连接到服务器')
263
+ this.switchCamera(0)
264
+ }
265
+
266
+ ws.onclose = (evt) => {
267
+ if (!this.connected) {
268
+ // 检查重试次数
269
+ if (retryCount < maxRetries) {
270
+ retryCount++
271
+ this.output(`连接失败,正在进行第${retryCount}次重试...`)
272
+ window.location.href = 'FLShell://'
273
+ setTimeout(tryConnect, 3 * 1000)
274
+ } else {
275
+ this.output('连接失败,已达到最大重试次数')
276
+ reject(new Error('连接失败,已达到最大重试次数'))
277
+ }
278
+ } else {
279
+ this.output('已断开服务器连接')
280
+ this.connected = false
281
+ }
282
+ ws = null
283
+ }
284
+
285
+ ws.onerror = (evt) => {
286
+ this.output('高拍仪连接错误')
287
+ reject(new Error('连接错误'))
288
+ }
289
+ ws.onmessage = (evt) => {
290
+ if (evt.data.length === 0) {
291
+ return
292
+ }
293
+ if (typeof evt.data === 'string') {
294
+ const msg = JSON.parse(evt.data)
295
+ console.log('msg1:', msg)
296
+ if (msg.err && msg.err !== 0) {
297
+ this.output('错误 - ' + msg.err + ', ' + msg.msg)
298
+ reject(new Error('错误 - ' + msg.err + ', ' + msg.msg))
299
+ } else if (msg.msg) {
300
+ console.log('msg2:', msg)
301
+ this.output(msg.msg)
302
+ }
303
+ if (msg.user_data) {
304
+ this.callback[msg.user_data](msg)
305
+ if (typeof msg.user_data === 'number') {
306
+ this.callback[msg.user_data] = undefined
307
+ }
308
+ }
309
+ } else {
310
+ const file = new FileReader()
311
+ file.onload = (evt) => {
312
+ if (evt.target.readyState == FileReader.DONE) {
313
+ const data = new Uint8Array(evt.target.result)
314
+ if (data[0] == this.SVR_BIN_MSG.CAP_FRAME) {
315
+ return this.drawImage(data)
316
+ }
317
+ }
318
+ }
319
+ file.readAsArrayBuffer(evt.data)
320
+ }
321
+ }
322
+ const canvas = document.getElementById('cam')
323
+ canvas.onmousedown = (e) => {
324
+ canvas.style.cursor = 'crosshair'
325
+ this.clicked = true
326
+ this.sendMsg(this.CLT_MSG.PRESET_MOUSEDOWN, { origX: e.layerX, origY: e.layerY }, (msg) => {
327
+ if (msg.err !== 0) {
328
+ console.warn('鼠标按下事件出错:', msg.err)
329
+ }
330
+ })
331
+ }
332
+ canvas.onmousemove = (e) => {
333
+ if (!this.clicked) {
334
+ canvas.style.cursor = 'default'
335
+ return
336
+ }
337
+ canvas.style.cursor = 'crosshair'
338
+ this.sendMsg(this.CLT_MSG.PRESET_MOUSEMOVE, { offx: e.layerX, offy: e.layerY }, (msg) => {
339
+ if (msg.err !== 0) {
340
+ console.warn('鼠标移动事件出错:', msg.err)
341
+ }
342
+ })
343
+ }
344
+ onmouseout = canvas.onmouseup = (e) => {
345
+ canvas.style.cursor = 'default'
346
+ if (!this.clicked) {
347
+ return
348
+ }
349
+ this.sendMsg(this.CLT_MSG.PRESET_MOUSEUP, { offx: e.layerX, offy: e.layerY }, (msg) => {
350
+ if (msg.err !== 0) {
351
+ console.warn('鼠标抬起事件出错:', msg.err)
352
+ }
353
+ })
354
+ this.clicked = false
355
+ }
356
+ }
357
+
358
+ tryConnect() // 开始首次连接
359
+ })
360
+ },
361
+ newInstancePost (url, data) {
362
+ // 重新创建是为了 避免axios的拦截器影响写卡读卡请求
363
+ // 请求 如果携带了 Cookie,token到卡服务 会导致请求失败
364
+ // 需要注意的是因为没有增加响应拦截器 所以返回结果的res里面会多一层data
365
+ const instance = axios.create()
366
+ return instance.post(url, data, {
367
+ withCredentials: false,
368
+ headers: {
369
+ 'Content-Type': 'text/plain;charset=UTF-8',
370
+ Accept: '*/*',
371
+ }
372
+ })
373
+ },
374
+ // 打开视频
375
+ switchCamera (data) {
376
+ this.cameraurl = 'http://127.0.0.1:38088/video=stream&camidx=' + data + '&tid=' + Date.parse(new Date())
377
+ },
378
+ // 关闭视频
379
+ async closeVideo () {
380
+ const params = ''
381
+ const url = this.cameraurl.replace('stream', 'close')
382
+ this.cameraurl = ''
383
+ const msg = await this.newInstancePost('http://127.0.0.1:38088/card=idcard', params)
384
+ if (msg.data.code != '0') {
385
+ document.getElementById('result').innerHTML = msg.data.message
386
+ }
387
+ },
388
+ // 获取设备状态
389
+ async getVideoStatus () {
390
+ document.getElementById('result').innerHTML = ''
391
+ const params = ''
392
+ const url = 'http://127.0.0.1:38088/video=status'
393
+ this.cameraurl = ''
394
+ const msg = await this.newInstancePost(url, params)
395
+ if (msg.data.code != '0') {
396
+ document.getElementById('result').innerHTML = '获取设备状态失败,返回代码 = ' + msg.data.code + ',返回信息 = ' + msg.data.message
397
+ } else {
398
+ document.getElementById('result').innerHTML = '文档摄像头:' + msg.data.video0 +
399
+ ', 人像1:' + msg.data.video1
400
+ }
401
+
402
+ },
403
+ openApp () {
404
+ window.location.href = 'cameraServicetis:0' // 启动 CameraService 服务程序
405
+ },
406
+ async capturePhoto () {
407
+ // if (!this.name) {
408
+ // return this.$showMessage('请输入照片名称')
409
+ // }
410
+ // if (!this.useType) {
411
+ // return this.$showMessage('请选择文件使用类型')
412
+ // }
413
+ let camidx = 0
414
+ if (this.cameraurl.indexOf('http://127.0.0.1:38088/video=stream&camidx=0') != -1) {
415
+ camidx = 0
416
+ } else if (this.cameraurl.indexOf('http://127.0.0.1:38088/video=stream&camidx=1') != -1) {
417
+ camidx = 1
418
+ } else {
419
+ this.$message.info('请先打开视频')
420
+ return
421
+ }
422
+ const param = {
423
+ camidx: camidx
424
+ }
425
+ const msg = await this.newInstancePost('http://127.0.0.1:38088/video=grabimage',param)
426
+ if (msg.data.code != '0') {
427
+ this.$message.info(msg.data.message)
428
+ return
429
+ }
430
+ this.previewImage = 'data:image/jpg;base64,' + msg.data.photoBase64
431
+ this.output('base64 长度 : ' + this.previewImage)
432
+ this.$emit('photo-finish', { img: this.previewImage })
433
+ this.name = ''
434
+ // post('http://127.0.0.1:38088/video=grabimage', param)
435
+ },
436
+ // 读身份证
437
+ async startReadCard () {
438
+ const msg = await this.newInstancePost('http://127.0.0.1:38088/card=idcard', param)
439
+ if (msg.data.code != '0') {
440
+ this.$message.info(msg.data.message, 2000)
441
+ return
442
+ } else {
443
+ this.updateIdCardInfo(msg.data.IDCardInfo)
444
+ }
445
+ this.output('读取身份证')
446
+ this.output('开始读卡')
447
+ },
448
+ // 停止读身份证
449
+ stopReadCard () {
450
+ this.sendMsg(this.CLT_MSG.STOP_READ_IDCARD, (msg) => {
451
+ if (msg.err !== 0) {
452
+ return
453
+ }
454
+ this.output('停止读卡')
455
+ })
456
+ },
457
+ // 视频帧绘制函数
458
+ drawImage (data) {
459
+ // 校验视频是否在一定时间内的
460
+ if (!this.checkTimestamp(data[2] * 256 + data[1])) {
461
+ return
462
+ }
463
+ // 视频帧头有时间戳 注意偏移 和 大小端处理
464
+ const width = data[this.base_offset + 1] * 256 + data[this.base_offset]
465
+ const height = data[this.base_offset + 3] * 256 + data[this.base_offset + 2]
466
+
467
+ const cam = document.getElementById('cam')
468
+ const context = cam.getContext('2d')
469
+ if (this.orgdrawwidth != width || this.orgdrawheight != height) {
470
+ this.orgdrawwidth = width
471
+ this.orgdrawheight = height
472
+ }
473
+
474
+ const image = context.createImageData(width, height)
475
+ for (let n = 0; n != height; ++n) {
476
+ for (let m = 0; m != width; ++m) {
477
+ const imageOffset = ((height - n - 1) * width + m) * 4
478
+ const dataOffset = (n * width + m) * 3 + this.baseOffset + 4
479
+ image.data[imageOffset] = data[dataOffset + 2]
480
+ image.data[imageOffset + 1] = data[imageOffset + 1]
481
+ image.data[imageOffset + 2] = data[imageOffset]
482
+ image.data[imageOffset + 3] = 255
483
+ }
484
+ }
485
+ context.putImageData(image, 0, 0)
486
+ },
487
+ checkTimestamp (svrTime) {
488
+ const myDate = new Date()
489
+ let cltTime = myDate.getSeconds() * 1000 + myDate.getMilliseconds()
490
+ if (cltTime < svrTime) {
491
+ cltTime += 60 * 1000
492
+ }
493
+ return cltTime - svrTime < 3000
494
+ },
495
+ sendMsg (proto, msg, cb) {
496
+ if (!ws) {
497
+ return
498
+ }
499
+
500
+ if (typeof msg !== 'object') {
501
+ if (typeof msg === 'function') {
502
+ cb = msg
503
+ msg = {}
504
+ } else {
505
+ msg = {}
506
+ }
507
+ }
508
+
509
+ msg.proto = proto
510
+ if (typeof cb === 'function') {
511
+ this.callback[++this.context] = cb
512
+ msg.user_data = this.context
513
+ }
514
+
515
+ ws.send(JSON.stringify(msg))
516
+ },
517
+ output (content) {
518
+ if (content.length == 0) {
519
+ return
520
+ }
521
+ const console = document.getElementById('Console')
522
+ console.value += content
523
+ console.value += '\r'
524
+ console.scrollTop = console.scrollHeight
525
+ },
526
+ // 显示读到的身份证信息
527
+ updateIdCardInfo (msg) {
528
+ document.getElementById('Name').value = msg.name
529
+ document.getElementById('Sex').value = msg.sex
530
+ document.getElementById('Nation').value = msg.nation
531
+ document.getElementById('Born').value = msg.birthday
532
+ document.getElementById('Address').value = msg.address
533
+ document.getElementById('CardNo').value = msg.cardID
534
+ document.getElementById('Police').value = msg.issueOrgan
535
+ document.getElementById('ActivityLFrom').value = msg.validStart
536
+ document.getElementById('ActivityLTo').value = msg.validEnd
537
+ // document.getElementById('DeviceNo').value = msg.validEnd
538
+ document.getElementById('PhotoBuffer').value = msg.fingerBase64
539
+ document.getElementById('PhotoDisplay').src = 'data:image/jpg;base64,' + msg.photoBase64
540
+ this.IdCardInfo = msg
541
+ },
542
+ confirmIdCard () {
543
+ const param = this.IdCardInfo
544
+ if (this.IdCardInfo) {
545
+ this.$emit('confirm-info', param)
546
+ this.IdCardInfo = {}
547
+ }
548
+ },
549
+ handleOk () {
550
+ this.$emit('confirmPhoto', this.previewImage)
551
+ },
552
+ handleCancel () {
553
+ this.show = false
554
+ }
555
+ },
556
+
557
+ mounted () {
558
+ this.onLoad().then(() => {
559
+ this.$emit('ready')
560
+ }).catch(error => {
561
+ this.$emit('error', error)
562
+ })
563
+ },
564
+
565
+ beforeDestroy () {
566
+ if (ws) {
567
+ ws.close()
568
+ ws = null
569
+ }
570
+ }
571
+ }
572
+ </script>