init commit
This commit is contained in:
159
demo.html
Normal file
159
demo.html
Normal file
@@ -0,0 +1,159 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
|
||||
<title>Demo</title>
|
||||
<!-- 添加vconsole-->
|
||||
<script src="https://cdn.jsdelivr.net/npm/vconsole@3.12.0/dist/vconsole.min.js"></script>
|
||||
<script>
|
||||
var vconsole = new VConsole();
|
||||
</script>
|
||||
<style>
|
||||
.btn {
|
||||
width: auto;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
margin-bottom: 5px;
|
||||
margin-left: 5px;
|
||||
border: 1px solid rgb(28, 79, 180);
|
||||
background: rgb(71, 123, 228);
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.output {
|
||||
border: 1px solid #eeeeee;
|
||||
background: #f1f1f1;
|
||||
padding: 10px;
|
||||
min-height: 40px;
|
||||
max-height: 400px;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.result {
|
||||
border: 1px solid rgb(28, 79, 180);
|
||||
background: rgb(71, 123, 228);
|
||||
color: #ffffff;
|
||||
padding: 10px;
|
||||
min-height: 40px;
|
||||
max-height: 1000px;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.error {
|
||||
border: 1px solid #6e2020;
|
||||
background: #804646;
|
||||
color: #ffffff;
|
||||
padding: 10px;
|
||||
min-height: 40px;
|
||||
max-height: 1000px;
|
||||
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) {
|
||||
output(window.navigator.userAgent);
|
||||
window.onerror = function (params) {
|
||||
error(params);
|
||||
}
|
||||
})();
|
||||
|
||||
function hide() {
|
||||
document.getElementById("result").style.display = "none"
|
||||
document.getElementById("result").innerHTML = "";
|
||||
document.getElementById("error").style.display = "none"
|
||||
document.getElementById("error").innerHTML = "";
|
||||
}
|
||||
|
||||
function error(data) {
|
||||
document.getElementById("result").style.display = "none"
|
||||
document.getElementById("result").innerHTML = "";
|
||||
document.getElementById("error").style.display = "block"
|
||||
document.getElementById("error").innerHTML = JSON.stringify(data);
|
||||
// console.log("error:", data);
|
||||
}
|
||||
|
||||
function result(data) {
|
||||
document.getElementById("error").style.display = "none"
|
||||
document.getElementById("error").innerHTML = "";
|
||||
document.getElementById("result").style.display = "block"
|
||||
document.getElementById("result").innerHTML = JSON.stringify(data);
|
||||
// console.log("result:", data);
|
||||
}
|
||||
|
||||
function output(key, data) {
|
||||
document.getElementById("output").innerHTML = key;
|
||||
if (data) {
|
||||
document.getElementById("output").innerHTML += "\n\n";
|
||||
document.getElementById("output").innerHTML += JSON.stringify(data);
|
||||
document.getElementById("output").innerHTML += "\n\n";
|
||||
// console.log("output:", data);
|
||||
}
|
||||
}
|
||||
|
||||
function initSDK(options, callback) {
|
||||
if (window.IScan) {
|
||||
IScan.config(options).then(function () {
|
||||
callback && callback();
|
||||
}).catch(function (err) {
|
||||
error(err);
|
||||
})
|
||||
} else {
|
||||
window.addEventListener("IScanReady", function () {
|
||||
initSDK(callback);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function ready() {
|
||||
output("call ready");
|
||||
hide();
|
||||
var url = "https://vet.iqudoo.com/api?action=api.biz.wechat.JSSDKConfig";
|
||||
initSDK({ initWechatJssdk: { apiUrl: url } }, function () {
|
||||
IScan.setStatusListener(function (res) {
|
||||
output("status", IScan.getStatus());
|
||||
});
|
||||
IScan.onScanListener(function (res) {
|
||||
result(res);
|
||||
}, "scan", null, 100);
|
||||
output(window.navigator.userAgent);
|
||||
result("初始化成功");
|
||||
});
|
||||
}
|
||||
|
||||
function stopScan() {
|
||||
output("call stopScan");
|
||||
hide();
|
||||
IScan.stopScan();
|
||||
}
|
||||
|
||||
function startScan() {
|
||||
output("call startScan");
|
||||
hide();
|
||||
IScan.startScan();
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user