refactor duration.js
This commit is contained in:
@@ -1259,6 +1259,29 @@ export default {
|
||||
checkActivityDuration() {
|
||||
return !this.selectDurationData?.length;
|
||||
},
|
||||
/**
|
||||
* 檢查活動序列的邏輯
|
||||
* @returns {boolean} 是否禁用按鈕
|
||||
*/
|
||||
checkActivitySequence() {
|
||||
switch (this.selectedActivitySequence) {
|
||||
case 'Start & End':
|
||||
return checkStartAndEndSequence(this.selectCfmSeqStart, this.selectCfmSeqEnd);
|
||||
case 'Sequence':
|
||||
return checkSequenceMode(this.selectedMode);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 檢查 Start & End 活動序列
|
||||
* @param {string} start 活動開始
|
||||
* @param {string} end 活動結束
|
||||
* @returns {boolean} 是否禁用按鈕
|
||||
*/
|
||||
checkStartAndEndSequence(start, end) {
|
||||
return !(start && end);
|
||||
},
|
||||
checkProcessingTime() {
|
||||
let disabled = true;
|
||||
switch (this.selectedProcessScope) {
|
||||
|
||||
@@ -250,37 +250,83 @@ export default {
|
||||
*/
|
||||
actionUpDown(input, goUp, selectIt = false) {
|
||||
const tUnit = input.dataset.tunit;
|
||||
let newVal = parseInt(input.value, 10);
|
||||
|
||||
newVal = isNaN(newVal) ? 0 : newVal;
|
||||
let newVal = this.getNewValue(input);
|
||||
|
||||
if (goUp) {
|
||||
// 箭頭向上,數字加一
|
||||
newVal = this.handleArrowUp(newVal, tUnit, input);
|
||||
} else {
|
||||
newVal = this.handleArrowDown(newVal, tUnit);
|
||||
}
|
||||
|
||||
this.updateInputValue(input, newVal, tUnit);
|
||||
if (selectIt) {
|
||||
input.select();
|
||||
}
|
||||
this.calculateTotalSeconds();
|
||||
},
|
||||
|
||||
/**
|
||||
* 獲取新的數值
|
||||
* @param {element} input 輸入的元素
|
||||
* @returns {number} 新的數值
|
||||
*/
|
||||
getNewValue(input) {
|
||||
let newVal = parseInt(input.value, 10);
|
||||
return isNaN(newVal) ? 0 : newVal;
|
||||
},
|
||||
|
||||
/**
|
||||
* 處理向上箭頭的行為
|
||||
* @param {number} newVal 當前數值
|
||||
* @param {string} tUnit 時間單位
|
||||
* @param {element} input 輸入的元素
|
||||
* @returns {number} 更新後的數值
|
||||
*/
|
||||
handleArrowUp(newVal, tUnit, input) {
|
||||
newVal += this.tUnits[tUnit].inc;
|
||||
if (newVal > this.tUnits[tUnit].max) {
|
||||
if (this.tUnits[tUnit].dsp === 'd') {
|
||||
// 超過 maxDays 要等於最大值
|
||||
this.totalSeconds = this.maxTotal;
|
||||
} else {
|
||||
// 超過該單位最大值時要進位為零
|
||||
newVal = newVal % (this.tUnits[tUnit].max + 1);
|
||||
// 前一個更大的單位要進位
|
||||
this.incrementPreviousUnit(input);
|
||||
}
|
||||
}
|
||||
return newVal;
|
||||
},
|
||||
|
||||
/**
|
||||
* 處理向下箭頭的行為
|
||||
* @param {number} newVal 當前數值
|
||||
* @param {string} tUnit 時間單位
|
||||
* @returns {number} 更新後的數值
|
||||
*/
|
||||
handleArrowDown(newVal, tUnit) {
|
||||
newVal -= this.tUnits[tUnit].inc;
|
||||
if (newVal < 0) {
|
||||
newVal = (this.tUnits[tUnit].max + 1) - this.tUnits[tUnit].inc;
|
||||
}
|
||||
return newVal;
|
||||
},
|
||||
|
||||
/**
|
||||
* 進位前一個更大的單位
|
||||
* @param {element} input 輸入的元素
|
||||
*/
|
||||
incrementPreviousUnit(input) {
|
||||
if (input.dataset.index > 0) {
|
||||
const prevUnit = document.querySelector(`input[data-index="${parseInt(input.dataset.index) - 1}"]`);
|
||||
this.actionUpDown(prevUnit, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 箭頭向下,數字減一
|
||||
newVal -= this.tUnits[tUnit].inc;
|
||||
if (newVal < 0) {
|
||||
// 小於零要調整為該單位最大值,但下一個單位不動
|
||||
newVal = (this.tUnits[tUnit].max + 1) - this.tUnits[tUnit].inc;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// input.value = newVal.toString().padStart(2, '0'); // 前綴要補 0
|
||||
/**
|
||||
* 更新輸入框的數值
|
||||
* @param {element} input 輸入的元素
|
||||
* @param {number} newVal 新的數值
|
||||
* @param {string} tUnit 時間單位
|
||||
*/
|
||||
updateInputValue(input, newVal, tUnit) {
|
||||
input.value = newVal.toString();
|
||||
switch (tUnit) {
|
||||
case 'd':
|
||||
@@ -295,11 +341,7 @@ export default {
|
||||
case 's':
|
||||
this.seconds = input.value;
|
||||
break;
|
||||
};
|
||||
if (selectIt) {
|
||||
input.select();
|
||||
}
|
||||
this.calculateTotalSeconds();
|
||||
},
|
||||
/**
|
||||
* 設定 dhms 的數值
|
||||
|
||||
Reference in New Issue
Block a user