feat(pda): 添加坯布出仓单功能和扫码设置界面

- 新增坯布出仓单相关API接口,包括列表、详情、新增、审核等功能
- 添加营销体系、往来单位、字典明细等基础数据接口
- 在用户中心添加扫描设置入口,支持PDA扫码枪配置
- 创建扫描设置页面,支持选择PDA品牌并配置广播动作和数据标签
- 重构扫码混入逻辑,支持远程配置和本地配置合并
- 添加扫码配置存储和读取功能,支持配置持久化
- 优化扫码广播注册流程,优先使用用户配置的扫码枪设置
This commit is contained in:
2026-06-17 16:32:24 +08:00
parent ebfa5bf2a0
commit cff4debea4
6 changed files with 403 additions and 71 deletions
+73 -71
View File
@@ -1,20 +1,27 @@
// common/scanMixin.js
// 多厂商PDA扫码器兼容方案 - 策略模式 + 配置表驱动
import {
getScanConfig,
hasShownNoConfigHint,
markNoConfigHintShown,
normalizeConfig,
} from '@/common/scanConfig.js';
export default {
data() {
return {
scanReceivers: [], // 支持多个接收器
scanReceivers: [],
isPageActive: false,
registeredBrands: [] // 已注册的品牌
registeredBrands: [],
remoteScannerConfigs: [],
}
},
methods: {
// 扫码器配置表 - 方便扩展新厂商
getScannerConfigs() {
return [
{
brand: 'newland', // 东集
brand: 'newland',
name: '东集',
action: 'com.android.server.scannerservice.broadcast',
dataKey: 'scannerdata',
@@ -27,96 +34,100 @@ export default {
}
},
{
brand: 'sunmi', // 商米
brand: 'sunmi',
name: '商米',
action: 'com.sunmi.scanner.ACTION_DATA_CODE_RECEIVED',
dataKey: 'data',
needSetup: false
},
// {
// brand: 'honeywell', // 霍尼韦尔
// name: '霍尼韦尔',
// action: 'com.honeywell.decode.intent.action.EDIT_DATA',
// dataKey: 'data',
// needSetup: false
// },
// {
// brand: 'zebra', // 斑马
// name: '斑马',
// action: 'com.symbol.datawedge.api.RESULT_ACTION',
// dataKey: 'com.symbol.datawedge.data_string',
// needSetup: false
// },
// {
// brand: 'idata', // 盈达聚力
// name: '盈达聚力',
// action: 'android.intent.action.SCANRESULT',
// dataKey: 'value',
// needSetup: false
// },
// {
// brand: 'urovo', // 优博讯
// name: '优博讯',
// action: 'android.intent.ACTION_DECODE_DATA',
// dataKey: 'barcode_string',
// needSetup: false
// }
];
},
// 注册所有扫码广播(推荐方式:同时注册所有厂商)
getAllScannerConfigs() {
const builtinConfigs = this.getScannerConfigs();
if (!this.remoteScannerConfigs.length) {
return builtinConfigs;
}
const configMap = new Map();
builtinConfigs.forEach((item) => configMap.set(item.brand, item));
this.remoteScannerConfigs.forEach((item) => configMap.set(item.brand, item));
return Array.from(configMap.values());
},
getActiveScanConfig() {
return getScanConfig();
},
getDefaultScanConfig() {
const configs = this.getAllScannerConfigs();
return configs.length ? configs[0] : null;
},
registerScanBroadcast(scanCallback) {
// #ifdef APP-PLUS
const configs = this.getScannerConfigs();
configs.forEach(config => {
try {
this.registerSingleBroadcast(config, scanCallback);
this.registeredBrands.push(config.brand);
console.log(`${config.name}扫码广播注册成功`);
} catch (error) {
console.log(`${config.name}扫码广播注册失败:`, error);
}
});
if (this.registeredBrands.length > 0) {
console.log('扫码广播注册完成,已注册厂商:', this.registeredBrands.join(', '));
return true;
const activeConfig = this.getActiveScanConfig();
if (activeConfig) {
return this.registerScanBroadcastByConfig(activeConfig, scanCallback);
}
console.error('所有扫码广播注册均失败');
return false;
if (!hasShownNoConfigHint()) {
markNoConfigHintShown();
uni.showToast({
title: '请先在「我的-扫描设置」配置扫码枪',
icon: 'none',
duration: 2500,
});
}
const defaultConfig = this.getDefaultScanConfig();
if (!defaultConfig) {
console.error('未找到默认可用的扫码枪配置');
return false;
}
return this.registerScanBroadcastByConfig(defaultConfig, scanCallback);
// #endif
},
// 注册指定厂商的扫码广播
registerScanBroadcastByBrand(brand, scanCallback) {
// #ifdef APP-PLUS
const configs = this.getScannerConfigs();
const configs = this.getAllScannerConfigs();
const config = configs.find(c => c.brand === brand);
if (!config) {
console.error(`未找到厂商配置: ${brand}`);
return false;
}
return this.registerScanBroadcastByConfig(config, scanCallback);
// #endif
},
registerScanBroadcastByConfig(config, scanCallback) {
// #ifdef APP-PLUS
const normalizedConfig = normalizeConfig(config);
if (!normalizedConfig) {
console.error('扫码枪配置无效');
return false;
}
try {
this.registerSingleBroadcast(config, scanCallback);
this.registeredBrands.push(config.brand);
console.log(`${config.name}扫码广播注册成功`);
this.registerSingleBroadcast(normalizedConfig, scanCallback);
this.registeredBrands.push(normalizedConfig.brand);
console.log(`${normalizedConfig.name}扫码广播注册成功`);
return true;
} catch (error) {
console.error(`${config.name}扫码广播注册失败:`, error);
console.error(`${normalizedConfig.name}扫码广播注册失败:`, error);
return false;
}
// #endif
},
// 单个广播注册的核心方法
registerSingleBroadcast(config, scanCallback) {
const main = plus.android.runtimeMainActivity();
// 如果需要预配置(如东集)
if (config.needSetup && config.setupAction) {
try {
const Intent = plus.android.importClass('android.content.Intent');
@@ -133,7 +144,6 @@ export default {
}
}
// 注册广播接收器
const IntentFilter = plus.android.importClass('android.content.IntentFilter');
const filter = new IntentFilter();
filter.addAction(config.action);
@@ -165,17 +175,14 @@ export default {
main.registerReceiver(receiver, filter);
// 保存接收器引用,用于后续注销
this.scanReceivers.push({
brand: config.brand,
receiver: receiver
});
},
// 处理扫码结果的统一方法
handleScanResult(scanResult, scanCallback) {
try {
// 数据清理:去除空格、换行符等
let cleanCode = scanResult.replace(/\s+/g, '').replace(/[\r\n]/g, '');
console.log("扫码结果:", cleanCode);
@@ -188,7 +195,6 @@ export default {
}
},
// 取消所有扫码广播监听
unregisterScanBroadcast() {
// #ifdef APP-PLUS
if (this.scanReceivers.length === 0) return;
@@ -214,7 +220,6 @@ export default {
// #endif
},
// 通用的商品扫描处理方法
handleGoodsScan(scanCode, successCallback, errorCallback) {
const trimmedCode = scanCode ? scanCode.toString().trim() : "";
@@ -224,17 +229,14 @@ export default {
return;
}
// 根据业务类型处理不同的扫码逻辑
if (this.processScanCode) {
this.processScanCode(trimmedCode, successCallback, errorCallback);
} else {
// 默认处理方式
successCallback && successCallback(trimmedCode);
}
}
},
// 页面激活状态管理
onShow() {
this.isPageActive = true;
console.log('页面显示,设置 isPageActive 为 true');