vue2-client 1.10.14 → 1.10.16

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,155 +1,155 @@
1
- <script setup>
2
- import { getConfigByName } from '@vue2-client/services/api/common'
3
- import { reactive, ref, provide } from 'vue'
4
- import RenderRow from './RenderRow'
5
- import Exp500 from '@vue2-client/pages/exception/500.vue'
6
-
7
- const layout = ref(null)
8
-
9
- // 加载状态,0:加载中,1:已加载,2:出现错误
10
- const loaded = ref(0)
11
-
12
- // 声明组件总数
13
- const componentTotal = ref(0)
14
-
15
- // 注册组件总数
16
- const registerComponentTotal = ref(0)
17
-
18
- // 组件注册集
19
- const componentRefMap = reactive({})
20
-
21
- // 通用参数
22
- const data = {
23
- comps: componentRefMap,
24
- func: {
25
- getConfigByName: getConfigByName
26
- }
27
- }
28
-
29
- /**
30
- * 初始化构建页面组件
31
- * @param params
32
- */
33
- function init (params) {
34
- const {
35
- configName,
36
- configValue,
37
- serviceName
38
- } = params
39
- loaded.value = 0
40
- const getConfigAfter = (res) => {
41
- if (res == null) {
42
- loaded.value = 2
43
- return
44
- }
45
- layout.value = res
46
- // 设置组件总量
47
- setComponentTotal(layout.value.children)
48
- loaded.value = 1
49
- }
50
- if (configName) {
51
- getConfigByName(configName, serviceName, getConfigAfter)
52
- } else {
53
- getConfigAfter(JSON.parse(configValue))
54
- }
55
- }
56
-
57
- /**
58
- * 注册组件
59
- * @param name 组件名称
60
- * @param vm 组件实例
61
- */
62
- function registerComponent (name, vm) {
63
- componentRefMap[name] = vm
64
- registerComponentTotal.value = registerComponentTotal.value + 1
65
- console.info(`总组件数量:${componentTotal.value},已注册数量:${registerComponentTotal.value}`)
66
- // 初始化页面
67
- initPage()
68
- if (registerComponentTotal.value >= componentTotal.value) {
69
- // 注册事件
70
- registerEvents(layout.value.children)
71
- }
72
- }
73
- provide('registerComponent', registerComponent)
74
-
75
- /**
76
- * 初始化页面
77
- */
78
- function initPage () {
79
- if (layout.value.onMounted) {
80
- // eslint-disable-next-line no-eval
81
- const onMountedFun = eval('(' + layout.value.onMounted + ')')
82
- onMountedFun(data)
83
- }
84
- }
85
-
86
- /**
87
- * 设置需要注册的组件总数
88
- * @param children 组件集合
89
- */
90
- function setComponentTotal (children) {
91
- children.forEach((child) => {
92
- // 如果不是row类型,追加组件数量
93
- if (child.type !== 'row') {
94
- componentTotal.value = componentTotal.value + 1
95
- }
96
- // 递归追加子组件数量
97
- if (child.children) {
98
- setComponentTotal(child.children)
99
- }
100
- })
101
- }
102
-
103
- /**
104
- * 注册组件事件
105
- * @param children 组件集合
106
- */
107
- function registerEvents (children) {
108
- children.forEach((child) => {
109
- // 如果有事件,注册它们
110
- if (child.event) {
111
- Object.entries(child.event).forEach(([eventName, handler]) => {
112
- // eslint-disable-next-line no-eval
113
- const eventHandler = eval('(' + handler + ')')
114
- const componentInstance = componentRefMap[child.id]
115
- if (componentInstance) {
116
- // 创建一个包装函数以传递额外参数
117
- const wrappedHandler = function (...args) {
118
- // 这里可以传递额外的参数,例如:
119
- eventHandler.call(componentInstance, ...args, data)
120
- }
121
- componentInstance.$on(eventName, wrappedHandler)
122
- }
123
- })
124
- }
125
-
126
- // 递归注册子组件的事件
127
- if (child.children) {
128
- registerEvents(child.children)
129
- }
130
- })
131
- }
132
-
133
- defineExpose({
134
- init
135
- })
136
-
137
- </script>
138
-
139
- <template>
140
- <div class="liuli_page">
141
- <div class="liuli_page_main" v-if="loaded === 1">
142
- <render-row
143
- v-for="row in layout.children"
144
- :key="row.id"
145
- :row="row"
146
- />
147
- </div>
148
- <div class="liuli_page_error" v-else-if="loaded === 2">
149
- <exp500></exp500>
150
- </div>
151
- </div>
152
- </template>
153
-
154
- <style scoped lang="less">
155
- </style>
1
+ <script setup>
2
+ import { getConfigByName } from '@vue2-client/services/api/common'
3
+ import { reactive, ref, provide } from 'vue'
4
+ import RenderRow from './RenderRow'
5
+ import Exp500 from '@vue2-client/pages/exception/500.vue'
6
+
7
+ const layout = ref(null)
8
+
9
+ // 加载状态,0:加载中,1:已加载,2:出现错误
10
+ const loaded = ref(0)
11
+
12
+ // 声明组件总数
13
+ const componentTotal = ref(0)
14
+
15
+ // 注册组件总数
16
+ const registerComponentTotal = ref(0)
17
+
18
+ // 组件注册集
19
+ const componentRefMap = reactive({})
20
+
21
+ // 通用参数
22
+ const data = {
23
+ comps: componentRefMap,
24
+ func: {
25
+ getConfigByName: getConfigByName
26
+ }
27
+ }
28
+
29
+ /**
30
+ * 初始化构建页面组件
31
+ * @param params
32
+ */
33
+ function init (params) {
34
+ const {
35
+ configName,
36
+ configValue,
37
+ serviceName
38
+ } = params
39
+ loaded.value = 0
40
+ const getConfigAfter = (res) => {
41
+ if (res == null) {
42
+ loaded.value = 2
43
+ return
44
+ }
45
+ layout.value = res
46
+ // 设置组件总量
47
+ setComponentTotal(layout.value.children)
48
+ loaded.value = 1
49
+ }
50
+ if (configName) {
51
+ getConfigByName(configName, serviceName, getConfigAfter)
52
+ } else {
53
+ getConfigAfter(JSON.parse(configValue))
54
+ }
55
+ }
56
+
57
+ /**
58
+ * 注册组件
59
+ * @param name 组件名称
60
+ * @param vm 组件实例
61
+ */
62
+ function registerComponent (name, vm) {
63
+ componentRefMap[name] = vm
64
+ registerComponentTotal.value = registerComponentTotal.value + 1
65
+ console.info(`总组件数量:${componentTotal.value},已注册数量:${registerComponentTotal.value}`)
66
+ // 初始化页面
67
+ initPage()
68
+ if (registerComponentTotal.value >= componentTotal.value) {
69
+ // 注册事件
70
+ registerEvents(layout.value.children)
71
+ }
72
+ }
73
+ provide('registerComponent', registerComponent)
74
+
75
+ /**
76
+ * 初始化页面
77
+ */
78
+ function initPage () {
79
+ if (layout.value.onMounted) {
80
+ // eslint-disable-next-line no-eval
81
+ const onMountedFun = eval('(' + layout.value.onMounted + ')')
82
+ onMountedFun(data)
83
+ }
84
+ }
85
+
86
+ /**
87
+ * 设置需要注册的组件总数
88
+ * @param children 组件集合
89
+ */
90
+ function setComponentTotal (children) {
91
+ children.forEach((child) => {
92
+ // 如果不是row类型,追加组件数量
93
+ if (child.type !== 'row') {
94
+ componentTotal.value = componentTotal.value + 1
95
+ }
96
+ // 递归追加子组件数量
97
+ if (child.children) {
98
+ setComponentTotal(child.children)
99
+ }
100
+ })
101
+ }
102
+
103
+ /**
104
+ * 注册组件事件
105
+ * @param children 组件集合
106
+ */
107
+ function registerEvents (children) {
108
+ children.forEach((child) => {
109
+ // 如果有事件,注册它们
110
+ if (child.event) {
111
+ Object.entries(child.event).forEach(([eventName, handler]) => {
112
+ // eslint-disable-next-line no-eval
113
+ const eventHandler = eval('(' + handler + ')')
114
+ const componentInstance = componentRefMap[child.id]
115
+ if (componentInstance) {
116
+ // 创建一个包装函数以传递额外参数
117
+ const wrappedHandler = function (...args) {
118
+ // 这里可以传递额外的参数,例如:
119
+ eventHandler.call(componentInstance, ...args, data)
120
+ }
121
+ componentInstance.$on(eventName, wrappedHandler)
122
+ }
123
+ })
124
+ }
125
+
126
+ // 递归注册子组件的事件
127
+ if (child.children) {
128
+ registerEvents(child.children)
129
+ }
130
+ })
131
+ }
132
+
133
+ defineExpose({
134
+ init
135
+ })
136
+
137
+ </script>
138
+
139
+ <template>
140
+ <div class="liuli_page">
141
+ <div class="liuli_page_main" v-if="loaded === 1">
142
+ <render-row
143
+ v-for="row in layout.children"
144
+ :key="row.id"
145
+ :row="row"
146
+ />
147
+ </div>
148
+ <div class="liuli_page_error" v-else-if="loaded === 2">
149
+ <exp500></exp500>
150
+ </div>
151
+ </div>
152
+ </template>
153
+
154
+ <style scoped lang="less">
155
+ </style>
@@ -5,6 +5,7 @@
5
5
  width="50vw"
6
6
  :footer="null"
7
7
  :zIndex="1050"
8
+ @cancel="handleCancel"
8
9
  :maskClosable="false"
9
10
  >
10
11
  <div class="scanner-container">
@@ -102,11 +103,12 @@
102
103
  </a-col>
103
104
  </a-row>
104
105
  </template>
106
+ <div id="result"></div>
105
107
  </a-modal>
106
108
  </template>
107
109
 
108
110
  <script>
109
- import { post } from '@vue2-client/services/api'
111
+ import axios from 'axios'
110
112
 
111
113
  let ws
112
114
  const SERVER_ADDR = 'ws://127.0.0.1:38088'
@@ -356,40 +358,52 @@ export default {
356
358
  tryConnect() // 开始首次连接
357
359
  })
358
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
+ },
359
374
  // 打开视频
360
375
  switchCamera (data) {
361
376
  this.cameraurl = 'http://127.0.0.1:38088/video=stream&camidx=' + data + '&tid=' + Date.parse(new Date())
362
377
  },
363
378
  // 关闭视频
364
- closeVideo () {
379
+ async closeVideo () {
365
380
  const params = ''
366
381
  const url = this.cameraurl.replace('stream', 'close')
367
382
  this.cameraurl = ''
368
- post(url, params).then((msg) => { // 截图
369
- if (msg.data.code != '0') {
370
- document.getElementById('result').innerHTML = msg.data.message
371
- }
372
- })
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
+ }
373
387
  },
374
388
  // 获取设备状态
375
- getVideoStatus () {
389
+ async getVideoStatus () {
376
390
  document.getElementById('result').innerHTML = ''
377
391
  const params = ''
378
392
  const url = 'http://127.0.0.1:38088/video=status'
379
393
  this.cameraurl = ''
380
- post(url, params).then((msg) => { // 截图
381
- if (msg.data.code != '0') {
382
- document.getElementById('result').innerHTML = '获取设备状态失败,返回代码 = ' + msg.data.code + ',返回信息 = ' + msg.data.message
383
- } else {
384
- document.getElementById('result').innerHTML = '文档摄像头:' + msg.data.video0 +
385
- ', 人像1:' + msg.data.video1
386
- }
387
- })
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
+
388
402
  },
389
403
  openApp () {
390
404
  window.location.href = 'cameraServicetis:0' // 启动 CameraService 服务程序
391
405
  },
392
- capturePhoto () {
406
+ async capturePhoto () {
393
407
  // if (!this.name) {
394
408
  // return this.$showMessage('请输入照片名称')
395
409
  // }
@@ -408,29 +422,27 @@ export default {
408
422
  const param = {
409
423
  camidx: camidx
410
424
  }
411
- post('http://127.0.0.1:38088/video=grabimage', param).then((msg) => { // 截图
412
- if (msg.data.code != '0') {
413
- this.$message.info(msg.data.message)
414
- return
415
- }
416
- this.previewImage = 'data:image/jpg;base64,' + msg.data.photoBase64
417
- this.output('base64 长度 : ' + this.previewImage)
418
- this.$emit('photo-finish', { img: this.previewImage })
419
- this.name = ''
420
- })
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)
421
435
  },
422
436
  // 读身份证
423
- startReadCard () {
424
- post('http://127.0.0.1:38088/card=idcard', {}).then((msg) => {
425
- if (msg.data.code != '0') {
426
- this.$message.info(msg.data.message, 2000)
427
- return
428
- } else {
429
- this.updateIdCardInfo(msg.data.IDCardInfo)
430
- }
431
-
432
- this.output('读取身份证')
433
- })
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('读取身份证')
434
446
  this.output('开始读卡')
435
447
  },
436
448
  // 停止读身份证