ly 3 年之前
父节点
当前提交
14dab295fa
共有 3 个文件被更改,包括 234 次插入11 次删除
  1. 25 2
      ui/src/views/invoicing/hazardwork/index.vue
  2. 178 0
      ui/src/views/invoicing/signcard/index.vue
  3. 31 9
      ui/src/views/tool/card/index.vue

+ 25 - 2
ui/src/views/invoicing/hazardwork/index.vue

@@ -1510,7 +1510,10 @@
                 <table>
                   <tr>
                     <td>签名:
-                      <el-input style="width: 150px;" v-model="form.hSafeMesSign"/>
+                      <el-input style="width: 60px;" v-model="form.hSafeMesSign">
+                      </el-input>
+                      <el-button type="primary" slot="append" @click="signCard('hSafeMesSign')" icon="el-icon-edit"></el-button>
+
                       <el-date-picker format="yyyy-MM-dd HH:mm:ss"
                                       value-format="yyyy-MM-dd HH:mm:ss" v-model="form.hSafeMesDate" type="datetime">
                       </el-date-picker>
@@ -1789,6 +1792,7 @@
         </el-col>
       </el-row>
     </div>
+  <sign-card v-if="signCardVisible" v-on:signRes="getSignRes" ref="signCard"></sign-card>
   </el-form>
 </template>
 <script>
@@ -1801,10 +1805,12 @@ import {
   getInfo
 } from "@/api/invoicing/hazardwork";
 import {listDept} from "@/api/system/dept"
-
+import SignCard from "../signcard/index"
 export default {
+  components: { SignCard},
   data() {
     return {
+      signCardVisible: false,
       //TODO 模拟生产装置获取后台数据
       aEquipments: [{
         value: '1',
@@ -2429,6 +2435,23 @@ export default {
       this.form.eIsFallArrest = this.eIsFallArrest;
 
     },
+    //IC卡签名
+    signCard(type){
+      console.log('签名类型:' + type)
+      this.signCardVisible = true
+      this.$nextTick(() => {
+        this.$refs.signCard.init(type)
+      })
+    },
+    //获取签名结果
+    getSignRes(res){
+      console.log(res)
+      if (res.signType == 'hSafeMesSign') {
+        this.form.hSafeMesSign = res.cardId
+        this.form.hSafeMesDate = new Date()
+        console.log('chuanguolai' + this.form.hSafeMesSign)
+      }
+    }
   }
 };
 </script>

+ 178 - 0
ui/src/views/invoicing/signcard/index.vue

@@ -0,0 +1,178 @@
+<template>
+
+  <el-dialog title="签名" :destroy-on-close="destroy" :visible.sync="visible" width="1200px" append-to-body>
+
+  <p align="center"><textarea rows="20" :value="this.cardId" cols="111"></textarea></p>
+    <div slot="footer" class="dialog-footer">
+      <el-button type="primary" @click="submitForm">{{ $t('提交') }}</el-button>
+      <el-button @click="cancel">{{ $t('取 消') }}</el-button>
+    </div>
+  </el-dialog>
+</template>
+
+<script>
+export default {
+  name : 'test',
+  data() {
+    return {
+      destroy: true,
+      visible: false,
+      websock: null,
+      paramStr: '',
+      isComOpen: false,
+      cardId: '',
+      signType: '',
+    }
+  },
+  created() {
+  },
+  destroyed() {
+    console.log("离开路由之后断开websocket连接")
+    this.websock.close() //离开路由之后断开websocket连接
+  },
+  methods: {
+    init(type){
+      this.visible = true
+      this.signType = type
+      this.initWebSocket();
+    },
+    initWebSocket(){ //初始化websocket
+      const wsuri = "ws://localhost:81/webReaderServer";
+      if ("WebSocket" in window){
+        this.websock = new WebSocket(wsuri);
+      }
+      else if("MozWebSocket" in window){
+        this.websock = new MozWebSocket(wsuri);
+      }
+      this.websock.onmessage = this.websocketonmessage;
+      this.websock.onopen = this.websocketonopen;
+      this.websock.onerror = this.websocketonerror;
+      this.websock.onclose = this.websocketclose;
+    },
+    websocketonopen(){ //连接建立之后执行send方法发送数据
+      console.log("连接建立之后执行send方法发送数据")
+      this.cardId = "服务运行"
+      this.websocketsend("0webReader");
+      this.websocketsend("10|adaptReader|1");
+    },
+    websocketonerror(){//连接建立失败重连
+      this.cardId = "服务未运行"
+      // this.initWebSocket();
+    },
+    websocketonmessage(e){ //数据接收
+      console.log(e.data);
+      var str = "";
+      str = e.data;
+      var id = str.substr(0, 1);
+      var separator = str.indexOf("|");
+      var funcid = "";
+      var arg1 = "";
+      if (separator != -1) {
+        funcid = str.substr(1, separator - 1);
+        arg1 = str.substr(separator + 1);
+      } else
+        funcid = str.substr(1);
+      //alert("id:" + id + ",funcid:" + funcid +",arg1:" + arg1);
+      var resultData = {
+        type: "Result",
+        FunctionID: parseInt(funcid),
+        RePara_Int: parseInt(this._getCmdResult(arg1)),
+        RePara_Str: this._getResultPara(arg1)
+      };
+      if(resultData.FunctionID == "0"){
+        //连接上websocket,连接读卡器
+        this.cardConnect()
+      }else if(resultData.FunctionID == "1"){
+        //配置参数
+        this.paramStr = resultData.RePara_Str
+        this.websocketsend("1399|config_card|" + this.paramStr +"65");
+      }else if (resultData.FunctionID == "399") {
+        //寻找卡片
+        this.findCard()
+
+      }else if (resultData.FunctionID == "32") {
+        if (resultData.RePara_Str!= "") {
+          this.cardId = resultData.RePara_Str
+          this.websocketsend("145|halt|" + this.paramStr +"");
+        }else {
+          this.cardId = this.cardId + "..."
+          this.findCard()
+        }
+      }else if (resultData.FunctionID == "45") {
+        this.websocketsend("13|beep|" + this.paramStr +"10");
+      }else if (resultData.FunctionID == "3") {
+        this.disconnect()
+        console.log("找到卡片之后断开websocket连接")
+        this.websock.close()
+        //寻找卡片
+        // let _this = this
+        // setTimeout(function (){
+        //   _this.findCard()
+        // }, 1000);
+      }
+      // console.log(resultData);
+    },
+    websocketsend(Data){//数据发送
+      this.websock.send(Data);
+    },
+    websocketclose(e){  //关闭
+      console.log('断开连接',e);
+    },
+    cardConnect() {
+      try{
+        if(this.isComOpen==false)          //if reader link failed
+        {
+          // alert("initialcom");
+          this.websocketsend("11|initialcom|100,115200");
+        }
+      }catch(e){alert(e.message);}
+      return;
+    },
+    disconnect() {
+       this.websocketsend("12|exit|"+ this.paramStr);
+    },
+    findCard() {
+      this.websocketsend("132|findcardStr|" + this.paramStr +"0");
+    },
+     _getCmdResult(relPara) {
+      var iRel;
+      var separator = relPara.indexOf(",");
+      if (separator != -1) {
+        iRel = relPara.substr(0, separator);
+      } else
+        iRel = relPara.substr(0);
+
+      return iRel;
+    },
+    _getResultPara(relPara) {
+      var szPara = "";
+      var separator = relPara.indexOf(",");
+      if (separator != -1) {
+        szPara = relPara.substr(separator + 1);
+      }
+      return szPara;
+    },
+    // 取消按钮
+    cancel() {
+      this.visible = false;
+      this.reset();
+    },
+    /** 确定按钮 */
+    submitForm() {
+      //传参给父类卡号
+      this.visible = false;
+      console.log("卡号:" + this.cardId)
+      let signRes = {
+        cardId: this.cardId,
+        signType: this.signType
+      }
+      this.$emit('signRes', signRes); //自定义事件,并传参
+    },
+  },
+
+}
+</script>
+
+<style scoped>
+
+</style>

+ 31 - 9
ui/src/views/tool/card/index.vue

@@ -3,8 +3,6 @@
 </template>
 
 <script>
-import {_getCmdResult, _getResultPara} from "@/common/interface";
-
 export default {
   name : 'test',
   data() {
@@ -19,6 +17,7 @@ export default {
     this.initWebSocket();
   },
   destroyed() {
+    console.log("离开路由之后断开websocket连接")
     this.websock.close() //离开路由之后断开websocket连接
   },
   methods: {
@@ -41,6 +40,7 @@ export default {
       this.websocketsend("10|adaptReader|1");
     },
     websocketonerror(){//连接建立失败重连
+      this.cardId = "服务未运行"
       this.initWebSocket();
     },
     websocketonmessage(e){ //数据接收
@@ -60,8 +60,8 @@ export default {
       var resultData = {
         type: "Result",
         FunctionID: parseInt(funcid),
-        RePara_Int: parseInt(_getCmdResult(arg1)),
-        RePara_Str: _getResultPara(arg1)
+        RePara_Int: parseInt(this._getCmdResult(arg1)),
+        RePara_Str: this._getResultPara(arg1)
       };
       if(resultData.FunctionID == "0"){
         //连接上websocket,连接读卡器
@@ -80,17 +80,18 @@ export default {
           console.log("卡号:" + this.cardId)
           this.websocketsend("145|halt|" + this.paramStr +"");
         }else {
-          console.log("没有卡号:" + this.cardId)
+          this.cardId = this.cardId + "等待卡片,"
           this.findCard()
         }
       }else if (resultData.FunctionID == "45") {
         this.websocketsend("13|beep|" + this.paramStr +"10");
       }else if (resultData.FunctionID == "3") {
+        this.disconnect()
         //寻找卡片
-        let _this = this
-        setTimeout(function (){
-          _this.findCard()
-        }, 1000);
+        // let _this = this
+        // setTimeout(function (){
+        //   _this.findCard()
+        // }, 1000);
       }
       // console.log(resultData);
     },
@@ -110,9 +111,30 @@ export default {
       }catch(e){alert(e.message);}
       return;
     },
+    disconnect() {
+       this.websocketsend("12|exit|"+ this.paramStr);
+    },
     findCard() {
       this.websocketsend("132|findcardStr|" + this.paramStr +"0");
     },
+     _getCmdResult(relPara) {
+      var iRel;
+      var separator = relPara.indexOf(",");
+      if (separator != -1) {
+        iRel = relPara.substr(0, separator);
+      } else
+        iRel = relPara.substr(0);
+
+      return iRel;
+    },
+    _getResultPara(relPara) {
+      var szPara = "";
+      var separator = relPara.indexOf(",");
+      if (separator != -1) {
+        szPara = relPara.substr(separator + 1);
+      }
+      return szPara;
+    }
   },
 
 }