From 1bcee828a3340d5f5642b3dbcf4cd9733072b7aa Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期一, 21 七月 2025 14:24:35 +0800 Subject: [PATCH] LLJ检验结果录入优化:添加自动保存和回车保存功能 --- pages/QC/LLJ/detail.vue | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 84 insertions(+), 0 deletions(-) diff --git a/pages/QC/LLJ/detail.vue b/pages/QC/LLJ/detail.vue index 68272a8..41783ec 100644 --- a/pages/QC/LLJ/detail.vue +++ b/pages/QC/LLJ/detail.vue @@ -142,6 +142,7 @@ </button> <input v-if="(tableData.length < formData.checkQyt) && formData.fupAllow && formData.fdownAllow" @input="onNumberInput" + @confirm="onEnterSave" v-model="formData.fcheckResu" type="text" class="result-input" @@ -149,6 +150,7 @@ placeholder-class="placeholder" /> <input v-else @input="search($event)" + @confirm="onEnterSave" v-model="inputTxt" type="text" class="result-input" @@ -181,6 +183,7 @@ <view class="input-wrapper" style="margin-top: 15px;"> <input v-if="(tableData.length < formData.checkQyt)" @input="search($event)" + @confirm="onEnterSave" v-model="inputTxt" type="text" class="result-input" placeholder="璇疯緭鍏ユ楠岀粨鏋�..." placeholder-class="placeholder" /> <button v-if="(tableData.length < formData.checkQyt)" @@ -290,9 +293,75 @@ meomPopup: false, showMeom:false, meom: '', + autoSaveTimer: null, // 鑷姩淇濆瓨瀹氭椂鍣� } }, methods: { + // 闃叉姈鑷姩淇濆瓨鏂规硶 + autoSaveResult() { + // 娓呴櫎涔嬪墠鐨勫畾鏃跺櫒 + if (this.autoSaveTimer) { + clearTimeout(this.autoSaveTimer); + } + + // 璁剧疆鏂扮殑瀹氭椂鍣紝1绉掑悗鑷姩淇濆瓨 + this.autoSaveTimer = setTimeout(() => { + // 妫�鏌ユ槸鍚﹀凡缁忚揪鍒版楠屾暟閲忎笂闄� + if (this.tableData.length >= this.formData.checkQyt) { + return; + } + + // 楠岃瘉杈撳叆骞朵繚瀛� + if (this.validateAndSave()) { + this.saveResult(); + } + }, 2000); + }, + + // 楠岃瘉杈撳叆鏄惁鏈夋晥 + validateAndSave() { + // 鏈変笂涓嬮檺鐨勬儏鍐� + if (this.formData.fupAllow && this.formData.fdownAllow) { + const value = this.formData.fcheckResu; + if (!value || value.trim() === '') { + return false; + } + + // 楠岃瘉鏄惁涓烘湁鏁堟暟瀛� + if (isNaN(parseFloat(value)) || !/^-?\d+(\.\d+)?$/.test(value)) { + return false; + } + + return true; + } else { + // 鏃犱笂涓嬮檺鐨勬儏鍐碉紝妫�楠岀粨鏋滃瓨鍌ㄥ湪 formData.fcheckResu 涓� + const value = this.formData.fcheckResu; + if (!value || value.trim() === '') { + return false; + } + + return true; + } + }, + + // 澶勭悊鍥炶溅閿繚瀛樹簨浠� + onEnterSave() { + // 妫�鏌ユ槸鍚﹀凡缁忚揪鍒版楠屾暟閲忎笂闄� + if (this.tableData.length >= this.formData.checkQyt) { + this.$showMessage("宸茶揪鍒版楠屾暟閲忎笂闄�"); + return; + } + + // 娓呴櫎鑷姩淇濆瓨瀹氭椂鍣� + if (this.autoSaveTimer) { + clearTimeout(this.autoSaveTimer); + this.autoSaveTimer = null; + } + + // 鐩存帴淇濆瓨缁撴灉 + this.saveResult(); + }, + switchTab(index, mainIds) { this.currentTab = index this.mainId = mainIds; @@ -377,6 +446,10 @@ //妫�娴嬭緭鍏ユ鐨勮緭鍏ワ紝骞剁粰鍙橀噺璧嬪�� search(event) { this.formData.fcheckResu = event.detail.value; + this.inputTxt = event.detail.value; + + // 瑙﹀彂鑷姩淇濆瓨 + this.autoSaveResult(); }, onNumberInput(e) { // 鍙厑璁歌緭鍏ユ暟瀛楀拰灏忔暟鐐� @@ -385,6 +458,9 @@ val = val.replace(/\.{2,}/g, '.'); val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); this.formData.fcheckResu = val; + + // 瑙﹀彂鑷姩淇濆瓨 + this.autoSaveResult(); }, toggleResult(item) { let fstand = "鈭�"; @@ -699,6 +775,14 @@ this.$nextTick(() => { this.validateBatchInput(); }); + }, + + // 椤甸潰鍗歌浇鏃舵竻闄ゅ畾鏃跺櫒 + onUnload() { + if (this.autoSaveTimer) { + clearTimeout(this.autoSaveTimer); + this.autoSaveTimer = null; + } } } </script> -- Gitblit v1.9.3