扫码JSSDK载入

This commit is contained in:
iqudoo
2026-04-30 15:16:11 +08:00
parent 4a27189ad4
commit 6b27975a45
6 changed files with 28 additions and 18 deletions

View File

@@ -1,5 +1,4 @@
import './polyfill';
import _global from './polyfill/_global';
import { setConfig, getVersion } from './services/config';
import { onScanListener, offScanListener, setStatusListener, getStatus, startScan, stopScan, clear } from './services/provider/scan';
import { initWxJssdk } from './services/wx';
@@ -8,10 +7,6 @@ import { printDebug } from './utils/logger';
let _readyPromise = null;
let _calledReady = false;
(function () {
_global.__IScanReady__ && _global.__IScanReady__();
})();
export function isReadyCalled() {
return _calledReady;
}
@@ -24,9 +19,9 @@ function config(config) {
return _readyPromise;
}
_readyPromise = Promise.resolve().then(() => {
printDebug('-------------------------------');
printDebug('-------------------------------------');
printDebug('sdk_version:', getVersion());
printDebug('-------------------------------');
printDebug('-------------------------------------');
initWxJssdk();
return Promise.resolve().then(() => {
_calledReady = true;

View File

@@ -1,11 +1,24 @@
import core from "./_core";
import _global from './polyfill/_global';
import { exportSDK } from './_export';
const IScan = exportSDK(core, null, "config", "setStatusListener", "onScanListener",
"offScanListener", "stopScan", "startScan", "clear");
if (typeof window !== 'undefined') {
window.IScan = IScan
function dispatchIScanReady() {
_global.__IScanReady__ && _global.__IScanReady__();
if (typeof Event === "function") {
_global.dispatchEvent(new Event("IScanReady"));
} else {
let event = document.createEvent("Event");
event.initEvent("IScanReady", true, true);
_global.dispatchEvent(event);
}
}
if (typeof _global !== 'undefined') {
_global.IScan = IScan;
dispatchIScanReady();
}
module.exports = {

View File

@@ -47,7 +47,6 @@ function onScannerKeydown(event) {
if (result) {
stopScannerEvent(event);
}
console.log("onScannerKeydown", result);
clearScannerValue();
if (result && _scannerCallback) {
_scannerCallback(result);