From 2b90c02a8c5312e80bd21563f24962f26f93a916 Mon Sep 17 00:00:00 2001 From: chiayin Date: Tue, 29 Aug 2023 14:47:53 +0800 Subject: [PATCH] Conformance: time duration component add a comment. --- .../ConformanceTimeRange.vue | 11 +++++++ src/components/durationjs.vue | 29 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/components/Discover/Conformance/ConformanceSidebar/ConformanceTimeRange.vue b/src/components/Discover/Conformance/ConformanceSidebar/ConformanceTimeRange.vue index 1bdfb2f..17d756f 100644 --- a/src/components/Discover/Conformance/ConformanceSidebar/ConformanceTimeRange.vue +++ b/src/components/Discover/Conformance/ConformanceSidebar/ConformanceTimeRange.vue @@ -54,6 +54,9 @@ export default { }, }, methods: { + /** + * set props values + */ setTimeValue() { // 深拷貝原始 timeData 的內容 this.minVuemin = JSON.parse(JSON.stringify(this.timeData.min)); @@ -61,9 +64,17 @@ export default { this.maxVuemin = JSON.parse(JSON.stringify(this.timeData.min)); this.maxVuemax = JSON.parse(JSON.stringify(this.timeData.max)); }, + /** + * get min total seconds + * @param {Number} e + */ minTotalSeconds(e) { this.timeRangeMin = e; }, + /** + * get min total seconds + * @param {Number} e + */ maxTotalSeconds(e) { this.timeRangeMax = e; this.updateMax = e; diff --git a/src/components/durationjs.vue b/src/components/durationjs.vue index 9c1504d..1f97a36 100644 --- a/src/components/durationjs.vue +++ b/src/components/durationjs.vue @@ -122,10 +122,18 @@ export default { }, }, methods: { + /** + * get focus element + * @param {event} event + */ onFocus(event) { this.lastInput = event.target; this.lastInput.select(); // 當呼叫該方法時,文本框內的文字會被自動選中,這樣使用者可以方便地進行複製或刪除等操作。 }, + /** + * when blur update input value and show number + * @param {event} event + */ onBlur(event) { isNaN(event.target.value) ? event.target.value = '00' : @@ -162,6 +170,10 @@ export default { this.calculateTotalSeconds(); }, + /** + * 上下箭頭時的行為 + * @param {event} event + */ onKeyUp(event) { event.target.value = event.target.value.replace(/\D/g, ''); @@ -169,6 +181,12 @@ export default { this.actionUpDown(event.target, event.keyCode === 38, true); }; }, + /** + * 上下箭頭時的行為 + * @param {element} input + * @param {number} goUp + * @param {boolean} selectIt + */ actionUpDown(input, goUp, selectIt = false) { const tUnit = input.dataset.tunit; let newVal = parseInt(input.value, 10); @@ -213,6 +231,11 @@ export default { }; if (selectIt) input.select(); }, + /** + * 設定 dhms 的數值 + * @param {number} totalSeconds + * @param {string} size + */ secondToDate(totalSeconds, size) { totalSeconds = parseInt(totalSeconds); if(!isNaN(totalSeconds)) { @@ -225,6 +248,9 @@ export default { else if(size === 'min') this.minDays = Math.floor(totalSeconds / (3600 * 24)); }; }, + /** + * 計算總秒數 + */ calculateTotalSeconds() { let totalSeconds = 0; @@ -245,6 +271,9 @@ export default { }; this.$emit('total-seconds', this.totalSeconds); }, + /** + * 初始化 + */ async createData() { let size = this.size; if (this.maxTotal !== await null && this.minTotal !== await null) {