代码备份

20240912_adapter
yewj 8 months ago
parent a09c6bca83
commit b42eb649c7

@ -6,110 +6,141 @@
* 1.0 * 1.0
*/ */
const KeyScaner = /** @class */ (function () { const KeyScaner = /** @class */ (function () {
function KeyScaner(_dom) { function KeyScaner(_dom) {
this.keybufs = []; this.keybufs = [];
this.altBuf = []; this.altBuf = [];
this.isShift = false; this.isShift = false;
this.lastTime = 0; this.lastTime = 0;
/** /**
* 在收集到文本输入时触发 * 在收集到文本输入时触发
* @param text 收集到的连续文本 * @param text 收集到的连续文本
*/ */
this.onInput = function (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.dom = _dom;
this.lastTime = new Date().getTime(); _dom.addEventListener('keydown', this.onKeyDown.bind(this));
if (ev.key == "Alt") { _dom.addEventListener('keyup', this.onKeyUp.bind(this));
if (ev.shiftKey || ev.ctrlKey || ev.metaKey) { _dom.addEventListener('keypress', this.onKeyPress.bind(this));
return; this.interval = setInterval(this.onTick.bind(this), 100);
} }
} else if (ev.key == "Shift") {
if (ev.altKey || ev.ctrlKey || ev.metaKey) { KeyScaner.prototype.appendChar = function (c) {
return; this.keybufs.push(c);
} // console.log('appendChar:', c, this.keybufs)
this.isShift = true; };
} else if (ev.key == "Enter") { KeyScaner.prototype.onKeyDown = function (ev) {
if (ev.shiftKey || ev.altKey || ev.ctrlKey || ev.metaKey) { this.lastTime = new Date().getTime();
return; if (ev.key == "Alt") {
} if (ev.shiftKey || ev.ctrlKey || ev.metaKey) {
this.appendChar("\r"); return;
this.completeInput(); //立即完成输入 }
} else if (ev.key == "Delete" || ev.key == "Backspace") { } else if (ev.key == "Shift") {
this.dom.innerTex = ""; if (ev.altKey || ev.ctrlKey || ev.metaKey) {
this.appendChar("delete"); return;
this.completeInput(); //立即完成输入 }
this.isShift = true;
} else if (ev.key == "Enter") {
if (ev.shiftKey || ev.altKey || ev.ctrlKey || ev.metaKey) {
return;
}
this.appendChar("\r");
this.completeInput(); //立即完成输入
} else if (ev.key == "Delete" || ev.key == "Backspace") {
this.dom.innerTex = "";
this.appendChar("delete");
this.completeInput(); //立即完成输入
} else {
if (ev.key.length == 1) {
var charCode = ev.key.charCodeAt(0);
// console.log("key="+charCode);
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 { } else {
if (ev.key.length == 1) { this.appendChar(ev.key);
var charCode = ev.key.charCodeAt(0);
// console.log("key="+charCode);
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.onKeyUp = function (ev) {
this.lastTime = new Date().getTime();
if (ev.charCode === 29) {
var str = this.altBuf.join("");
var num = parseInt(str);
var c = String.fromCharCode(num);
this.appendChar(c);
this.altBuf = [];
console.log('onKeyUp success:', ev.charCode, this.keybufs);
} else 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.onKeyPress = function (ev) {
this.lastTime = new Date().getTime();
const char = String.fromCharCode(ev.charCode);
console.log('KeyPress:', ev.charCode, char);
/** /**
* 释放资源 * if (ev.charCode === 29) {
this.appendChar(char);
// console.log('KeyPress success:', ev.charCode, this.keybufs);
} else
*/ */
KeyScaner.prototype.dispose = function () { if (char == '\n') {
this.dom.removeEventListener('keydown', this.onKeyDown); this.completeInput();
this.dom.removeEventListener('keyup', this.onKeyUp); }
clearInterval(this.interval);
}; // if (ev.charCode === 49) {
return KeyScaner; // const char = String.fromCharCode(ev.charCode);
// this.appendChar(char);
// }
};
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);
this.dom.removeEventListener('keypress', this.onKeyPress);
clearInterval(this.interval);
};
return KeyScaner;
}()); }());
export default { export default {
KeyScaner KeyScaner
} }

@ -772,7 +772,7 @@ export default {
this.filterQuery.endTime = null; this.filterQuery.endTime = null;
} }
let query = JSON.parse(JSON.stringify(this.filterQuery)); let query = JSON.parse(JSON.stringify(this.filterQuery));
query.workPlaceCode = null // query.workPlaceCode = null
orderPage(query).then(res => { orderPage(query).then(res => {
this.loading = false this.loading = false
this.list = res.data.list || [] this.list = res.data.list || []

@ -324,7 +324,7 @@
> >
<selectPrescribeDialog <selectPrescribeDialog
ref="childRef" ref="childRef"
:workPlaceCode="null" :workPlaceCode="this.workplaceId"
:busType="this.formData.busType" :busType="this.formData.busType"
:fromCorp="this.formData.fromCorp" :fromCorp="this.formData.fromCorp"
:confirmSelect="this.confirmSelect" :confirmSelect="this.confirmSelect"

@ -642,7 +642,9 @@ export default {
this.filterQuery.startTime = null; this.filterQuery.startTime = null;
this.filterQuery.endTime = null; this.filterQuery.endTime = null;
} }
this.filterQuery.workPlaceCode = null // this.filterQuery.workPlaceCode = null
this.filterQuery.workPlaceCode = this.$route.query.workplaceId
// workPlaceCode: this.workplaceId,
this.filterQuery.busType = this.busType this.filterQuery.busType = this.busType
// this.filterQuery.fromCorp = this.fromCorp // this.filterQuery.fromCorp = this.fromCorp
this.filterQuery.excludeWorkCode = null this.filterQuery.excludeWorkCode = null

@ -1928,8 +1928,26 @@ export default {
}; };
var that = this; var that = this;
var inputer = document.getElementById("inputer"); var inputer = document.getElementById("inputer");
// inputer.addEventListener('keypress', function(e) {
// if (e.charCode === 29) {
// // this.value += String.fromCharCode(e.which);
// that.sictomText = that.sictomText + String.fromCharCode(e.which);
// console.log(that.sictomText+"*")
// }
//
// // if (that.sitcomScan) {
// // let tempTxt = text;
// // let str = tempTxt.replace(/[\r]/g, "");
// // that.sictomText = that.sictomText + str;
// // that.codeFormData.code = that.sictomText;
// // } else {
// // that.codeFormData.code = text;
// // }
// });
window.sc = new A.KeyScaner(inputer); //DOM window.sc = new A.KeyScaner(inputer); //DOM
sc.onInput = function (text) { sc.onInput = function (text) {
if (text.includes("delete")) { if (text.includes("delete")) {
that.codeFormData.code = ""; that.codeFormData.code = "";
that.sictomText = ""; that.sictomText = "";
@ -1941,8 +1959,11 @@ export default {
let str = tempTxt.replace(/[\r]/g, ""); let str = tempTxt.replace(/[\r]/g, "");
that.sictomText = that.sictomText + str; that.sictomText = that.sictomText + str;
that.codeFormData.code = that.sictomText; that.codeFormData.code = that.sictomText;
console.log(text + "*1")
} else { } else {
console.log(text + "*2")
that.codeFormData.code = text; that.codeFormData.code = text;
that.scanCode = text;
} }
}; };
inputer.focus(); inputer.focus();

Loading…
Cancel
Save