|
@@ -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>
|