From 1378fc4cd7abc24ed3a982e09437c2c8a74e9f2f Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期二, 27 一月 2026 19:06:32 +0800
Subject: [PATCH] 代码优化
---
项目代码/WIDESEA_WMSClient/src/extension/inbound/extend/AllcatedPallet.vue | 72 +++++++++++++++++++++++++++++++++--
1 files changed, 67 insertions(+), 5 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/AllcatedPallet.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/AllcatedPallet.vue"
index 0fc42d7..fe15c2e 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/AllcatedPallet.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/AllcatedPallet.vue"
@@ -175,7 +175,7 @@
import http from '@/api/http.js';
import VolBox from '@/components/basic/VolBox.vue';
-// 闃叉姈鍑芥暟淇濇寔涓嶅彉
+// 闃叉姈鍑芥暟
function debounce(func, wait) {
let timeout;
return function () {
@@ -251,7 +251,11 @@
trigger: 'change'
}
]
- }
+ },
+
+ // 鏂板锛氶敭鐩樹簨浠剁洃鍚爣璁�
+ keyPressListenerAdded: false,
+ isDialogClosing: false
}
},
@@ -272,6 +276,26 @@
},
watch: {
+ // 鐩戝惉show鍙橀噺鍙樺寲
+ show(newVal) {
+ if (newVal === true) {
+ console.log('寮规鎵撳紑锛岄噸缃暟鎹�');
+ this.isDialogClosing = false;
+ this.resetData();
+ this.$nextTick(() => {
+ setTimeout(() => {
+ this.fetchUnpalletMaterialDetails();
+ this.addKeyPressListener(); // 娣诲姞閿洏浜嬩欢鐩戝惉
+ }, 300);
+ });
+ } else if (newVal === false && !this.isDialogClosing) {
+ console.log('寮规鍏抽棴锛岀Щ闄や簨浠剁洃鍚�');
+ this.isDialogClosing = true;
+ this.removeKeyPressListener(); // 绉婚櫎閿洏浜嬩欢鐩戝惉
+ this.resetData();
+ }
+ },
+
visible(newVal, oldVal) {
this.palletVisible = newVal;
@@ -306,15 +330,34 @@
},
mounted() {
- document.addEventListener('keypress', this.handleKeyPress);
+ // 涓嶅湪mounted鏃舵坊鍔犵洃鍚紝鍦ㄥ脊绐楁墦寮�鏃舵坊鍔�
},
beforeDestroy() {
- document.removeEventListener('keypress', this.handleKeyPress);
+ // 纭繚缁勪欢閿�姣佹椂绉婚櫎鐩戝惉
+ this.removeKeyPressListener();
this.clearAllTimers();
},
methods: {
+ // 娣诲姞閿洏浜嬩欢鐩戝惉
+ addKeyPressListener() {
+ if (!this.keyPressListenerAdded) {
+ document.addEventListener('keypress', this.handleKeyPress);
+ this.keyPressListenerAdded = true;
+ console.log('閿洏浜嬩欢鐩戝惉宸叉坊鍔�');
+ }
+ },
+
+ // 绉婚櫎閿洏浜嬩欢鐩戝惉
+ removeKeyPressListener() {
+ if (this.keyPressListenerAdded) {
+ document.removeEventListener('keypress', this.handleKeyPress);
+ this.keyPressListenerAdded = false;
+ console.log('閿洏浜嬩欢鐩戝惉宸茬Щ闄�');
+ }
+ },
+
open() {
this.show = true;
this.orderNo = "";
@@ -322,6 +365,13 @@
this.initLocationTypes();
this.initwarehouseTypes();
this.fetchUnpalletMaterialDetails();
+
+ // 寮圭獥鎵撳紑鏃舵坊鍔犻敭鐩樹簨浠剁洃鍚�
+ this.$nextTick(() => {
+ setTimeout(() => {
+ this.addKeyPressListener();
+ }, 100);
+ });
},
validateLocationType(rule, value, callback) {
@@ -483,6 +533,9 @@
},
resetData() {
+ // 鍏堢Щ闄ら敭鐩樹簨浠剁洃鍚�
+ this.removeKeyPressListener();
+
this.palletGroupedBarcodes = {};
this.isSubmitting = false;
this.trayBarcode = '';
@@ -509,6 +562,8 @@
};
this.warehouseTypes = [];
this.locationTypes = [];
+ this.isDialogClosing = false;
+ this.keyPressListenerAdded = false;
this.$nextTick(() => {
if (this.$refs.locationForm) {
@@ -529,6 +584,8 @@
},
handleDialogClose() {
+ // 鍏堢Щ闄ら敭鐩樹簨浠剁洃鍚�
+ this.removeKeyPressListener();
this.show = false;
this.resetData();
},
@@ -759,7 +816,7 @@
});
},
- // API璇锋眰
+ // API璇锋眰 - 娉ㄦ剰杩欓噷淇敼浜咥PI鍦板潃涓�/AllGroupPallet
fetchMaterialData(barcode) {
return http.post('/api/Inbound/AllGroupPallet', {
palletCode: this.trayBarcode,
@@ -797,6 +854,11 @@
// 澶勭悊鎵爜鏋緭鍏�
handleKeyPress(event) {
+ // 妫�鏌ュ脊绐楁槸鍚︽樉绀�
+ if (!this.show || this.isDialogClosing) {
+ return;
+ }
+
if (this.isManualInput || this.isSubmitting) {
return;
}
--
Gitblit v1.9.3