Commit 3a05fea7 authored by jiangjiantao's avatar jiangjiantao

扫码枪工具类

parent c48667ff
export default class scan {
static Page(page) {
['onShow', 'onHide', 'onUnload'].forEach((f) => {
const raw = page[f];
var code = '';
var isScaning = false;
page[f] = (...args) => {
if (f === 'onShow') {
if (!page._keyEventListener) {
my.ix.onKeyEventChange(page._keyEventListener = (r) => {
let cur = getCurrentPages().slice(-1)[0];
if (cur && cur.onKeyPress){
if (isScaning == false) {
isScaning = true
code = (r.keyCode - 7)+''
setTimeout(() => {
cur.onKeyPress.call(cur, code);
isScaning = false
}, 500);
}else{
//特殊处理 keycode需要减7
code = code + (r.keyCode - 7)
}
}
});
}
} else if (f === 'onHide' || f === 'onUnload') {
if (page._keyEventListener) {
my.ix.offKeyEventChange(page._keyEventListener);
page._keyEventListener = null;
}
}
if (raw instanceof Function) {
let cur = getCurrentPages().slice(-1)[0];
raw.call(cur, ...args);
}
};
});
return Page(page);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment