| | |
| | | loadingForm: false, |
| | | submitting: false, |
| | | _searchTimer: null, |
| | | workOrderCurrentCjNum: null // å·¥åå½åæ°é |
| | | workOrderCurrentCjNum: null, // å·¥åå½åæ°é |
| | | |
| | | // èªå¨ä¿åç¸å
³ |
| | | autoSaveTimer: null, |
| | | isDirty: false, // è¡¨åæ¯å¦ææªä¿ååæ´ |
| | | autoSaveIntervalMs: 5 * 60 * 1000, // é»è®¤ 5 åé |
| | | autoSaveEnabled: true, |
| | | autoSaveActionName: 'handleUpTool' // èªå¨è§¦åçæ¹æ³åï¼å¯æ¹ä¸ºèªå®ä¹ä¿åæ¹æ³ |
| | | }; |
| | | }, |
| | | computed: { |
| | |
| | | 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; |
| | |
| | | } catch (err) { |
| | | console.error(err); |
| | | this.$showMessage('ä¸åæäº¤å¤±è´¥ï¼è¯·æ£æ¥ç½ç»'); |
| | | throw err; // æåºä»¥ä¾¿èªå¨ä¿åé»è¾æè·å¹¶ä¿ç isDirty |
| | | } finally { |
| | | this.submitting = false; |
| | | } |
| | |
| | | } catch (err) { |
| | | console.error(err); |
| | | this.$showMessage('ä¸åæäº¤å¤±è´¥ï¼è¯·æ£æ¥ç½ç»'); |
| | | throw err; |
| | | } finally { |
| | | this.submitting = false; |
| | | } |
| | |
| | | this.toolModel = ''; |
| | | this.useLimitInput = ''; |
| | | this.lifeWarnInput = ''; // æ°å¢ï¼æ¸
空 |
| | | this.isDirty = false; |
| | | }, |
| | | async fetchFormData() { |
| | | if (!this.workOrderNo || !this.machineNo) { |
| | |
| | | } else { |
| | | console.warn('æºå°å·æå·¥åå·ä¸ºç©ºï¼æ æ³è·åè¡¨åæ°æ®'); |
| | | } |
| | | |
| | | // å¯å¨èªå¨ä¿å宿¶å¨ |
| | | this.startAutoSave(); |
| | | }, |
| | | beforeDestroy() { |
| | | // æ¸
ç宿¶å¨ï¼é²æ¢å
åæ³æ¼ |
| | | this.stopAutoSave(); |
| | | } |
| | | }; |
| | | </script> |