281 lines
7.9 KiB
HTML
281 lines
7.9 KiB
HTML
<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no"/><title>IScan 使用示例</title><script src="https://cdn.jsdelivr.net/npm/vconsole@3.12.0/dist/vconsole.min.js"></script><script>var vconsole = new VConsole();</script><style>* {
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
body {
|
||
margin: 0;
|
||
color: #17233d;
|
||
background: #f5f7fb;
|
||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.page {
|
||
max-width: 960px;
|
||
margin: 0 auto;
|
||
padding: 20px 16px 40px;
|
||
}
|
||
|
||
.hero {
|
||
padding: 28px 20px;
|
||
color: #ffffff;
|
||
border-radius: 18px;
|
||
background: linear-gradient(135deg, #1b63f4, #13c2c2);
|
||
box-shadow: 0 16px 36px rgba(27, 99, 244, 0.2);
|
||
}
|
||
|
||
.hero h1 {
|
||
margin: 0 0 8px;
|
||
font-size: 30px;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.hero p {
|
||
margin: 0;
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||
gap: 16px;
|
||
margin-top: 16px;
|
||
}
|
||
|
||
.card {
|
||
padding: 18px;
|
||
border: 1px solid #e8edf7;
|
||
border-radius: 16px;
|
||
background: #ffffff;
|
||
box-shadow: 0 10px 28px rgba(23, 35, 61, 0.06);
|
||
}
|
||
|
||
.card h2 {
|
||
margin: 0 0 12px;
|
||
font-size: 18px;
|
||
}
|
||
|
||
.card p {
|
||
margin: 8px 0;
|
||
color: #53627c;
|
||
}
|
||
|
||
.feature-list {
|
||
margin: 0;
|
||
padding-left: 18px;
|
||
color: #53627c;
|
||
}
|
||
|
||
.feature-list li {
|
||
margin: 6px 0;
|
||
}
|
||
|
||
.actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 12px;
|
||
margin-top: 12px;
|
||
}
|
||
|
||
.btn {
|
||
min-width: 128px;
|
||
height: 44px;
|
||
padding: 0 18px;
|
||
border: 0;
|
||
border-radius: 999px;
|
||
color: #ffffff;
|
||
background: #1b63f4;
|
||
font-size: 15px;
|
||
font-weight: 600;
|
||
box-shadow: 0 8px 18px rgba(27, 99, 244, 0.24);
|
||
}
|
||
|
||
.btn.secondary {
|
||
color: #1b63f4;
|
||
background: #eef4ff;
|
||
box-shadow: none;
|
||
}
|
||
|
||
.status {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
min-height: 28px;
|
||
padding: 4px 12px;
|
||
border-radius: 999px;
|
||
color: #1b63f4;
|
||
background: #eef4ff;
|
||
font-weight: 600;
|
||
}
|
||
|
||
pre {
|
||
margin: 0;
|
||
overflow: auto;
|
||
white-space: pre-wrap;
|
||
word-break: break-word;
|
||
font-family: Menlo, Consolas, monospace;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.panel {
|
||
min-height: 72px;
|
||
padding: 12px;
|
||
border-radius: 12px;
|
||
background: #f7f9fc;
|
||
color: #53627c;
|
||
}
|
||
|
||
.result {
|
||
display: none;
|
||
color: #0f5132;
|
||
background: #d1f5e0;
|
||
}
|
||
|
||
.error {
|
||
display: none;
|
||
color: #842029;
|
||
background: #f8d7da;
|
||
}
|
||
|
||
.code {
|
||
color: #334155;
|
||
background: #0f172a;
|
||
}
|
||
|
||
.code pre {
|
||
color: #dbeafe;
|
||
}
|
||
|
||
@media (max-width: 720px) {
|
||
.grid {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
|
||
.hero h1 {
|
||
font-size: 26px;
|
||
}
|
||
|
||
.btn {
|
||
flex: 1;
|
||
}
|
||
}
|
||
|
||
section {
|
||
margin-bottom: 16px;
|
||
}</style></head><body><main class="page"><section class="hero"><h1>IScan 通用扫码SDK</h1><p>统一接入桥接扫码、微信小程序、微信 JSSDK 扫码、Web 摄像头扫码、图片识别和扫码枪输入。</p></section><section class="grid"><div class="card"><h2>功能说明</h2><ul class="feature-list"><li>支持桥接扫码、微信 JSSDK 扫码、Web 摄像头扫码、图片识别和扫码枪输入。</li><li>浏览器环境使用WASM库识别二维码和条形码。</li><li>扫码结果由监听规则统一回调,支持正则匹配和优先级排序。</li></ul></div><div class="card"><h2>当前状态</h2><p>SDK 状态:<span id="status" class="status">loading</span></p><p>运行环境:</p><pre id="output" class="panel"></pre></div></section><section class="card"><h2>操作</h2><p>点击开始后,会按桥接、微信、Web 摄像头、图片识别的顺序选择可用扫码方式。</p><div class="actions"><button onclick="startScan()" class="btn">开始扫码</button> <button onclick="scanImage()" class="btn secondary">选择图片识别</button> <button onclick="stopScan()" class="btn secondary">停止扫码</button></div></section><section class="card"><h2>扫码结果</h2><pre id="result" class="panel result"></pre></section><section class="card"><h2>错误信息</h2><pre id="error" class="panel error"></pre><p style="color: #919191">错误信息可能来源于扫码结果、扫码过程、扫码初始化等。</p></section><section class="card code"><h2>接入方式</h2><pre>IScan.config({
|
||
webScanEnabled: true,
|
||
webScanCanvasEnabled: true,
|
||
webScanCloseButtonStyle: "background: rgba(27, 99, 244, 0.88);",
|
||
scanBeepEnabled: true,
|
||
initWechatJssdk: {
|
||
apiUrl: "https://your-domain.com/wechat/jssdk-config"
|
||
}
|
||
}).then(function () {
|
||
// 监听扫码状态
|
||
IScan.setStatusListener(function () {
|
||
console.log("status:", IScan.getStatus());
|
||
});
|
||
// 监听扫码结果
|
||
IScan.onScanListener(function (res) {
|
||
console.log("scan result:", res);
|
||
}, "scan", null, 100);
|
||
});
|
||
|
||
IScan.startScan();
|
||
IScan.scanImage();
|
||
IScan.stopScan();</pre></section></main><script>(function () {
|
||
output(window.navigator.userAgent);
|
||
window.onerror = function (message, source, lineno, colno, err) {
|
||
error(err || message);
|
||
}
|
||
})();
|
||
|
||
function setStatus(status) {
|
||
document.getElementById("status").innerHTML = status || "unknown";
|
||
}
|
||
|
||
function hide() {
|
||
document.getElementById("result").style.display = "none";
|
||
document.getElementById("result").innerHTML = "";
|
||
document.getElementById("error").style.display = "none";
|
||
document.getElementById("error").innerHTML = "";
|
||
}
|
||
|
||
function format(data) {
|
||
if (typeof data === "string") {
|
||
return data;
|
||
}
|
||
try {
|
||
return JSON.stringify(data, null, 2);
|
||
} catch (e) {
|
||
return String(data);
|
||
}
|
||
}
|
||
|
||
function error(data) {
|
||
document.getElementById("result").style.display = "none";
|
||
document.getElementById("result").innerHTML = "";
|
||
document.getElementById("error").style.display = "block";
|
||
document.getElementById("error").innerHTML = format(data);
|
||
}
|
||
|
||
function result(data) {
|
||
document.getElementById("error").style.display = "none";
|
||
document.getElementById("error").innerHTML = "";
|
||
document.getElementById("result").style.display = "block";
|
||
document.getElementById("result").innerHTML = format(data);
|
||
}
|
||
|
||
function output(data) {
|
||
document.getElementById("output").innerHTML = format(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(options, callback);
|
||
}, { once: true })
|
||
}
|
||
}
|
||
|
||
function ready() {
|
||
hide();
|
||
setStatus("initializing");
|
||
var url = "https://vet.iqudoo.com/api?action=api.biz.wechat.JSSDKConfig";
|
||
initSDK({
|
||
webScanCanvasEnabled: true,
|
||
webScanCloseButtonStyle: "background: rgba(27, 99, 244, 0.88);",
|
||
scanBeepEnabled: true,
|
||
initWechatJssdk: { apiUrl: url }
|
||
}, function () {
|
||
setStatus(IScan.getStatus());
|
||
result("初始化成功");
|
||
IScan.setStatusListener(function () {
|
||
setStatus(IScan.getStatus());
|
||
});
|
||
IScan.onScanListener(function (res) {
|
||
result(res);
|
||
}, "scan", null, 100);
|
||
});
|
||
}
|
||
|
||
function stopScan() {
|
||
IScan.stopScan();
|
||
setStatus(IScan.getStatus());
|
||
}
|
||
|
||
function startScan() {
|
||
IScan.startScan();
|
||
setStatus(IScan.getStatus());
|
||
}
|
||
|
||
function scanImage() {
|
||
IScan.scanImage();
|
||
}
|
||
|
||
ready();</script><script src="index.js"></script></body></html> |