init commit
This commit is contained in:
85
dist/index.d.ts
vendored
Normal file
85
dist/index.d.ts
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 扫码初始化选项
|
||||
*/
|
||||
interface ScanConfigOptions {
|
||||
/**
|
||||
* 网页扫码canvas样式
|
||||
*/
|
||||
webCanvasStyle?: string,
|
||||
/**
|
||||
* 微信JSSDK配置,配置后会自动初始化微信JSSDK
|
||||
*/
|
||||
initWechatJssdk: {
|
||||
/**
|
||||
* 微信JSSDK配置API地址,调用接口会带上当前页面url作为参数
|
||||
*/
|
||||
apiUrl: string,
|
||||
/**
|
||||
* 微信JSSDK配置SDK地址,默认为https://res.wx.qq.com/open/js/jweixin-1.6.0.js
|
||||
*/
|
||||
sdkUrl?: string,
|
||||
/**
|
||||
* 微信JSSDK配置JS-API列表,默认追加["scanQRCode"]
|
||||
*/
|
||||
jsApiList?: string[]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码选项
|
||||
*/
|
||||
interface ScanResult {
|
||||
result: string,
|
||||
key: string
|
||||
}
|
||||
|
||||
/** IScan */
|
||||
interface IScan {
|
||||
/**
|
||||
* 配置SDK
|
||||
* @param options 配置选项
|
||||
*/
|
||||
config(options?: ScanConfigOptions): Promise<any>;
|
||||
/**
|
||||
* 监听扫码状态
|
||||
* @param callback 监听回调
|
||||
*/
|
||||
setStatusListener(callback: (status: "scanning" | "closed") => any): void;
|
||||
/**
|
||||
* 监听扫码结果
|
||||
* @param callback 监听回调
|
||||
* @param key 监听key
|
||||
* @param match 监听匹配
|
||||
* @param level 监听级别
|
||||
*/
|
||||
onScanListener(callback: (result: ScanResult) => any, key: string, match: string, level: number): void;
|
||||
/**
|
||||
* 取消监听扫码结果
|
||||
* @param callback 监听回调
|
||||
*/
|
||||
offScanListener(callback: (result: ScanResult) => any): void;
|
||||
/**
|
||||
* 获取扫码状态
|
||||
* @returns "scanning" | "closed"
|
||||
*/
|
||||
getStatus(): "scanning" | "closed";
|
||||
/**
|
||||
* 关闭扫码
|
||||
*/
|
||||
stopScan(): void;
|
||||
/**
|
||||
* 开启扫码
|
||||
*/
|
||||
startScan(): void;
|
||||
/**
|
||||
* 清除全部监听
|
||||
*/
|
||||
clear(): void;
|
||||
|
||||
}
|
||||
|
||||
declare var IScan: IScan;
|
||||
|
||||
declare interface Window {
|
||||
IScan: IScan;
|
||||
}
|
||||
125
dist/index.html
vendored
Normal file
125
dist/index.html
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no"/><title>Demo</title><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><script src="index.js"></script></body></html>
|
||||
1
dist/index.js
vendored
Normal file
1
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user