快乐的昕的电脑
2025-10-31 5197487b9d4948cccaafbd56faf05acb51ea307a
自动保存相关
已修改7个文件
68 ■■■■■ 文件已修改
.vs/前端2/CopilotIndices/17.14.878.3237/CodeChunks.db 补丁 | 查看 | 原始文档 | blame | 历史
.vs/前端2/CopilotIndices/17.14.878.3237/CodeChunks.db-shm 补丁 | 查看 | 原始文档 | blame | 历史
.vs/前端2/CopilotIndices/17.14.878.3237/CodeChunks.db-wal 补丁 | 查看 | 原始文档 | blame | 历史
.vs/前端2/CopilotIndices/17.14.878.3237/SemanticSymbols.db 补丁 | 查看 | 原始文档 | blame | 历史
.vs/前端2/CopilotIndices/17.14.878.3237/SemanticSymbols.db-shm 补丁 | 查看 | 原始文档 | blame | 历史
.vs/前端2/CopilotIndices/17.14.878.3237/SemanticSymbols.db-wal 补丁 | 查看 | 原始文档 | blame | 历史
components/mold.vue 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.vs/ǰ¶Ë2/CopilotIndices/17.14.878.3237/CodeChunks.db
Binary files differ
.vs/ǰ¶Ë2/CopilotIndices/17.14.878.3237/CodeChunks.db-shm
Binary files differ
.vs/ǰ¶Ë2/CopilotIndices/17.14.878.3237/CodeChunks.db-wal
Binary files differ
.vs/ǰ¶Ë2/CopilotIndices/17.14.878.3237/SemanticSymbols.db
Binary files differ
.vs/ǰ¶Ë2/CopilotIndices/17.14.878.3237/SemanticSymbols.db-shm
Binary files differ
.vs/ǰ¶Ë2/CopilotIndices/17.14.878.3237/SemanticSymbols.db-wal
Binary files differ
components/mold.vue
@@ -138,7 +138,14 @@
                loadingForm: false,
                submitting: false,
                _searchTimer: null,
                workOrderCurrentCjNum: null // å·¥å•当前数采
                workOrderCurrentCjNum: null, // å·¥å•当前数采
                // è‡ªåŠ¨ä¿å­˜ç›¸å…³
                autoSaveTimer: null,
                isDirty: false, // è¡¨å•是否有未保存变更
                autoSaveIntervalMs: 5 * 60 * 1000, // é»˜è®¤ 5 åˆ†é’Ÿ
                autoSaveEnabled: true,
                autoSaveActionName: 'handleUpTool' // è‡ªåŠ¨è§¦å‘çš„æ–¹æ³•åï¼Œå¯æ”¹ä¸ºè‡ªå®šä¹‰ä¿å­˜æ–¹æ³•
            };
        },
        computed: {
@@ -146,7 +153,56 @@
                return Math.max(1, Math.ceil(this.total / this.pageSize) || 1);
            }
        },
        watch: {
            // æ ‡è®°è„æ•°æ®ï¼šæŒ‰éœ€ç›‘听字段变化
            selectedToolNo() { this.isDirty = true; },
            useLimitInput() { this.isDirty = true; },
            lifeWarnInput() { this.isDirty = true; },
            toolName() { this.isDirty = true; },
            toolModel() { this.isDirty = true; }
        },
        methods: {
            // è‡ªåŠ¨ä¿å­˜ï¼šå¯åŠ¨
            startAutoSave() {
                if (!this.autoSaveEnabled) return;
                this.stopAutoSave();
                this.autoSaveTimer = setInterval(() => {
                    this.autoSaveTick();
                }, this.autoSaveIntervalMs);
            },
            // è‡ªåŠ¨ä¿å­˜ï¼šåœæ­¢
            stopAutoSave() {
                if (this.autoSaveTimer) {
                    clearInterval(this.autoSaveTimer);
                    this.autoSaveTimer = null;
                }
            },
            // è‡ªåŠ¨ä¿å­˜ï¼šæ¯æ¬¡å®šæ—¶æ‰§è¡Œæ—¶çš„é€»è¾‘
            async autoSaveTick() {
                if (!this.autoSaveEnabled) return;
                if (!this.isDirty) return;
                if (this.submitting || this.loadingForm) return;
                const fn = this.autoSaveActionName && typeof this[this.autoSaveActionName] === 'function'
                    ? this[this.autoSaveActionName]
                    : null;
                if (!fn) {
                    console.warn('自动保存:未找到方法', this.autoSaveActionName);
                    return;
                }
                try {
                    this.submitting = true;
                    await fn.call(this); // è°ƒç”¨ä¿å­˜æ–¹æ³•(例如 handleUpTool)
                    // å¦‚果保存成功,清脏标记(保存方法内部若失败没有抛出可保持此方式)
                    this.isDirty = false;
                } catch (e) {
                    console.error('自动保存失败:', e);
                } finally {
                    this.submitting = false;
                }
            },
            // æ–°å¢žï¼šå¯¿å‘½æ¯”预警值归一化 (返回 0~1 æˆ– null)
            normalizeLifeWarn(v) {
                if (v == null) return null;
@@ -322,6 +378,7 @@
                } catch (err) {
                    console.error(err);
                    this.$showMessage('上刀提交失败,请检查网络');
                    throw err; // æŠ›å‡ºä»¥ä¾¿è‡ªåŠ¨ä¿å­˜é€»è¾‘æ•èŽ·å¹¶ä¿ç•™ isDirty
                } finally {
                    this.submitting = false;
                }
@@ -373,6 +430,7 @@
                } catch (err) {
                    console.error(err);
                    this.$showMessage('下刀提交失败,请检查网络');
                    throw err;
                } finally {
                    this.submitting = false;
                }
@@ -383,6 +441,7 @@
                this.toolModel = '';
                this.useLimitInput = '';
                this.lifeWarnInput = ''; // æ–°å¢žï¼šæ¸…空
                this.isDirty = false;
            },
            async fetchFormData() {
                if (!this.workOrderNo || !this.machineNo) {
@@ -560,6 +619,13 @@
            } else {
                console.warn('机台号或工单号为空,无法获取表单数据');
            }
            // å¯åŠ¨è‡ªåŠ¨ä¿å­˜å®šæ—¶å™¨
            this.startAutoSave();
        },
        beforeDestroy() {
            // æ¸…理定时器,防止内存泄漏
            this.stopAutoSave();
        }
    };
</script>