根据具体的时分秒增值或者减值
data(){
return{
batchData:[
{batchNum:'NVGAH76',quantity:20000,time:'12:01:03',endTime:'15:01:03',top:30,left:14},
{batchNum:'NVGAH76',quantity:20000,time:'03:34:14',endTime:'06:32:58',top:200,left:14},
{batchNum:'NVGAH76',quantity:20000,time:'02:44:32',endTime:'16:01:09',top:370,left:14},
{batchNum:'NVGAH76',quantity:20000,time:'11:01:33',endTime:'12:01:23',top:548,left:14},
{batchNum:'NVGAH73',quantity:'1600L',time:'10:01:13',endTime:'16:31:03',top:30,left:426},
{batchNum:'NVGAH72',quantity:'1650L',time:'18:01:03',endTime:'20:01:03',top:30,left:846},
{batchNum:'NVGAH77',quantity:'1600L',time:'07:31:03',endTime:'10:01:43',top:200,left:426},
{batchNum:'NVGAH76',quantity:'1650L',time:'10:01:13',endTime:'14:05:03',top:200,left:846},
{batchNum:'NVGAH74',quantity:'1600L',time:'09:08:23',endTime:'11:31:43',top:478,left:518},
{batchNum:'NVGAH73',quantity:'1600L',time:'10:01:43',endTime:'13:31:53',top:478,left:960},
]
}
}
增值
increaseTime() {
for(let i = 0; i < this.batchData.length; i++) {
const [hours, minutes, seconds] = this.batchData[i].time.split(':'); // 将当前时间按小时、分钟、秒进行切割
let newSeconds = parseInt(seconds) + 1; // 新的秒数等于原有秒数+1
let newMinutes = parseInt(minutes); // 初始化新的分钟数等于原有分钟数
let newHours = parseInt(hours); // 初始化新的小时数等于原有小时数
if (newSeconds >= 60) { // 若新的秒数达到了60(表示已经过去了一分钟)
newSeconds = 0; // 则重置为0
newMinutes += 1; // 同样地,更新分钟数
if (newMinutes >= 60) { // 若新的分钟数达到了60(表示已经过去了一小时)
newMinutes = 0; // 则重置为0
newHours += 1; // 最后更新小时数
if (newHours >= 24) { // 若新的小时数大于或等于24(表示已经过去了一天)
newHours %= 24; // 则取余数作为新的小时数
}
}
}
this.batchData[i].time = `${newHours.toString().padStart(2, '0')}:${newMinutes.toString().padStart(2, '0')}:${newSeconds.toString().padStart(2, '0')}`; // 更新显示的时间
}
},
减值
increaseTime1() {
for(let i = 0; i < this.batchData.length; i++) {
const [hours, minutes, seconds] = this.batchData[i].endTime.split(':');
let newSeconds = parseInt(seconds) - 1;
let newMinutes = parseInt(minutes);
let newHours = parseInt(hours);
if (newSeconds < 0) { // 当秒数变为负数时,需要减少分钟数
newSeconds = 59; // 重置秒数为59
newMinutes -= 1;
if (newMinutes < 0) { // 当分钟数变为负数时,需要减少小时数
newMinutes = 59; // 重置分钟数为59
newHours -= 1;
if (newHours < 0) { // 当小时数变为负数时,表示时间已经过去一天
newHours += 24; // 取余数作为新的小时数
}
}
}
this.batchData[i].endTime = `${newHours.toString().padStart(2, '0')}:${newMinutes.toString().padStart(2, '0')}:${newSeconds.toString().padStart(2, '0')}`;
}
},