优化
This commit is contained in:
File diff suppressed because one or more lines are too long
62
dist/index.d.ts
vendored
62
dist/index.d.ts
vendored
@@ -7,7 +7,7 @@ interface ScanConfigOptions {
|
||||
*/
|
||||
webCanvasStyle?: string,
|
||||
/**
|
||||
* 微信JSSDK配置,配置后会自动初始化微信JSSDK
|
||||
* 微信JSSDK配置,微信环境才会生效,配置后会自动初始化微信JSSDK
|
||||
*/
|
||||
initWechatJssdk: {
|
||||
/**
|
||||
@@ -33,6 +33,47 @@ interface ScanResult {
|
||||
key: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听key
|
||||
*/
|
||||
interface ScanListenerInfo {
|
||||
/**
|
||||
* 监听key
|
||||
*/
|
||||
key?: string;
|
||||
/**
|
||||
* 监听匹配
|
||||
*/
|
||||
match?: string;
|
||||
/**
|
||||
* 监听级别
|
||||
*/
|
||||
level?: number;
|
||||
/**
|
||||
* 监听回调
|
||||
*/
|
||||
listener: ScanCallback;
|
||||
/**
|
||||
* 取消监听
|
||||
*/
|
||||
cancel: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听状态
|
||||
*/
|
||||
type ScanStatus = "scanning" | "closed";
|
||||
|
||||
/**
|
||||
* 监听回调
|
||||
*/
|
||||
type ScanCallback = (result: ScanResult) => any;
|
||||
|
||||
/**
|
||||
* 监听状态
|
||||
*/
|
||||
type ScanStatusCallback = (status: ScanStatus) => any;
|
||||
|
||||
/** IScan */
|
||||
interface IScan {
|
||||
/**
|
||||
@@ -44,7 +85,7 @@ interface IScan {
|
||||
* 监听扫码状态
|
||||
* @param callback 监听回调
|
||||
*/
|
||||
setStatusListener(callback: (status: "scanning" | "closed") => any): void;
|
||||
setStatusListener(callback: ScanStatusCallback): void;
|
||||
/**
|
||||
* 监听扫码结果
|
||||
* @param callback 监听回调
|
||||
@@ -52,17 +93,17 @@ interface IScan {
|
||||
* @param match 监听匹配
|
||||
* @param level 监听级别
|
||||
*/
|
||||
onScanListener(callback: (result: ScanResult) => any, key: string, match: string, level: number): void;
|
||||
onScanListener(callback: ScanCallback, key: string, match?: string, level?: number): ScanListenerInfo;
|
||||
/**
|
||||
* 取消监听扫码结果
|
||||
* @param callback 监听回调
|
||||
* @param callback 监听回调,或监听key
|
||||
*/
|
||||
offScanListener(callback: (result: ScanResult) => any): void;
|
||||
offScanListener(callback: ScanCallback | string): void;
|
||||
/**
|
||||
* 获取扫码状态
|
||||
* @returns "scanning" | "closed"
|
||||
* @returns ScanStatus
|
||||
*/
|
||||
getStatus(): "scanning" | "closed";
|
||||
getStatus(): ScanStatus;
|
||||
/**
|
||||
* 关闭扫码
|
||||
*/
|
||||
@@ -78,8 +119,15 @@ interface IScan {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* IScan 实例
|
||||
*/
|
||||
declare var IScan: IScan;
|
||||
|
||||
/**
|
||||
* 将 IScan 实例挂载到 Window 对象上
|
||||
* 方便在全局使用
|
||||
*/
|
||||
declare interface Window {
|
||||
IScan: IScan;
|
||||
}
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -278,7 +278,12 @@ export function onScanListener(listener, key, match, level) {
|
||||
export function offScanListener(listener) {
|
||||
for (let i = 0; i < _scan_listener_list.length; i++) {
|
||||
const _i = _scan_listener_list[i];
|
||||
if (_i.listener === listener) {
|
||||
if (typeof listener === 'string') {
|
||||
if (_i.key === listener) {
|
||||
_i.cancel();
|
||||
break;
|
||||
}
|
||||
} else if (_i.listener === listener) {
|
||||
_i.cancel();
|
||||
break;
|
||||
}
|
||||
|
||||
62
types/index.d.ts
vendored
62
types/index.d.ts
vendored
@@ -7,7 +7,7 @@ interface ScanConfigOptions {
|
||||
*/
|
||||
webCanvasStyle?: string,
|
||||
/**
|
||||
* 微信JSSDK配置,配置后会自动初始化微信JSSDK
|
||||
* 微信JSSDK配置,微信环境才会生效,配置后会自动初始化微信JSSDK
|
||||
*/
|
||||
initWechatJssdk: {
|
||||
/**
|
||||
@@ -33,6 +33,47 @@ interface ScanResult {
|
||||
key: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听key
|
||||
*/
|
||||
interface ScanListenerInfo {
|
||||
/**
|
||||
* 监听key
|
||||
*/
|
||||
key?: string;
|
||||
/**
|
||||
* 监听匹配
|
||||
*/
|
||||
match?: string;
|
||||
/**
|
||||
* 监听级别
|
||||
*/
|
||||
level?: number;
|
||||
/**
|
||||
* 监听回调
|
||||
*/
|
||||
listener: ScanCallback;
|
||||
/**
|
||||
* 取消监听
|
||||
*/
|
||||
cancel: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听状态
|
||||
*/
|
||||
type ScanStatus = "scanning" | "closed";
|
||||
|
||||
/**
|
||||
* 监听回调
|
||||
*/
|
||||
type ScanCallback = (result: ScanResult) => any;
|
||||
|
||||
/**
|
||||
* 监听状态
|
||||
*/
|
||||
type ScanStatusCallback = (status: ScanStatus) => any;
|
||||
|
||||
/** IScan */
|
||||
interface IScan {
|
||||
/**
|
||||
@@ -44,7 +85,7 @@ interface IScan {
|
||||
* 监听扫码状态
|
||||
* @param callback 监听回调
|
||||
*/
|
||||
setStatusListener(callback: (status: "scanning" | "closed") => any): void;
|
||||
setStatusListener(callback: ScanStatusCallback): void;
|
||||
/**
|
||||
* 监听扫码结果
|
||||
* @param callback 监听回调
|
||||
@@ -52,17 +93,17 @@ interface IScan {
|
||||
* @param match 监听匹配
|
||||
* @param level 监听级别
|
||||
*/
|
||||
onScanListener(callback: (result: ScanResult) => any, key: string, match: string, level: number): void;
|
||||
onScanListener(callback: ScanCallback, key: string, match?: string, level?: number): ScanListenerInfo;
|
||||
/**
|
||||
* 取消监听扫码结果
|
||||
* @param callback 监听回调
|
||||
* @param callback 监听回调,或监听key
|
||||
*/
|
||||
offScanListener(callback: (result: ScanResult) => any): void;
|
||||
offScanListener(callback: ScanCallback | string): void;
|
||||
/**
|
||||
* 获取扫码状态
|
||||
* @returns "scanning" | "closed"
|
||||
* @returns ScanStatus
|
||||
*/
|
||||
getStatus(): "scanning" | "closed";
|
||||
getStatus(): ScanStatus;
|
||||
/**
|
||||
* 关闭扫码
|
||||
*/
|
||||
@@ -78,8 +119,15 @@ interface IScan {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* IScan 实例
|
||||
*/
|
||||
declare var IScan: IScan;
|
||||
|
||||
/**
|
||||
* 将 IScan 实例挂载到 Window 对象上
|
||||
* 方便在全局使用
|
||||
*/
|
||||
declare interface Window {
|
||||
IScan: IScan;
|
||||
}
|
||||
Reference in New Issue
Block a user