You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.7 KiB
105 lines
3.7 KiB
2 years ago
|
"use strict";
|
||
|
const common_vendor = require("../common/vendor.js");
|
||
|
const _sfc_main = {
|
||
|
setup() {
|
||
|
let details = common_vendor.reactive({
|
||
|
activity: null,
|
||
|
receiver: null,
|
||
|
intentFilter: null
|
||
|
});
|
||
|
common_vendor.onLoad(() => {
|
||
|
initScan();
|
||
|
startScan();
|
||
|
});
|
||
|
common_vendor.onHide(() => {
|
||
|
stopScan();
|
||
|
});
|
||
|
common_vendor.onUnload(() => {
|
||
|
details.stopScan();
|
||
|
common_vendor.index.$off("scancodedate");
|
||
|
});
|
||
|
function initScan() {
|
||
|
if (plus) {
|
||
|
details.activity = plus.android.runtimeMainActivity();
|
||
|
var IntentFilter = plus.android.importClass("android.content.IntentFilter");
|
||
|
details.intentFilter = new IntentFilter();
|
||
|
details.intentFilter.addAction("scan.rcv.message");
|
||
|
details.receiver = plus.android.implements("io.dcloud.feature.internal.reflect.BroadcastReceiver", {
|
||
|
onReceive: function(context, intent) {
|
||
|
console.log("intent", intent);
|
||
|
plus.android.importClass(intent);
|
||
|
let content = utf8ByteToUnicodeStr(intent.getByteArrayExtra("barocode"));
|
||
|
common_vendor.index.$emit("scancodedate", content.replace(/\n/g, ""));
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
function utf8ByteToUnicodeStr(utf8Bytes) {
|
||
|
var unicodeStr = "";
|
||
|
for (var pos = 0; pos < utf8Bytes.length; ) {
|
||
|
var flag = utf8Bytes[pos];
|
||
|
var unicode = 0;
|
||
|
if (flag >>> 7 === 0) {
|
||
|
unicodeStr += String.fromCharCode(utf8Bytes[pos]);
|
||
|
pos += 1;
|
||
|
} else if ((flag & 252) === 252) {
|
||
|
unicode = (utf8Bytes[pos] & 3) << 30;
|
||
|
unicode |= (utf8Bytes[pos + 1] & 63) << 24;
|
||
|
unicode |= (utf8Bytes[pos + 2] & 63) << 18;
|
||
|
unicode |= (utf8Bytes[pos + 3] & 63) << 12;
|
||
|
unicode |= (utf8Bytes[pos + 4] & 63) << 6;
|
||
|
unicode |= utf8Bytes[pos + 5] & 63;
|
||
|
unicodeStr += String.fromCodePoint(unicode);
|
||
|
pos += 6;
|
||
|
} else if ((flag & 248) === 248) {
|
||
|
unicode = (utf8Bytes[pos] & 7) << 24;
|
||
|
unicode |= (utf8Bytes[pos + 1] & 63) << 18;
|
||
|
unicode |= (utf8Bytes[pos + 2] & 63) << 12;
|
||
|
unicode |= (utf8Bytes[pos + 3] & 63) << 6;
|
||
|
unicode |= utf8Bytes[pos + 4] & 63;
|
||
|
unicodeStr += String.fromCodePoint(unicode);
|
||
|
pos += 5;
|
||
|
} else if ((flag & 240) === 240) {
|
||
|
unicode = (utf8Bytes[pos] & 15) << 18;
|
||
|
unicode |= (utf8Bytes[pos + 1] & 63) << 12;
|
||
|
unicode |= (utf8Bytes[pos + 2] & 63) << 6;
|
||
|
unicode |= utf8Bytes[pos + 3] & 63;
|
||
|
unicodeStr += String.fromCodePoint(unicode);
|
||
|
pos += 4;
|
||
|
} else if ((flag & 224) === 224) {
|
||
|
unicode = (utf8Bytes[pos] & 31) << 12;
|
||
|
unicode |= (utf8Bytes[pos + 1] & 63) << 6;
|
||
|
unicode |= utf8Bytes[pos + 2] & 63;
|
||
|
unicodeStr += String.fromCharCode(unicode);
|
||
|
pos += 3;
|
||
|
} else if ((flag & 192) === 192) {
|
||
|
unicode = (utf8Bytes[pos] & 63) << 6;
|
||
|
unicode |= utf8Bytes[pos + 1] & 63;
|
||
|
unicodeStr += String.fromCharCode(unicode);
|
||
|
pos += 2;
|
||
|
} else {
|
||
|
unicodeStr += String.fromCharCode(utf8Bytes[pos]);
|
||
|
pos += 1;
|
||
|
}
|
||
|
}
|
||
|
return unicodeStr;
|
||
|
}
|
||
|
function startScan() {
|
||
|
details.activity.registerReceiver(details.receiver, details.intentFilter);
|
||
|
}
|
||
|
function stopScan() {
|
||
|
details.activity.unregisterReceiver(details.receiver);
|
||
|
}
|
||
|
return {
|
||
|
startScan,
|
||
|
stopScan,
|
||
|
initScan
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||
|
return {};
|
||
|
}
|
||
|
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "F:/物流/logPm/compoment/saomiao3.vue"]]);
|
||
|
wx.createComponent(Component);
|