Commit 0dab6a95 authored by jiangjiantao's avatar jiangjiantao

兼容摄像头扫描

parent cdd140bd
...@@ -7,10 +7,20 @@ export default class scan { ...@@ -7,10 +7,20 @@ export default class scan {
page[f] = (...args) => { page[f] = (...args) => {
if (f === 'onShow') { if (f === 'onShow') {
if (!page._keyEventListener) { if (!page._keyEventListener) {
//摄像头
my.ix.onCodeScan((r) => {
if (r.success){
let cur = getCurrentPages().slice(-1)[0];
cur.onKeyPress.call(cur, code);
}
console.log('code: ' + r.code);
});
//物理扫码枪
my.ix.onKeyEventChange(page._keyEventListener = (r) => { my.ix.onKeyEventChange(page._keyEventListener = (r) => {
let cur = getCurrentPages().slice(-1)[0]; let cur = getCurrentPages().slice(-1)[0];
if (cur && cur.onKeyPress) { if (cur && cur.onKeyPress) {
if (isScaning == false) { if (isScaning == false) {
isScaning = true isScaning = true
code = (r.keyCode - 7) + '' code = (r.keyCode - 7) + ''
...@@ -34,6 +44,8 @@ export default class scan { ...@@ -34,6 +44,8 @@ export default class scan {
if (page._keyEventListener) { if (page._keyEventListener) {
my.ix.offKeyEventChange(page._keyEventListener); my.ix.offKeyEventChange(page._keyEventListener);
page._keyEventListener = null; page._keyEventListener = null;
//摄像头资源释放
my.ix.offCodeScan();
} }
} }
if (raw instanceof Function) { if (raw instanceof Function) {
......
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