扫码JSSDK载入
This commit is contained in:
@@ -61,7 +61,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1 style="text-align: center;">IScan</h1>
|
<h1 style="text-align: center;">IScan</h1>
|
||||||
<div style="text-align: center;">
|
<div style="text-align: center;">
|
||||||
<button onclick="ready()" class="btn">ready</button>
|
|
||||||
<button onclick="stopScan()" class="btn">stopScan</button>
|
<button onclick="stopScan()" class="btn">stopScan</button>
|
||||||
<button onclick="startScan()" class="btn">startScan</button>
|
<button onclick="startScan()" class="btn">startScan</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -120,7 +119,7 @@
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
window.addEventListener("IScanReady", function () {
|
window.addEventListener("IScanReady", function () {
|
||||||
initSDK(callback);
|
initSDK(options, callback);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,6 +133,7 @@
|
|||||||
webScanBeepEnabled: true,
|
webScanBeepEnabled: true,
|
||||||
initWechatJssdk: { apiUrl: url }
|
initWechatJssdk: { apiUrl: url }
|
||||||
}, function () {
|
}, function () {
|
||||||
|
result("初始化成功");
|
||||||
IScan.setStatusListener(function (res) {
|
IScan.setStatusListener(function (res) {
|
||||||
output("status", IScan.getStatus());
|
output("status", IScan.getStatus());
|
||||||
});
|
});
|
||||||
@@ -141,7 +141,6 @@
|
|||||||
result(res);
|
result(res);
|
||||||
}, "scan", null, 100);
|
}, "scan", null, 100);
|
||||||
output(window.navigator.userAgent);
|
output(window.navigator.userAgent);
|
||||||
result("初始化成功");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +156,8 @@
|
|||||||
IScan.startScan();
|
IScan.startScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ready();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
10
dist/index.html
vendored
10
dist/index.html
vendored
@@ -42,7 +42,7 @@
|
|||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
display: none;
|
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);
|
output(window.navigator.userAgent);
|
||||||
window.onerror = function (params) {
|
window.onerror = function (params) {
|
||||||
error(params);
|
error(params);
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
window.addEventListener("IScanReady", function () {
|
window.addEventListener("IScanReady", function () {
|
||||||
initSDK(callback);
|
initSDK(options, callback);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,6 +105,7 @@
|
|||||||
webScanBeepEnabled: true,
|
webScanBeepEnabled: true,
|
||||||
initWechatJssdk: { apiUrl: url }
|
initWechatJssdk: { apiUrl: url }
|
||||||
}, function () {
|
}, function () {
|
||||||
|
result("初始化成功");
|
||||||
IScan.setStatusListener(function (res) {
|
IScan.setStatusListener(function (res) {
|
||||||
output("status", IScan.getStatus());
|
output("status", IScan.getStatus());
|
||||||
});
|
});
|
||||||
@@ -112,7 +113,6 @@
|
|||||||
result(res);
|
result(res);
|
||||||
}, "scan", null, 100);
|
}, "scan", null, 100);
|
||||||
output(window.navigator.userAgent);
|
output(window.navigator.userAgent);
|
||||||
result("初始化成功");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,4 +126,6 @@
|
|||||||
output("call startScan");
|
output("call startScan");
|
||||||
hide();
|
hide();
|
||||||
IScan.startScan();
|
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 './polyfill';
|
||||||
import _global from './polyfill/_global';
|
|
||||||
import { setConfig, getVersion } from './services/config';
|
import { setConfig, getVersion } from './services/config';
|
||||||
import { onScanListener, offScanListener, setStatusListener, getStatus, startScan, stopScan, clear } from './services/provider/scan';
|
import { onScanListener, offScanListener, setStatusListener, getStatus, startScan, stopScan, clear } from './services/provider/scan';
|
||||||
import { initWxJssdk } from './services/wx';
|
import { initWxJssdk } from './services/wx';
|
||||||
@@ -8,10 +7,6 @@ import { printDebug } from './utils/logger';
|
|||||||
let _readyPromise = null;
|
let _readyPromise = null;
|
||||||
let _calledReady = false;
|
let _calledReady = false;
|
||||||
|
|
||||||
(function () {
|
|
||||||
_global.__IScanReady__ && _global.__IScanReady__();
|
|
||||||
})();
|
|
||||||
|
|
||||||
export function isReadyCalled() {
|
export function isReadyCalled() {
|
||||||
return _calledReady;
|
return _calledReady;
|
||||||
}
|
}
|
||||||
@@ -24,9 +19,9 @@ function config(config) {
|
|||||||
return _readyPromise;
|
return _readyPromise;
|
||||||
}
|
}
|
||||||
_readyPromise = Promise.resolve().then(() => {
|
_readyPromise = Promise.resolve().then(() => {
|
||||||
printDebug('-------------------------------');
|
printDebug('-------------------------------------');
|
||||||
printDebug('sdk_version:', getVersion());
|
printDebug('sdk_version:', getVersion());
|
||||||
printDebug('-------------------------------');
|
printDebug('-------------------------------------');
|
||||||
initWxJssdk();
|
initWxJssdk();
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
_calledReady = true;
|
_calledReady = true;
|
||||||
|
|||||||
17
src/index.js
17
src/index.js
@@ -1,11 +1,24 @@
|
|||||||
import core from "./_core";
|
import core from "./_core";
|
||||||
|
import _global from './polyfill/_global';
|
||||||
import { exportSDK } from './_export';
|
import { exportSDK } from './_export';
|
||||||
|
|
||||||
const IScan = exportSDK(core, null, "config", "setStatusListener", "onScanListener",
|
const IScan = exportSDK(core, null, "config", "setStatusListener", "onScanListener",
|
||||||
"offScanListener", "stopScan", "startScan", "clear");
|
"offScanListener", "stopScan", "startScan", "clear");
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
function dispatchIScanReady() {
|
||||||
window.IScan = IScan
|
_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 = {
|
module.exports = {
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ function onScannerKeydown(event) {
|
|||||||
if (result) {
|
if (result) {
|
||||||
stopScannerEvent(event);
|
stopScannerEvent(event);
|
||||||
}
|
}
|
||||||
console.log("onScannerKeydown", result);
|
|
||||||
clearScannerValue();
|
clearScannerValue();
|
||||||
if (result && _scannerCallback) {
|
if (result && _scannerCallback) {
|
||||||
_scannerCallback(result);
|
_scannerCallback(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user