Files
scan-code-jssdk/dist/index.d.ts
iqudoo 51738b1936 fix
2026-04-30 15:35:30 +08:00

182 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 扫码初始化选项
*/
interface ScanConfigOptions {
/**
* 网页扫码canvas样式
*/
webCanvasStyle?: string,
/**
* 网页扫码类型,默认支持二维码和条码
*/
webScanType?: ('qrCode' | 'barCode')[],
/**
* 网页扫码canvas是否启用默认启用
*/
webCanvasEnabled?: boolean,
/**
* 网页扫码成功提示音地址,默认使用内置提示音
*/
webScanBeepAudio?: string,
/**
* 网页扫码成功提示音是否启用,默认启用
*/
webScanBeepEnabled?: boolean,
/**
* BarcodeDetector polyfill 地址,默认使用 jsDelivr CDN
*/
webBarcodeDetectorPolyfillUrl?: string,
/**
* 微信JSSDK配置微信环境才会生效配置后会自动初始化微信JSSDK
*/
initWechatJssdk: {
/**
* 微信JSSDK配置API地址调用接口会带上当前页面url作为参数
*/
apiUrl: string,
/**
* 微信JSSDK配置参数不配置则自动获取
*/
sdkConfig?: {
/**
* 是否开启调试模式
*/
debug?: boolean,
/**
* 微信公众平台应用ID
*/
appId: string,
/**
* 时间戳
*/
timestamp: number,
/**
* 随机字符串
*/
nonceStr: string,
/**
* 签名
*/
signature: 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
}
/**
* 监听key
*/
interface ScanListenerInfo {
/**
* 监听key
*/
key?: string;
/**
* 监听匹配
*/
match?: string;
/**
* 监听级别
*/
level?: number;
/**
* 监听回调
*/
listener: ScanCallback;
/**
* 取消监听
*/
cancel: () => void;
}
/**
* 监听状态
*/
type ScanStatus = "scanning" | "closed";
/**
* 监听结果回调
*/
type ScanResultCallback = (result: ScanResult) => any;
/**
* 监听状态回调
*/
type ScanStatusCallback = (status: ScanStatus) => any;
/** IScan */
interface IScan {
/**
* 配置SDK
* @param options 配置选项
*/
config(options?: ScanConfigOptions): Promise<any>;
/**
* 监听扫码状态
* @param callback 监听回调
*/
setStatusListener(callback: ScanStatusCallback): void;
/**
* 添加监听扫码结果
* @param callback 监听回调
* @param key 监听key
* @param match 监听匹配
* @param level 监听级别
*/
onScanListener(callback: ScanResultCallback, key: string, match?: string, level?: number): ScanListenerInfo;
/**
* 取消监听扫码结果
* @param callback 监听回调或监听key
*/
offScanListener(callback: ScanResultCallback | string): void;
/**
* 获取扫码状态
* @returns ScanStatus
*/
getStatus(): ScanStatus;
/**
* 关闭扫码
*/
stopScan(): void;
/**
* 开启扫码
*/
startScan(): void;
/**
* 选择图片进行识别
*/
scanImage(): void;
/**
* 清除全部监听
*/
clear(): void;
}
/**
* IScan 实例
*/
declare var IScan: IScan;
/**
* 将 IScan 实例挂载到 Window 对象上
* 方便在全局使用
*/
declare interface Window {
IScan: IScan;
}