扫码JSSDK载入
This commit is contained in:
@@ -61,7 +61,6 @@
|
||||
<body>
|
||||
<h1 style="text-align: center;">IScan</h1>
|
||||
<div style="text-align: center;">
|
||||
<button onclick="ready()" class="btn">ready</button>
|
||||
<button onclick="stopScan()" class="btn">stopScan</button>
|
||||
<button onclick="startScan()" class="btn">startScan</button>
|
||||
</div>
|
||||
@@ -120,7 +119,7 @@
|
||||
})
|
||||
} else {
|
||||
window.addEventListener("IScanReady", function () {
|
||||
initSDK(callback);
|
||||
initSDK(options, callback);
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -134,6 +133,7 @@
|
||||
webScanBeepEnabled: true,
|
||||
initWechatJssdk: { apiUrl: url }
|
||||
}, function () {
|
||||
result("初始化成功");
|
||||
IScan.setStatusListener(function (res) {
|
||||
output("status", IScan.getStatus());
|
||||
});
|
||||
@@ -141,7 +141,6 @@
|
||||
result(res);
|
||||
}, "scan", null, 100);
|
||||
output(window.navigator.userAgent);
|
||||
result("初始化成功");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -157,6 +156,8 @@
|
||||
IScan.startScan();
|
||||
}
|
||||
|
||||
ready();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
10
dist/index.html
vendored
10
dist/index.html
vendored
@@ -42,7 +42,7 @@
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
display: none;
|
||||
}</style></head><body><h1 style="text-align: center;">IScan</h1><div style="text-align: center;"><button onclick="ready()" class="btn">ready</button> <button onclick="stopScan()" class="btn">stopScan</button> <button onclick="startScan()" class="btn">startScan</button></div><pre id="output" class="output"></pre><pre id="result" class="result"></pre><pre id="error" class="error"></pre><br><script>(function (params) {
|
||||
}</style></head><body><h1 style="text-align: center;">IScan</h1><div style="text-align: center;"><button onclick="stopScan()" class="btn">stopScan</button> <button onclick="startScan()" class="btn">startScan</button></div><pre id="output" class="output"></pre><pre id="result" class="result"></pre><pre id="error" class="error"></pre><br><script>(function (params) {
|
||||
output(window.navigator.userAgent);
|
||||
window.onerror = function (params) {
|
||||
error(params);
|
||||
@@ -91,7 +91,7 @@
|
||||
})
|
||||
} else {
|
||||
window.addEventListener("IScanReady", function () {
|
||||
initSDK(callback);
|
||||
initSDK(options, callback);
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,7 @@
|
||||
webScanBeepEnabled: true,
|
||||
initWechatJssdk: { apiUrl: url }
|
||||
}, function () {
|
||||
result("初始化成功");
|
||||
IScan.setStatusListener(function (res) {
|
||||
output("status", IScan.getStatus());
|
||||
});
|
||||
@@ -112,7 +113,6 @@
|
||||
result(res);
|
||||
}, "scan", null, 100);
|
||||
output(window.navigator.userAgent);
|
||||
result("初始化成功");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -126,4 +126,6 @@
|
||||
output("call startScan");
|
||||
hide();
|
||||
IScan.startScan();
|
||||
}</script><script src="index.js"></script></body></html>
|
||||
}
|
||||
|
||||
ready();</script><script src="index.js"></script></body></html>
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -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;
|
||||
|
||||
17
src/index.js
17
src/index.js
@@ -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 = {
|
||||
|
||||
@@ -47,7 +47,6 @@ function onScannerKeydown(event) {
|
||||
if (result) {
|
||||
stopScannerEvent(event);
|
||||
}
|
||||
console.log("onScannerKeydown", result);
|
||||
clearScannerValue();
|
||||
if (result && _scannerCallback) {
|
||||
_scannerCallback(result);
|
||||
|
||||
Reference in New Issue
Block a user