From 7cc98a02d914db89be6f26899a8c157b9f708426 Mon Sep 17 00:00:00 2001 From: x_z Date: Sun, 24 Apr 2022 17:38:04 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=8C=BB=E9=99=A2=E5=AE=A2=E6=88=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=A1=B5=E9=9D=A2=E6=90=9C=E7=B4=A2=E6=A1=86=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B8=85=E7=A9=BA=E6=8C=89=E9=92=AE=202.UDI=E6=B5=81?= =?UTF-8?q?=E5=90=91=E6=9F=A5=E8=AF=A2=E6=9F=A5=E8=AF=A2=E6=A1=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=88=86=E6=AE=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/KeyScaner.js | 116 +++++++++++++++++++++++++++++ src/views/sys/bindPlatform.vue | 2 +- src/views/warehouse/ioUdiTrace.vue | 42 ++++++++--- 3 files changed, 149 insertions(+), 11 deletions(-) create mode 100644 src/plugin/KeyScaner.js diff --git a/src/plugin/KeyScaner.js b/src/plugin/KeyScaner.js new file mode 100644 index 0000000..0b8024d --- /dev/null +++ b/src/plugin/KeyScaner.js @@ -0,0 +1,116 @@ +"use strict"; +/** + * 浏览器按键处理 + * howay + * 20200421 + * 1.0 + */ +const KeyScaner = /** @class */ (function () { + function KeyScaner(_dom) { + this.keybufs = []; + this.altBuf = []; + this.isShift = false; + this.lastTime = 0; + /** + * 在收集到文本输入时触发 + * @param text 收集到的连续文本 + */ + this.onInput = function (text) { + }; + this.dom = _dom; + _dom.addEventListener('keydown', this.onKeyDown.bind(this)); + _dom.addEventListener('keyup', this.onKeyUp.bind(this)); + this.interval = setInterval(this.onTick.bind(this), 100); + } + + KeyScaner.prototype.appendChar = function (c) { + this.keybufs.push(c); + }; + KeyScaner.prototype.onKeyDown = function (ev) { + this.lastTime = new Date().getTime(); + if (ev.key == "Alt") { + if (ev.shiftKey || ev.ctrlKey || ev.metaKey) { + return; + } + } else if (ev.key == "Shift") { + if (ev.altKey || ev.ctrlKey || ev.metaKey) { + return; + } + this.isShift = true; + } else if (ev.key == "Enter") { + if (ev.shiftKey || ev.altKey || ev.ctrlKey || ev.metaKey) { + return; + } + console.log("监听到回车键。。。。。。。。。。。。。。。。。。。"); + this.appendChar("\r"); + this.completeInput(); //立即完成输入 + } else if (ev.key == "Delete" || ev.key == "Backspace") { + console.log("监听到删除键。。。。。。。。。。。。。。。。。。。"); + this.dom.innerTex = ""; + this.appendChar("delete"); + this.completeInput(); //立即完成输入 + } else { + if (ev.key.length == 1) { + var charCode = ev.key.charCodeAt(0); + if (charCode >= 48 && charCode <= 57) { + if (ev.altKey) { + this.altBuf.push(ev.key); + } else { + this.appendChar(ev.key); + } + } else if ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122)) { + //忽略大小写锁定键,直接通过SHIFT键判断大小写 + if (ev.shiftKey) { + this.appendChar(ev.key.toUpperCase()); + } else { + this.appendChar(ev.key.toLowerCase()); + } + } else { + this.appendChar(ev.key); + } + } + //忽略其他控制键 + } + }; + KeyScaner.prototype.onKeyUp = function (ev) { + this.lastTime = new Date().getTime(); + if (ev.key == "Alt") { + if (this.altBuf && this.altBuf.length > 0) { + var str = this.altBuf.join(""); + var num = parseInt(str); + var c = String.fromCharCode(num); + this.appendChar(c); + this.altBuf = []; + } + } else if (ev.key == "Shift") { + this.isShift = false; + } + }; + KeyScaner.prototype.completeInput = function () { + var text = this.keybufs.join(""); + this.keybufs = []; + if (this.onInput) { + this.onInput.bind(this)(text); + } + }; + KeyScaner.prototype.onTick = function () { + if (this.keybufs && this.keybufs.length > 0 && (!this.altBuf || this.altBuf.length == 0) && new Date().getTime() - this.lastTime > 500) { + //有缓存的字符,且没有缓存的alt字符 且 与上次按键时间超过500毫秒。 收集输入 + // this.completeInput(); + } + }; + /** + * 释放资源 + */ + KeyScaner.prototype.dispose = function () { + this.dom.removeEventListener('keydown', this.onKeyDown); + this.dom.removeEventListener('keyup', this.onKeyUp); + clearInterval(this.interval); + }; + return KeyScaner; +}()); + +export default { + KeyScaner +} + diff --git a/src/views/sys/bindPlatform.vue b/src/views/sys/bindPlatform.vue index 159fb97..646de92 100644 --- a/src/views/sys/bindPlatform.vue +++ b/src/views/sys/bindPlatform.vue @@ -3,7 +3,7 @@ - + diff --git a/src/views/warehouse/ioUdiTrace.vue b/src/views/warehouse/ioUdiTrace.vue index 1ffa711..542cbd9 100644 --- a/src/views/warehouse/ioUdiTrace.vue +++ b/src/views/warehouse/ioUdiTrace.vue @@ -10,11 +10,16 @@ @submit.native.prevent > - - + + + 分段扫码 @@ -40,7 +45,7 @@ > - + @@ -50,13 +55,13 @@ prop="orderId" show-overflow-tooltip="true" > - - + +