优化
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 ScanStatus = "scanning" | "closed";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听回调
|
* 监听结果回调
|
||||||
*/
|
*/
|
||||||
type ScanCallback = (result: ScanResult) => any;
|
type ScanResultCallback = (result: ScanResult) => any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听状态
|
* 监听状态回调
|
||||||
*/
|
*/
|
||||||
type ScanStatusCallback = (status: ScanStatus) => any;
|
type ScanStatusCallback = (status: ScanStatus) => any;
|
||||||
|
|
||||||
@@ -128,18 +128,18 @@ interface IScan {
|
|||||||
*/
|
*/
|
||||||
setStatusListener(callback: ScanStatusCallback): void;
|
setStatusListener(callback: ScanStatusCallback): void;
|
||||||
/**
|
/**
|
||||||
* 监听扫码结果
|
* 添加监听扫码结果
|
||||||
* @param callback 监听回调
|
* @param callback 监听回调
|
||||||
* @param key 监听key
|
* @param key 监听key
|
||||||
* @param match 监听匹配
|
* @param match 监听匹配
|
||||||
* @param level 监听级别
|
* @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
|
* @param callback 监听回调,或监听key
|
||||||
*/
|
*/
|
||||||
offScanListener(callback: ScanCallback | string): void;
|
offScanListener(callback: ScanResultCallback | string): void;
|
||||||
/**
|
/**
|
||||||
* 获取扫码状态
|
* 获取扫码状态
|
||||||
* @returns ScanStatus
|
* @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) {
|
export function onScanListener(listener, key, match, level) {
|
||||||
|
if (!key || typeof key !== 'string') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (typeof listener !== 'function') {
|
if (typeof listener !== 'function') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let item = null;
|
let item = null;
|
||||||
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 (_i.key === key) {
|
||||||
item = _i;
|
item = _i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item) {
|
if (item) {
|
||||||
item.key = key;
|
|
||||||
item.level = level;
|
item.level = level;
|
||||||
item.match = match;
|
item.match = match;
|
||||||
|
item.listener = listener;
|
||||||
} else {
|
} else {
|
||||||
item = {
|
item = {
|
||||||
key,
|
key,
|
||||||
match,
|
match: match || "",
|
||||||
level,
|
level: level || 0,
|
||||||
listener,
|
listener: listener ,
|
||||||
cancel: () => {
|
cancel: () => {
|
||||||
const index = _scan_listener_list.indexOf(item);
|
const index = _scan_listener_list.indexOf(item);
|
||||||
if (index !== -1) {
|
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 ScanStatus = "scanning" | "closed";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听回调
|
* 监听结果回调
|
||||||
*/
|
*/
|
||||||
type ScanCallback = (result: ScanResult) => any;
|
type ScanResultCallback = (result: ScanResult) => any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听状态
|
* 监听状态回调
|
||||||
*/
|
*/
|
||||||
type ScanStatusCallback = (status: ScanStatus) => any;
|
type ScanStatusCallback = (status: ScanStatus) => any;
|
||||||
|
|
||||||
@@ -128,18 +128,18 @@ interface IScan {
|
|||||||
*/
|
*/
|
||||||
setStatusListener(callback: ScanStatusCallback): void;
|
setStatusListener(callback: ScanStatusCallback): void;
|
||||||
/**
|
/**
|
||||||
* 监听扫码结果
|
* 添加监听扫码结果
|
||||||
* @param callback 监听回调
|
* @param callback 监听回调
|
||||||
* @param key 监听key
|
* @param key 监听key
|
||||||
* @param match 监听匹配
|
* @param match 监听匹配
|
||||||
* @param level 监听级别
|
* @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
|
* @param callback 监听回调,或监听key
|
||||||
*/
|
*/
|
||||||
offScanListener(callback: ScanCallback | string): void;
|
offScanListener(callback: ScanResultCallback | string): void;
|
||||||
/**
|
/**
|
||||||
* 获取扫码状态
|
* 获取扫码状态
|
||||||
* @returns ScanStatus
|
* @returns ScanStatus
|
||||||
|
|||||||
Reference in New Issue
Block a user