From 4957423e351c8007d94a0cba66718c4ebd84a777 Mon Sep 17 00:00:00 2001
From: chen.llin <1442464845@qq.comm>
Date: 星期三, 14 一月 2026 20:12:19 +0800
Subject: [PATCH] rfid-3版
---
common/rfid-input-helper.js | 135 ++++++++++++++++++++++++++++++++++++---------
1 files changed, 108 insertions(+), 27 deletions(-)
diff --git a/common/rfid-input-helper.js b/common/rfid-input-helper.js
index 48095c8..3dc0c07 100644
--- a/common/rfid-input-helper.js
+++ b/common/rfid-input-helper.js
@@ -68,6 +68,63 @@
}
/**
+ * 鎾斁鎻愮ず闊�
+ * @param {String} type - 鎻愮ず闊崇被鍨嬶細'success'=鎴愬姛锛堟淮1澹帮級锛�'error'=閿欒锛堟淮2澹帮級锛�'warning'=璀﹀憡锛堟淮3澹帮級锛�'short'=鐭績锛堝揩閫熸淮1澹帮級
+ */
+function playBeepSound(type = 'success') {
+ // #ifdef APP-PLUS
+ try {
+ // 浣跨敤璁惧铚傞福鍣ㄦ挱鏀炬彁绀洪煶
+ if (typeof plus !== 'undefined' && plus.device && plus.device.beep) {
+ let beepCount = 1; // 榛樿鎾斁1娆�
+
+ // 鏍规嵁绫诲瀷璁剧疆涓嶅悓鐨勬彁绀洪煶
+ switch(type) {
+ case 'success':
+ beepCount = 1; // 鎴愬姛锛氭淮1澹�
+ break;
+ case 'error':
+ beepCount = 2; // 閿欒锛氭淮2澹�
+ break;
+ case 'warning':
+ beepCount = 3; // 璀﹀憡锛氭淮3澹�
+ break;
+ case 'short':
+ beepCount = 1; // 鐭績锛氬揩閫熸淮1澹�
+ break;
+ default:
+ beepCount = 1;
+ }
+
+ plus.device.beep(beepCount); // 鎾斁鎸囧畾娆℃暟
+
+ // 濡傛灉鏄敊璇垨璀﹀憡锛屽彲浠ユ坊鍔犻渿鍔ㄥ弽棣�
+ if (type === 'error' || type === 'warning') {
+ if (typeof plus !== 'undefined' && plus.device && plus.device.vibrate) {
+ setTimeout(() => {
+ plus.device.vibrate(200); // 闇囧姩200ms
+ }, 100);
+ }
+ }
+ } else {
+ // 濡傛灉璁惧涓嶆敮鎸乥eep锛屽皾璇曚娇鐢╲ibrate锛堥渿鍔級浣滀负鏇夸唬
+ if (typeof plus !== 'undefined' && plus.device && plus.device.vibrate) {
+ let vibrateDuration = 100; // 榛樿闇囧姩100ms
+ if (type === 'error') {
+ vibrateDuration = 300; // 閿欒锛氶渿鍔�300ms
+ } else if (type === 'warning') {
+ vibrateDuration = 200; // 璀﹀憡锛氶渿鍔�200ms
+ }
+ plus.device.vibrate(vibrateDuration);
+ }
+ }
+ } catch (error) {
+ console.warn('[RFIDInputHelper] 鎾斁鎻愮ず闊冲け璐�:', error);
+ }
+ // #endif
+}
+
+/**
* 璇诲彇RFID鏍囩锛堝崟鏍囩璇伙紝鏃犺繃婊わ級
*/
function readRFIDTag() {
@@ -150,6 +207,8 @@
}
console.log('[RFIDInputHelper] 鉁� 璇诲彇鍒版爣绛綞PC (闀垮害' + epc.length + '浣�):', epc);
+ // 鎾斁鎻愮ず闊筹紙婊翠竴澹帮級
+ // playBeepSound(); // 宸叉敞閲婏紝鍚庣画鑷繁鍐冲畾鏄惁鍚敤
// 鑷姩濉叆褰撳墠鐒︾偣杈撳叆妗嗭紙涓嶈拷鍔狅紝浣跨敤瀹為檯闀垮害锛�
fillCurrentInput(epc);
modal.toast({
@@ -176,6 +235,8 @@
if (originalLength !== hexOnly.length) {
console.log('[RFIDInputHelper] 鍘婚櫎鍓嶅0: 鍘熷闀垮害=' + originalLength + ', 鍘婚櫎鍚庨暱搴�=' + hexOnly.length);
}
+ // 鎾斁鎻愮ず闊筹紙婊翠竴澹帮級
+ // playBeepSound(); // 宸叉敞閲婏紝鍚庣画鑷繁鍐冲畾鏄惁鍚敤
fillCurrentInput(hexOnly); // 浣跨敤瀹為檯闀垮害锛屼笉杩藉姞
modal.toast({
message: '宸茶鍙栨爣绛�',
@@ -219,6 +280,8 @@
}
console.log('[RFIDInputHelper] 鉁� 璇诲彇鍒版爣绛綞PC (闀垮害' + epc.length + '浣�):', epc);
+ // 鎾斁鎻愮ず闊筹紙婊翠竴澹帮級
+ // playBeepSound(); // 宸叉敞閲婏紝鍚庣画鑷繁鍐冲畾鏄惁鍚敤
fillCurrentInput(epc); // 浣跨敤瀹為檯闀垮害锛屼笉杩藉姞
modal.toast({
message: '宸茶鍙栨爣绛�',
@@ -269,20 +332,52 @@
const vm = currentPage.$vm;
console.log('[RFIDInputHelper] 褰撳墠椤甸潰:', currentPage.route);
- // 瀹氫箟杈撳叆妗嗗瓧娈靛拰瀵瑰簲鐨勭劍鐐圭姸鎬佸瓧娈�
+ // 瀹氫箟杈撳叆妗嗗瓧娈靛拰瀵瑰簲鐨勭劍鐐圭姸鎬佸瓧娈碉紙棰勫畾涔夌殑甯歌瀛楁锛�
// 鏍煎紡锛歿 瀛楁鍚�: 鐒︾偣鐘舵�佸瓧娈靛悕 }
- const inputFieldMap = [
+ const predefinedFieldMap = [
{ field: 'barcode', focusField: 'barcodeFocus' },
{ field: 'matnr', focusField: 'matFocus' },
{ field: 'sourceSite', focusField: 'sourceSiteFocus' },
{ field: 'orderNo', focusField: 'orderNoFocus' },
{ field: 'targetSite', focusField: 'targetSiteFocus' },
- { field: 'locNo', focusField: 'locNoFocus' }
+ { field: 'locNo', focusField: 'locNoFocus' },
+ { field: 'batch', focusField: 'batchFocus' },
+ { field: 'userName', focusField: 'userNameFocus' },
+ { field: 'password', focusField: 'passwordFocus' }
];
+
+ // 鑷姩妫�娴嬫墍鏈夊彲鑳界殑杈撳叆妗嗗瓧娈碉紙浠巚m.$data涓煡鎵炬墍鏈夊瓧绗︿覆绫诲瀷鐨勫睘鎬э級
+ const autoDetectedFields = [];
+ if (vm.$data) {
+ for (let key in vm.$data) {
+ // 璺宠繃浠�$寮�澶寸殑Vue鍐呴儴灞炴�э紝璺宠繃鍑芥暟锛岃烦杩噁ocus瀛楁鏈韩
+ if (key.startsWith('$') || typeof vm.$data[key] === 'function' || key.endsWith('Focus')) {
+ continue;
+ }
+ // 濡傛灉鏄瓧绗︿覆绫诲瀷锛岃涓烘槸鍙兘鐨勮緭鍏ユ瀛楁
+ if (typeof vm.$data[key] === 'string' || vm.$data[key] === null || vm.$data[key] === undefined) {
+ // 妫�鏌ユ槸鍚︽湁瀵瑰簲鐨刦ocusField锛堝瓧娈靛悕 + Focus锛�
+ const focusFieldName = key + 'Focus';
+ if (vm.$data[focusFieldName] !== undefined) {
+ autoDetectedFields.push({ field: key, focusField: focusFieldName });
+ }
+ }
+ }
+ }
+
+ // 鍚堝苟棰勫畾涔夊瓧娈靛拰鑷姩妫�娴嬬殑瀛楁锛堝幓閲嶏級
+ const allFieldsMap = [...predefinedFieldMap];
+ for (let autoField of autoDetectedFields) {
+ // 妫�鏌ユ槸鍚﹀凡瀛樺湪
+ const exists = allFieldsMap.some(item => item.field === autoField.field);
+ if (!exists) {
+ allFieldsMap.push(autoField);
+ }
+ }
// 璋冭瘯锛氭墦鍗版墍鏈夎緭鍏ユ鐨勭劍鐐圭姸鎬�
console.log('[RFIDInputHelper] ========== 妫�鏌ヨ緭鍏ユ鐒︾偣鐘舵�� ==========');
- for (let item of inputFieldMap) {
+ for (let item of allFieldsMap) {
if (vm[item.field] !== undefined) {
const focusValue = vm[item.focusField];
console.log(`[RFIDInputHelper] ${item.field}: focus=${focusValue}, value="${vm[item.field]}"`);
@@ -291,7 +386,7 @@
// 鍙煡鎵炬湁鐒︾偣鐨勮緭鍏ユ锛堝厜鏍囨墍鍦ㄧ殑杈撳叆妗嗭級
let focusedField = null;
- for (let item of inputFieldMap) {
+ for (let item of allFieldsMap) {
if (vm[item.field] !== undefined) {
// 妫�鏌ユ槸鍚︽湁鐒︾偣鐘舵�佸瓧娈碉紝骞朵笖鐒︾偣涓簍rue
const focusValue = vm[item.focusField];
@@ -307,31 +402,17 @@
// 鍙~鍏ユ湁鐒︾偣鐨勮緭鍏ユ锛屽鏋滄病鏈夌劍鐐瑰垯涓嶅~鍏�
if (focusedField) {
console.log(`[RFIDInputHelper] 濉叆鏈夌劍鐐圭殑杈撳叆妗� ${focusedField}:`, epc);
- console.log(`[RFIDInputHelper] 杈撳叆妗嗗綋鍓嶅��: "${vm[focusedField]}"`);
-
- // 鍏堟竻绌鸿緭鍏ユ锛屽啀濉叆鏂板�硷紙閬垮厤杩藉姞锛�
- vm[focusedField] = '';
-
- // 浣跨敤 $nextTick 纭繚娓呯┖鎿嶄綔瀹屾垚鍚庡啀濉叆鏂板��
+ vm[focusedField] = epc;
+ // 瑙﹀彂input浜嬩欢锛岀‘淇濋〉闈㈤�昏緫鑳藉搷搴�
if (vm.$nextTick) {
vm.$nextTick(() => {
- // 濉叆鏂扮殑EPC鍊硷紙鏇挎崲锛屼笉杩藉姞锛�
- vm[focusedField] = epc;
- console.log(`[RFIDInputHelper] 鉁� 宸叉浛鎹㈣緭鍏ユ鍊间负: "${vm[focusedField]}"`);
-
- // 鍐嶆浣跨敤 $nextTick 纭繚鍊煎凡璁剧疆锛屽啀瑙﹀彂input浜嬩欢
- vm.$nextTick(() => {
- // 濡傛灉椤甸潰鏈夊搴旂殑input澶勭悊鏂规硶锛屽彲浠ユ墜鍔ㄨЕ鍙�
- if (focusedField === 'barcode' && typeof vm.barcodeInput === 'function') {
- vm.barcodeInput();
- } else if (focusedField === 'matnr' && typeof vm.findMat === 'function') {
- vm.findMat();
- }
- });
+ // 濡傛灉椤甸潰鏈夊搴旂殑input澶勭悊鏂规硶锛屽彲浠ユ墜鍔ㄨЕ鍙�
+ if (focusedField === 'barcode' && typeof vm.barcodeInput === 'function') {
+ vm.barcodeInput();
+ } else if (focusedField === 'matnr' && typeof vm.findMat === 'function') {
+ vm.findMat();
+ }
});
- } else {
- // 濡傛灉娌℃湁 $nextTick锛岀洿鎺ヨ缃�
- vm[focusedField] = epc;
}
} else {
console.warn('[RFIDInputHelper] 鉁� 鏈壘鍒版湁鐒︾偣鐨勮緭鍏ユ锛屼笉濉叆浠讳綍杈撳叆妗�');
--
Gitblit v1.9.1