let elapsedTime = 0; //记录时间 存储计时器当前的时间
let timer; //存储setInterval的返回值,用于稍后清除定时器
const formattedTime = (elapsedTime: number) => {
const hours = Math.floor(elapsedTime / 3600);
const minutes = Math.floor((elapsedTime % 3600) / 60);
const seconds = elapsedTime % 60;
return `${hours.toString().padStart(2, '0')}:
${minutes.toString().padStart(2, '0')}:
${seconds.toString().padStart(2, '0')}`;
},
const handleOk = () => {
updateModalRt.synchronizationLoading = true;
timer = setInterval(() => {
elapsedTime += 1;
updateModalRt.value.loadingText = `正在生成中... 已用时:${formattedTime(elapsedTime)}`
}, 1000);
const handleCancel = () =>{
clearInterval(timer);
elapsedTime = 0; //不归零的话 相当于是暂停计时器
}
计时器计时器
于 2024-06-06 15:09:56 首次发布