From 86108ff4e9719a799d2ada419039681a1c6f7bef Mon Sep 17 00:00:00 2001 From: BianLzhaoMin <11485688+bianliangzhaomin123@user.noreply.gitee.com> Date: Thu, 21 Aug 2025 10:46:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../person-entry/add-or-edit-form.vue | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/views/construction-person/entry-and-exit-manage/person-entry/add-or-edit-form.vue b/src/views/construction-person/entry-and-exit-manage/person-entry/add-or-edit-form.vue index 0d702fd..f54e109 100644 --- a/src/views/construction-person/entry-and-exit-manage/person-entry/add-or-edit-form.vue +++ b/src/views/construction-person/entry-and-exit-manage/person-entry/add-or-edit-form.vue @@ -631,7 +631,7 @@ export default { return { // 身份证读卡器表单 idCardReaderForm: { - idCardReaderAddress: '127.0.0.1:8080', // 身份证读卡器地址 + idCardReaderAddress: 'ws://127.0.0.1:24011', // 身份证读卡器地址 }, // 身份证信息表单 idCardInfoForm: { @@ -931,6 +931,7 @@ export default { editUploadFileList: [], // 编辑时已上传的文件列表 isEditContract: false, // 是否是编辑状态 + webSocket: null, // websocket连接 } }, methods: { @@ -1439,6 +1440,36 @@ export default { const age = new Date().getFullYear() - birthday.slice(0, 4) this.idCardInfoForm.age = age }, + + // 建立一个websocket连接 + createWebSocket() { + this.webSocket = new WebSocket( + this.idCardReaderForm.idCardReaderAddress, + ) + + this.webSocket.onopen = function (evt) { + console.log('建立连接成功', evt) + } + this.webSocket.onclose = function (evt) { + console.log('断开连接', evt) + } + this.webSocket.onmessage = function (evt) { + console.log('收到消息', evt) + } + this.webSocket.onerror = function (evt) { + console.log('错误', evt) + } + }, + + // 断开websocket连接 + closeWebSocket() { + this.webSocket.close() + }, + + // 下载身份证读卡器驱动 + downloadIdCardReaderDriver() { + // window.open(this.idCardReaderForm.idCardReaderAddress) + }, }, async created() { @@ -1451,6 +1482,13 @@ export default { }) this.getLotProjectSelectList() + this.createWebSocket() + }, + + beforeDestroy() { + if (this.webSocket) { + this.closeWebSocket() + } }, watch: {