优化iframe内使用的优化
This commit is contained in:
@@ -5,6 +5,7 @@ import { startScanner, stopScanner } from "../scanner";
|
||||
import { getConfig } from "../config";
|
||||
import { toAny } from "../../utils/toany";
|
||||
import { printDebug } from "../../utils/logger";
|
||||
import { forwardEmbedScanResultIfNeeded } from "../embedScanBridge";
|
||||
|
||||
let _scan_status = "ready";
|
||||
let _scan_status_listener = null;
|
||||
@@ -93,6 +94,7 @@ function __match(result, match) {
|
||||
|
||||
function __result(result) {
|
||||
result = parseBarcodeString(result);
|
||||
forwardEmbedScanResultIfNeeded(result);
|
||||
let matched = false;
|
||||
for (let i = 0; i < _scan_listener_list.length; i++) {
|
||||
const item = _scan_listener_list[i];
|
||||
@@ -157,18 +159,38 @@ function __stopCurrentScan() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 由嵌入子页转发过来的扫码枪按键结果,与 startScanner 走同一匹配与回调链路
|
||||
*(仅在父页的 installEmbedHost 处理 forwardScanGun 时调用)。
|
||||
* 父页通过 postMessage 将识别结果投递到嵌入 iframe 时调用(与本地扫码枪/监听同一链路)。
|
||||
* @returns {boolean} 是否有监听消费了该结果
|
||||
*/
|
||||
export function dispatchHardwareScanResult(raw) {
|
||||
export function dispatchEmbedScanResult(raw) {
|
||||
const result =
|
||||
typeof raw === "string" ? parseBarcodeString(raw) : raw;
|
||||
__scannerResult(result);
|
||||
return __scannerResult(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 嵌入 iframe 已消费扫码结果时通知父页结束当前识别(关闭摄像头/UI 等)。
|
||||
*/
|
||||
export function acknowledgeEmbedScanConsumed(raw) {
|
||||
const result =
|
||||
typeof raw === "string" ? parseBarcodeString(raw) : raw;
|
||||
if (!isScanning()) {
|
||||
return;
|
||||
}
|
||||
const resolve = __finishScan();
|
||||
_scan_closing = true;
|
||||
_scan_next_start_time = Date.now() + getScanRestartDelay();
|
||||
__stopCurrentScan().then(() => {
|
||||
setTimeout(() => {
|
||||
_scan_closing = false;
|
||||
}, 0);
|
||||
});
|
||||
resolve && resolve({ result });
|
||||
}
|
||||
|
||||
function __scannerResult(result) {
|
||||
if (!__hasMatchedListener(result)) {
|
||||
return;
|
||||
return __result(result);
|
||||
}
|
||||
if (isScanning()) {
|
||||
const resolve = __finishScan();
|
||||
@@ -178,13 +200,13 @@ function __scannerResult(result) {
|
||||
_scan_closing = false;
|
||||
}, 0);
|
||||
});
|
||||
__result(result);
|
||||
const matched = __result(result);
|
||||
resolve && resolve({
|
||||
result
|
||||
});
|
||||
return;
|
||||
return matched;
|
||||
}
|
||||
__result(result);
|
||||
return __result(result);
|
||||
}
|
||||
|
||||
function __startBridgeScan() {
|
||||
|
||||
Reference in New Issue
Block a user