85 lines
1.7 KiB
TypeScript
85 lines
1.7 KiB
TypeScript
/**
|
||
* 扫码初始化选项
|
||
*/
|
||
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;
|
||
} |