feat: login page T0
This commit is contained in:
1 parent
12faab7f92
commit
001f9f4774
5 files changed
+824
-2
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { computed, onUnmounted, ref } from 'vue'
|
||||
|
||||
export function useRetryAfter() {
|
||||
const remaining = ref(0)
|
||||
let timer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
function clear() {
|
||||
if (timer !== null) {
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
}
|
||||
|
||||
function start(seconds: number) {
|
||||
clear()
|
||||
remaining.value = Math.max(0, Math.floor(seconds))
|
||||
if (remaining.value <= 0) {
|
||||
return
|
||||
}
|
||||
timer = setInterval(() => {
|
||||
remaining.value -= 1
|
||||
if (remaining.value <= 0) {
|
||||
remaining.value = 0
|
||||
clear()
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const active = computed(() => remaining.value > 0)
|
||||
|
||||
const formatted = computed(() => {
|
||||
const minutes = Math.floor(remaining.value / 60)
|
||||
const seconds = remaining.value % 60
|
||||
return `${minutes}:${seconds.toString().padStart(2, '0')}`
|
||||
})
|
||||
|
||||
onUnmounted(clear)
|
||||
|
||||
return { remaining, active, formatted, start }
|
||||
}
|
||||
Reference in new issue
Block a user