export function useSmsCode() { // 数据 const disabled:globalThis.Ref = ref(false) const text:globalThis.Ref = ref('获取验证码') let timeoutId: any; const handleCodeSend = (timer: number = 60) => { if (disabled.value) return disabled.value = true let n: number = timer text.value = '剩余 ' + n + ' s' timeoutId = setInterval(() => { n = n - 1 if (n < 0) { clearInterval(timeoutId) } text.value = '剩余 ' + n + ' s' if (n <= 0) { disabled.value = false text.value = '重新获取' } }, 1000) } //清除倒计时 const stopCountdown = ()=>{ disabled.value = false if (timeoutId !== undefined) { clearInterval(timeoutId); // 清除定时器 } } return { disabled, text, handleCodeSend, stopCountdown } }