From d9b9cd8ea1791bc6a28b2ae63d7b2ec42599b5ea Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Mon, 22 Nov 2021 17:34:02 +0800
Subject: [PATCH] +预先判读是否有身份证设备

---
 src/views/securityGuard/securityGuard.vue |  100 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 79 insertions(+), 21 deletions(-)

diff --git a/src/views/securityGuard/securityGuard.vue b/src/views/securityGuard/securityGuard.vue
index d593f29..af1e1bc 100644
--- a/src/views/securityGuard/securityGuard.vue
+++ b/src/views/securityGuard/securityGuard.vue
@@ -512,6 +512,7 @@
       // 表格数据
       defaults: {},
       // 身份证设备数据
+      haveSEL: true, //是否存在设备
       cardShebei: "",
       intTime: "", //自动获取身份证;
       haveCardid: true, //读卡开关
@@ -1287,6 +1288,7 @@
     this.deptIds = this.userInfo.dept_id;
 
     // this.beginzhiwen();
+    this.olondSFZ(); //检查身份证设备是否存在
   },
   methods: {
     openccc() {
@@ -2032,6 +2034,53 @@
         }
       }
     },
+    olondSFZ() {
+      console.log(123456);
+      var that = this;
+      try {
+        // 开始连接设备
+        //调用对应的连接方法,并赋值给result
+        this.cardShebei = CertCtl.connect();
+        //如果result为空,代表读卡插件未启动
+        if (this.cardShebei == "") {
+          console.log("未启动读卡插件!1");
+          that.haveSEL = false;
+          return;
+        } else {
+          //result页面回显
+          console.log("ok!");
+        }
+      } catch (e) {
+        that.haveSEL = false;
+        return;
+      }
+      let result = CertCtl.readCert();
+      if (result == "") {
+        console.log("未启动读卡插件!2");
+        that.haveSEL = false;
+        return;
+      } else {
+        var resultObj = eval("(" + result + ")");
+        //resultFlag为0代表读卡成功
+        if (resultObj.resultFlag == "0") {
+          //回显相关数据
+          console.log("身份证设备连接成功");
+          that.haveSEL = true;
+        } else if (resultObj.resultFlag == "-1") {
+          if (resultObj.errorMsg == "端口打开失败") {
+            console.log("读卡器未连接");
+            that.haveSEL = false;
+          } else {
+            console.log(resultObj.errorMsg);
+            //无卡片提醒
+            that.haveSEL = true;
+          }
+        } else if (resultObj.resultFlag == "-2") {
+          console.log(resultObj.errorMsg);
+          that.haveSEL = false;
+        }
+      }
+    },
     setIntervals: function () {
       let that = this;
       this.intTime = setInterval(function () {
@@ -2040,6 +2089,7 @@
           let result = CertCtl.readCert();
           if (result == "") {
             console.log("未启动读卡插件!");
+            that.closeSFZ();
           } else {
             var resultObj = eval("(" + result + ")");
             //resultFlag为0代表读卡成功
@@ -2101,12 +2151,15 @@
             } else if (resultObj.resultFlag == "-1") {
               if (resultObj.errorMsg == "端口打开失败") {
                 console.log("读卡器未连接");
+                that.closeSFZ();
               } else {
                 // console.log(resultObj.errorMsg);
                 //无卡片提醒
+                that.closeSFZ();
               }
             } else if (resultObj.resultFlag == "-2") {
               console.log(resultObj.errorMsg);
+              that.closeSFZ();
             }
           }
         } else {
@@ -2115,36 +2168,41 @@
       }, 2000);
     },
     beginSFZ() {
-      try {
-        // 开始连接设备
-        //调用对应的连接方法,并赋值给result
-        this.cardShebei = CertCtl.connect();
-        //如果result为空,代表读卡插件未启动
-        if (this.cardShebei == "") {
-          console.log("未启动读卡插件!");
+      if (this.haveSEL) {
+        try {
+          // 开始连接设备
+          //调用对应的连接方法,并赋值给result
+          this.cardShebei = CertCtl.connect();
+          //如果result为空,代表读卡插件未启动
+          if (this.cardShebei == "") {
+            console.log("未启动读卡插件!");
+          } else {
+            //result页面回显
+            console.log("ok!");
+          }
+        } catch (e) {}
+        this.haveCardid = false;
+        if (this.intTime) {
+          clearInterval(this.intTime);
+          this.setIntervals();
         } else {
-          //result页面回显
-          console.log("ok!");
+          this.setIntervals();
         }
-      } catch (e) {}
-      this.haveCardid = false;
-      if (this.intTime) {
-        clearInterval(this.intTime);
-        this.setIntervals();
-      } else {
-        this.setIntervals();
       }
     },
-    closeSFZ() {
+    closeSFZ(val) {
       if (this.intTime) {
         clearInterval(this.intTime);
         // this.setIntervals();
       } else {
+        clearInterval(this.intTime);
         // this.setIntervals();
       }
-      this.haveCardid = true;
-      this.cardShebei = "";
-      //可以编辑
+      if (val) {
+        this.haveCardid = true;
+        this.cardShebei = "";
+        //可以编辑
+      }
       this.openClosegroup(false);
     },
     beforeOpen(done, type) {
@@ -2182,7 +2240,7 @@
       done();
     },
     beforeClose(done, type) {
-      this.closeSFZ();
+      this.closeSFZ(112);
       done();
     },
     currentChange(currentPage) {

--
Gitblit v1.9.3