feat: 手机连续扫与出仓汇总表改用t-table并升至1.1.24
This commit is contained in:
+84
-2
@@ -72,20 +72,63 @@ export default {
|
||||
return configs.length ? configs[0] : null;
|
||||
},
|
||||
|
||||
/** 停止手机连续扫码(含 Ba-Scanner) */
|
||||
stopPhoneScanContinuous() {
|
||||
this._phoneScanContinuousActive = false;
|
||||
// #ifdef APP-PLUS
|
||||
try {
|
||||
const scanner = uni.requireNativePlugin('Ba-Scanner');
|
||||
if (scanner && typeof scanner.onClose === 'function') {
|
||||
scanner.onClose();
|
||||
}
|
||||
} catch (e) {
|
||||
// 未购买/未打包原生插件时忽略
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
|
||||
/**
|
||||
* 打开手机扫码
|
||||
* @param {{ continuous?: boolean, callback?: Function, fail?: Function, scanType?: string[], hintText?: string, scanTimeSpace?: number }} options
|
||||
* continuous=true 时优先用 Ba-Scanner 连续扫;无插件则扫完自动再开相机
|
||||
*/
|
||||
openPhoneScan(options = {}) {
|
||||
const callback = options.callback || this._scanCallback;
|
||||
const continuous = !!options.continuous;
|
||||
this._phoneScanContinuousActive = continuous;
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
if (continuous && this.openBaScannerContinuous(options, callback)) {
|
||||
return;
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS || MP-WEIXIN
|
||||
uni.scanCode({
|
||||
scanType: options.scanType || ['qrCode', 'barCode'],
|
||||
success: (res) => {
|
||||
this.handleScanResult(res.result, callback);
|
||||
const result = this.handleScanResult(res.result, callback);
|
||||
if (!continuous || !this._phoneScanContinuousActive) return;
|
||||
Promise.resolve(result)
|
||||
.catch(() => null)
|
||||
.then(() => {
|
||||
if (!this._phoneScanContinuousActive || !this.isPageActive) return;
|
||||
setTimeout(() => {
|
||||
if (!this._phoneScanContinuousActive || !this.isPageActive) return;
|
||||
this.openPhoneScan(options);
|
||||
}, Number(options.scanTimeSpace) > 0 ? Number(options.scanTimeSpace) : 400);
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('手机扫码失败:', err);
|
||||
this._phoneScanContinuousActive = false;
|
||||
if (options.fail) {
|
||||
options.fail(err);
|
||||
return;
|
||||
}
|
||||
// 用户取消不打扰
|
||||
const msg = (err && (err.errMsg || err.message)) || '';
|
||||
if (/cancel|取消/i.test(msg)) return;
|
||||
uni.showToast({
|
||||
title: '扫码失败',
|
||||
icon: 'none',
|
||||
@@ -103,6 +146,41 @@ export default {
|
||||
// #endif
|
||||
},
|
||||
|
||||
/**
|
||||
* Ba-Scanner 连续扫码(插件市场 id=9669)
|
||||
* @returns {boolean} 是否已成功唤起原生连续扫
|
||||
*/
|
||||
openBaScannerContinuous(options = {}, callback) {
|
||||
// #ifdef APP-PLUS
|
||||
try {
|
||||
const scanner = uni.requireNativePlugin('Ba-Scanner');
|
||||
if (!scanner || typeof scanner.onScan !== 'function') return false;
|
||||
scanner.onScan(
|
||||
{
|
||||
isContinuous: true,
|
||||
scanTimeSpace: Number(options.scanTimeSpace) > 0 ? Number(options.scanTimeSpace) : 1500,
|
||||
isShowVibrate: options.isShowVibrate !== false,
|
||||
isShowBeep: !!options.isShowBeep,
|
||||
isShowToast: false,
|
||||
isShowPhotoAlbum: options.isShowPhotoAlbum !== false,
|
||||
hintText: options.hintText || '扫二维码/条形码,可连续扫',
|
||||
barcodeFormats: options.barcodeFormats || ['QR Code', 'Code 128', 'Code 39', 'EAN-13', 'EAN-8'],
|
||||
},
|
||||
(ret) => {
|
||||
if (!ret || !ret.result) return;
|
||||
if (!this._phoneScanContinuousActive) return;
|
||||
this.handleScanResult(ret.result, callback);
|
||||
},
|
||||
);
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.warn('Ba-Scanner 不可用,回退 uni.scanCode', e);
|
||||
return false;
|
||||
}
|
||||
// #endif
|
||||
return false;
|
||||
},
|
||||
|
||||
triggerScan() {
|
||||
if (this.usePhoneScanFallback) {
|
||||
this.openPhoneScan();
|
||||
@@ -261,11 +339,12 @@ export default {
|
||||
console.log("扫码结果:", cleanCode);
|
||||
|
||||
if (scanCallback) {
|
||||
scanCallback(cleanCode);
|
||||
return scanCallback(cleanCode);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("处理扫码结果时出错:", error);
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
unregisterScanBroadcast() {
|
||||
@@ -317,10 +396,13 @@ export default {
|
||||
|
||||
onHide() {
|
||||
this.isPageActive = false;
|
||||
// 不在 onHide 里关 Ba-Scanner:打开原生扫码页也会触发 hide,误关会打断连续扫
|
||||
// 无插件回退模式靠 isPageActive 控制是否自动再开相机
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
this.isPageActive = false;
|
||||
this.stopPhoneScanContinuous();
|
||||
this.unregisterScanBroadcast();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user