LaveyD il y a 7 mois
Parent
commit
f801efa353

+ 61 - 1
src/components/ReaderInput/index.vue

@@ -52,6 +52,7 @@ import { openDevice, readcard, closeDevice } from '@/api/HuashiReaderApi'
 import { getReaderConnect, getReaderDisconnect, getReadCert } from '@/api/JinlunReaderApi'
 import donsee from '@/api/donsee'
 import { getServerConfig, isEmpty } from '@/utils'
+import HuashiReaderWsApi from '@/api/HuashiReaderWsApi'
 
 export default {
   data () {
@@ -61,7 +62,8 @@ export default {
       tempValue: '',
       loading: false,
       comName: '', // 身份证阅读器端口号
-      deviceName: this.$localStore.get('idDevice') // 身份证阅读器类型。 zk 中控; hs 华视
+      deviceName: this.$localStore.get('idDevice'), // 身份证阅读器类型。 zk 中控; hs 华视
+      hsWsApi: null
     }
   },
   props: {
@@ -83,6 +85,11 @@ export default {
       default: '读取卡号'
     }
   },
+  mounted () {
+    if (this.deviceName === 'hs-ws') {
+      this.hsWsApi = new HuashiReaderWsApi()
+    }
+  },
   methods: {
     // IC卡位数补全
     padString (e) {
@@ -129,6 +136,11 @@ export default {
 
       this.finished = false
 
+      if (this.deviceName === 'hs-ws') {
+        this.handleHsWebSocket()
+        return
+      }
+
       // 东信EST-100R
       if (this.deviceName === 'donsee-100R') {
         this.handleDonsee100R()
@@ -159,6 +171,52 @@ export default {
 
       this.getDevice()
     },
+    handleHsWebSocket () {
+      if (!this.hsWsApi) {
+        this.hsWsApi = new HuashiReaderWsApi()
+      }
+      if (this.hsWsApi.isConnected) {
+        this.loading = true
+        this.active = true
+        this.hsWsApi.addMessageListener((res) => {
+          if (res.data === 'failed to obtain ID card information') {
+            this.$message.error('读取失败,请重试')
+            this.getIdInfo()
+            return
+          }
+
+          const alldata = res.data.split('|')
+          console.log(alldata)
+
+          if (alldata.length.length && alldata[0] === '卡认证失败') {
+            this.$message.error('读取失败,请重试')
+            this.loading = false
+            this.active = false
+            return
+          }
+
+          if (alldata.length >= 17) {
+            this.$emit('change', { Name: alldata[3], IDNumber: alldata[8] })
+            this.loading = false
+            this.active = false
+          }
+        })
+
+        this.hsWsApi.readIDCard(10 * 1000)
+      } else {
+        this.loading = false
+        this.active = false
+        this.hsWsApi.closeConnect()
+        this.hsWsApi.connect((isConnected) => {
+          if (isConnected) {
+            // this.timer && clearTimeout(this.timer)
+            this.handleHsWebSocket()
+          } else {
+            this.$message.error('身份证读卡器暂时无法使用,请检查;')
+          }
+        })
+      }
+    },
     handleTecsun () {
       this.loading = true
       this.active = true
@@ -440,6 +498,8 @@ export default {
     }
 
     this.cardSearchTimer && clearTimeout(this.cardSearchTimer)
+
+    this.hsWsApi && this.hsWsApi.closeConnect()
   }
 }
 </script>

+ 5 - 3
src/pages/sellManage/common/TouristList.vue

@@ -407,7 +407,9 @@ export default {
         this.getAge()
       })
 
-      this.hsWsApi = new HuashiReaderWsApi()
+      if (this.deviceName === 'hs-ws') {
+        this.hsWsApi = new HuashiReaderWsApi()
+      }
     },
 
     // 获取社保卡信息
@@ -485,7 +487,6 @@ export default {
             if (!this.hsWsApi) return
             if (this.hsWsApi.isConnected) {
               this.hsWsApi.addMessageListener((res) => {
-                console.log(res, '11212')
                 if (res.data === 'failed to obtain ID card information') {
                   this.message = '读取失败,请重试'
                   this.getIdInfo()
@@ -493,7 +494,6 @@ export default {
                 }
 
                 const alldata = res.data.split('|')
-                console.log(alldata)
 
                 if (alldata.length >= 17) {
                   setTourist(this.touristData, 1, { Name: alldata[3], IDNumber: alldata[8] })
@@ -737,6 +737,8 @@ export default {
     if (this.deviceName === 'donsee-100R') {
       this.$store.dispatch('stopAutoReadIDCard')
     }
+
+    this.hsWsApi && this.hsWsApi.closeConnect()
   }
 }
 </script>

+ 5 - 1
src/pages/sellManage/preOrder/TouristList.vue

@@ -342,7 +342,9 @@ export default {
         // }))
       })
 
-      this.hsWsApi = new HuashiReaderWsApi()
+      if (this.deviceName === 'hs-ws') {
+        this.hsWsApi = new HuashiReaderWsApi()
+      }
     },
 
     // 获取社保卡信息
@@ -632,6 +634,8 @@ export default {
     if (this.deviceName === 'donsee-100R') {
       this.$store.dispatch('stopAutoReadIDCard')
     }
+
+    this.hsWsApi && this.hsWsApi.closeConnect()
   }
 }
 </script>