优化
This commit is contained in:
12
dist/index.d.ts
vendored
12
dist/index.d.ts
vendored
@@ -106,12 +106,12 @@ interface ScanListenerInfo {
|
||||
type ScanStatus = "scanning" | "closed";
|
||||
|
||||
/**
|
||||
* 监听回调
|
||||
* 监听结果回调
|
||||
*/
|
||||
type ScanCallback = (result: ScanResult) => any;
|
||||
type ScanResultCallback = (result: ScanResult) => any;
|
||||
|
||||
/**
|
||||
* 监听状态
|
||||
* 监听状态回调
|
||||
*/
|
||||
type ScanStatusCallback = (status: ScanStatus) => any;
|
||||
|
||||
@@ -128,18 +128,18 @@ interface IScan {
|
||||
*/
|
||||
setStatusListener(callback: ScanStatusCallback): void;
|
||||
/**
|
||||
* 监听扫码结果
|
||||
* 添加监听扫码结果
|
||||
* @param callback 监听回调
|
||||
* @param key 监听key
|
||||
* @param match 监听匹配
|
||||
* @param level 监听级别
|
||||
*/
|
||||
onScanListener(callback: ScanCallback, key: string, match?: string, level?: number): ScanListenerInfo;
|
||||
onScanListener(callback: ScanResultCallback, key: string, match?: string, level?: number): ScanListenerInfo;
|
||||
/**
|
||||
* 取消监听扫码结果
|
||||
* @param callback 监听回调,或监听key
|
||||
*/
|
||||
offScanListener(callback: ScanCallback | string): void;
|
||||
offScanListener(callback: ScanResultCallback | string): void;
|
||||
/**
|
||||
* 获取扫码状态
|
||||
* @returns ScanStatus
|
||||
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -235,27 +235,30 @@ export function clear() {
|
||||
}
|
||||
|
||||
export function onScanListener(listener, key, match, level) {
|
||||
if (!key || typeof key !== 'string') {
|
||||
return;
|
||||
}
|
||||
if (typeof listener !== 'function') {
|
||||
return;
|
||||
}
|
||||
let item = null;
|
||||
for (let i = 0; i < _scan_listener_list.length; i++) {
|
||||
const _i = _scan_listener_list[i];
|
||||
if (_i.listener === listener) {
|
||||
if (_i.key === key) {
|
||||
item = _i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (item) {
|
||||
item.key = key;
|
||||
item.level = level;
|
||||
item.match = match;
|
||||
item.listener = listener;
|
||||
} else {
|
||||
item = {
|
||||
key,
|
||||
match,
|
||||
level,
|
||||
listener,
|
||||
match: match || "",
|
||||
level: level || 0,
|
||||
listener: listener ,
|
||||
cancel: () => {
|
||||
const index = _scan_listener_list.indexOf(item);
|
||||
if (index !== -1) {
|
||||
|
||||
12
types/index.d.ts
vendored
12
types/index.d.ts
vendored
@@ -106,12 +106,12 @@ interface ScanListenerInfo {
|
||||
type ScanStatus = "scanning" | "closed";
|
||||
|
||||
/**
|
||||
* 监听回调
|
||||
* 监听结果回调
|
||||
*/
|
||||
type ScanCallback = (result: ScanResult) => any;
|
||||
type ScanResultCallback = (result: ScanResult) => any;
|
||||
|
||||
/**
|
||||
* 监听状态
|
||||
* 监听状态回调
|
||||
*/
|
||||
type ScanStatusCallback = (status: ScanStatus) => any;
|
||||
|
||||
@@ -128,18 +128,18 @@ interface IScan {
|
||||
*/
|
||||
setStatusListener(callback: ScanStatusCallback): void;
|
||||
/**
|
||||
* 监听扫码结果
|
||||
* 添加监听扫码结果
|
||||
* @param callback 监听回调
|
||||
* @param key 监听key
|
||||
* @param match 监听匹配
|
||||
* @param level 监听级别
|
||||
*/
|
||||
onScanListener(callback: ScanCallback, key: string, match?: string, level?: number): ScanListenerInfo;
|
||||
onScanListener(callback: ScanResultCallback, key: string, match?: string, level?: number): ScanListenerInfo;
|
||||
/**
|
||||
* 取消监听扫码结果
|
||||
* @param callback 监听回调,或监听key
|
||||
*/
|
||||
offScanListener(callback: ScanCallback | string): void;
|
||||
offScanListener(callback: ScanResultCallback | string): void;
|
||||
/**
|
||||
* 获取扫码状态
|
||||
* @returns ScanStatus
|
||||
|
||||
Reference in New Issue
Block a user