feat: 优化手动进仓流程并修复N5S扫码识别升至1.1.26
This commit is contained in:
@@ -35,7 +35,11 @@ export async function ensureScanConfigAfterLogin(api) {
|
||||
if (result.skipped) {
|
||||
console.log('本地已有扫码设置,跳过自动匹配', result.config && result.config.name);
|
||||
} else if (result.saved) {
|
||||
console.log('已自动写入扫码设置', result.config && result.config.name);
|
||||
if (result.reason === 'rematch_n5s_from_seuic') {
|
||||
console.log('N5S 误识别为东集,已纠正为', result.config && result.config.name);
|
||||
} else {
|
||||
console.log('已自动写入扫码设置', result.config && result.config.name);
|
||||
}
|
||||
} else {
|
||||
console.log('自动匹配扫码设置未写入', result.reason);
|
||||
}
|
||||
|
||||
+105
-9
@@ -50,6 +50,14 @@ export const BUILTIN_SCANNER_CONFIGS = [
|
||||
dataKey: 'SCAN_BARCODE1',
|
||||
needSetup: false,
|
||||
},
|
||||
{
|
||||
// N5S 部分固件走智联天地兼容广播,而不是 nlscan.action
|
||||
brand: 'nlscan_compat',
|
||||
name: '新大陆(兼容广播)',
|
||||
action: 'android.intent.action.RECEIVE_SCANDATA_BROADCAST',
|
||||
dataKey: 'android.intent.extra.SCAN_BROADCAST_DATA',
|
||||
needSetup: false,
|
||||
},
|
||||
{ ...PHONE_SCAN_CONFIG },
|
||||
];
|
||||
|
||||
@@ -62,10 +70,19 @@ const DETECT_RULES = [
|
||||
packages: ['com.sunmi.scanner', 'woyou.aidlservice.jiuiv5'],
|
||||
},
|
||||
{
|
||||
matchNames: ['新大陆'],
|
||||
matchActions: ['nlscan.action.SCANNER_RESULT'],
|
||||
keywords: ['newland', 'nls', 'nlscan'],
|
||||
packages: ['com.nlscan.barcodescanner', 'com.newland'],
|
||||
matchNames: ['新大陆', '新大陆(兼容广播)'],
|
||||
matchActions: [
|
||||
'nlscan.action.SCANNER_RESULT',
|
||||
'android.intent.action.RECEIVE_SCANDATA_BROADCAST',
|
||||
],
|
||||
// N5S 机型常标成 alps/zltd,不能只靠 newland 关键字
|
||||
keywords: ['newland', 'nls', 'nlscan', 'n5s', 'zltd'],
|
||||
models: ['n5s', 'n5'],
|
||||
packages: [
|
||||
'com.nlscan.barcodescanner',
|
||||
'com.newland',
|
||||
'com.nlscan.android.scan.service',
|
||||
],
|
||||
},
|
||||
{
|
||||
matchNames: ['优博讯'],
|
||||
@@ -94,10 +111,19 @@ const DETECT_RULES = [
|
||||
];
|
||||
|
||||
const PDA_DEVICE_KEYWORDS = [
|
||||
'newland', 'nls', 'nlscan', 'sunmi', 'urovo', 'ubx', 'zebra', 'honeywell',
|
||||
'newland', 'nls', 'nlscan', 'n5s', 'zltd', 'sunmi', 'urovo', 'ubx', 'zebra', 'honeywell',
|
||||
'idata', 'seuic', 'autoid', '东集', '东大',
|
||||
];
|
||||
|
||||
/** 明确机型 → 优先品牌,避免通用东集广播抢分 */
|
||||
const MODEL_PREFERRED_BRANDS = [
|
||||
{
|
||||
models: ['n5s'],
|
||||
brands: ['nlscan', 'nlscan_compat'],
|
||||
score: 220,
|
||||
},
|
||||
];
|
||||
|
||||
const NO_SETUP_HINT_KEY = 'pda_scan_config_hint_shown';
|
||||
|
||||
export function isPhoneScanConfig(config) {
|
||||
@@ -319,6 +345,57 @@ function canResolveBroadcast(action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isModelMatch(identity, models = []) {
|
||||
const model = String((identity && identity.model) || '').toLowerCase();
|
||||
if (!model) return false;
|
||||
return (models || []).some((item) => model === item || model.includes(item));
|
||||
}
|
||||
|
||||
function getModelPreferredBoost(config, identity) {
|
||||
if (!config || isPhoneScanConfig(config)) {
|
||||
return 0;
|
||||
}
|
||||
const brand = String(config.brand || '');
|
||||
for (let i = 0; i < MODEL_PREFERRED_BRANDS.length; i += 1) {
|
||||
const rule = MODEL_PREFERRED_BRANDS[i];
|
||||
if (!isModelMatch(identity, rule.models)) continue;
|
||||
if ((rule.brands || []).includes(brand)) {
|
||||
return Number(rule.score) || 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** 新大陆 N5S / 智联天地 N5S:机型名常为 n5s,厂商可能是 newland/zltd/alps */
|
||||
export function isNewlandN5sDevice(identity = getDeviceIdentity()) {
|
||||
const model = String((identity && identity.model) || '').toLowerCase();
|
||||
const text = `${identity.manufacturer || ''} ${identity.brand || ''} ${model}`.toLowerCase();
|
||||
if (model === 'n5s' || model.includes('n5s')) {
|
||||
return true;
|
||||
}
|
||||
return text.includes('n5s') && (
|
||||
text.includes('newland')
|
||||
|| text.includes('zltd')
|
||||
|| text.includes('nlscan')
|
||||
|| text.includes('alps')
|
||||
);
|
||||
}
|
||||
|
||||
function isWrongSeuicOnNewlandDevice(config, identity = getDeviceIdentity()) {
|
||||
if (!config || isPhoneScanConfig(config)) {
|
||||
return false;
|
||||
}
|
||||
if (!isNewlandN5sDevice(identity) && !isModelMatch(identity, ['n5s'])) {
|
||||
return false;
|
||||
}
|
||||
const brand = String(config.brand || '');
|
||||
const action = String(config.action || '');
|
||||
return brand === 'seuic'
|
||||
|| action.includes('scannerservice.broadcast')
|
||||
|| String(config.name || '').includes('东集')
|
||||
|| String(config.name || '').includes('东大');
|
||||
}
|
||||
|
||||
function scoreScannerConfig(config, identity) {
|
||||
if (!config || isPhoneScanConfig(config)) {
|
||||
return 0;
|
||||
@@ -339,6 +416,19 @@ function scoreScannerConfig(config, identity) {
|
||||
if ((rule.keywords || []).some((keyword) => deviceText.includes(String(keyword).toLowerCase()))) {
|
||||
score += 40;
|
||||
}
|
||||
if (isModelMatch(identity, rule.models || [])) {
|
||||
score += 80;
|
||||
}
|
||||
}
|
||||
|
||||
score += getModelPreferredBoost(config, identity);
|
||||
|
||||
// 明确是 N5S 时,压低东集通用广播抢分
|
||||
if (isNewlandN5sDevice(identity) && (
|
||||
config.brand === 'seuic'
|
||||
|| String(config.action || '').includes('scannerservice.broadcast')
|
||||
)) {
|
||||
score = Math.min(score, 30);
|
||||
}
|
||||
|
||||
return score;
|
||||
@@ -376,12 +466,16 @@ export function matchBestScanConfig(candidateConfigs = []) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅本地没有有效配置时,自动匹配并写入扫描设置
|
||||
* 仅本地没有有效配置时,自动匹配并写入扫描设置。
|
||||
* 若本地误把 N5S 识别成东集,则强制重配。
|
||||
* @returns {{ saved: boolean, config: object|null, skipped: boolean, reason?: string }}
|
||||
*/
|
||||
export function autoConfigureScanSettings({ remoteConfigs = [] } = {}) {
|
||||
const existing = getScanConfig(BUILTIN_SCANNER_CONFIGS);
|
||||
if (existing) {
|
||||
const identity = getDeviceIdentity();
|
||||
const forceRematch = !!(existing && isWrongSeuicOnNewlandDevice(existing, identity));
|
||||
|
||||
if (existing && !forceRematch) {
|
||||
return {
|
||||
saved: false,
|
||||
skipped: true,
|
||||
@@ -396,7 +490,7 @@ export function autoConfigureScanSettings({ remoteConfigs = [] } = {}) {
|
||||
return {
|
||||
saved: false,
|
||||
skipped: false,
|
||||
config: null,
|
||||
config: existing || null,
|
||||
reason: 'no_match',
|
||||
};
|
||||
}
|
||||
@@ -406,6 +500,8 @@ export function autoConfigureScanSettings({ remoteConfigs = [] } = {}) {
|
||||
saved,
|
||||
skipped: false,
|
||||
config: matched,
|
||||
reason: saved ? 'saved' : 'save_failed',
|
||||
reason: saved
|
||||
? (forceRematch ? 'rematch_n5s_from_seuic' : 'saved')
|
||||
: 'save_failed',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user