优化
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,
|
webCanvasStyle?: string,
|
||||||
/**
|
/**
|
||||||
* 微信JSSDK配置,配置后会自动初始化微信JSSDK
|
* 微信JSSDK配置,微信环境才会生效,配置后会自动初始化微信JSSDK
|
||||||
*/
|
*/
|
||||||
initWechatJssdk: {
|
initWechatJssdk: {
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +33,47 @@ interface ScanResult {
|
|||||||
key: string
|
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 */
|
/** IScan */
|
||||||
interface IScan {
|
interface IScan {
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +85,7 @@ interface IScan {
|
|||||||
* 监听扫码状态
|
* 监听扫码状态
|
||||||
* @param callback 监听回调
|
* @param callback 监听回调
|
||||||
*/
|
*/
|
||||||
setStatusListener(callback: (status: "scanning" | "closed") => any): void;
|
setStatusListener(callback: ScanStatusCallback): void;
|
||||||
/**
|
/**
|
||||||
* 监听扫码结果
|
* 监听扫码结果
|
||||||
* @param callback 监听回调
|
* @param callback 监听回调
|
||||||
@@ -52,17 +93,17 @@ interface IScan {
|
|||||||
* @param match 监听匹配
|
* @param match 监听匹配
|
||||||
* @param level 监听级别
|
* @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;
|
declare var IScan: IScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 IScan 实例挂载到 Window 对象上
|
||||||
|
* 方便在全局使用
|
||||||
|
*/
|
||||||
declare interface Window {
|
declare interface Window {
|
||||||
IScan: IScan;
|
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) {
|
export function offScanListener(listener) {
|
||||||
for (let i = 0; i < _scan_listener_list.length; i++) {
|
for (let i = 0; i < _scan_listener_list.length; i++) {
|
||||||
const _i = _scan_listener_list[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();
|
_i.cancel();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
62
types/index.d.ts
vendored
62
types/index.d.ts
vendored
@@ -7,7 +7,7 @@ interface ScanConfigOptions {
|
|||||||
*/
|
*/
|
||||||
webCanvasStyle?: string,
|
webCanvasStyle?: string,
|
||||||
/**
|
/**
|
||||||
* 微信JSSDK配置,配置后会自动初始化微信JSSDK
|
* 微信JSSDK配置,微信环境才会生效,配置后会自动初始化微信JSSDK
|
||||||
*/
|
*/
|
||||||
initWechatJssdk: {
|
initWechatJssdk: {
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +33,47 @@ interface ScanResult {
|
|||||||
key: string
|
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 */
|
/** IScan */
|
||||||
interface IScan {
|
interface IScan {
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +85,7 @@ interface IScan {
|
|||||||
* 监听扫码状态
|
* 监听扫码状态
|
||||||
* @param callback 监听回调
|
* @param callback 监听回调
|
||||||
*/
|
*/
|
||||||
setStatusListener(callback: (status: "scanning" | "closed") => any): void;
|
setStatusListener(callback: ScanStatusCallback): void;
|
||||||
/**
|
/**
|
||||||
* 监听扫码结果
|
* 监听扫码结果
|
||||||
* @param callback 监听回调
|
* @param callback 监听回调
|
||||||
@@ -52,17 +93,17 @@ interface IScan {
|
|||||||
* @param match 监听匹配
|
* @param match 监听匹配
|
||||||
* @param level 监听级别
|
* @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;
|
declare var IScan: IScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 IScan 实例挂载到 Window 对象上
|
||||||
|
* 方便在全局使用
|
||||||
|
*/
|
||||||
declare interface Window {
|
declare interface Window {
|
||||||
IScan: IScan;
|
IScan: IScan;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user