KUN1007 / kun-galgame-vue

The CUTEST Visual Novel / Galgame Forum! KUN Visual Novel Forum front-end project
https://www.kungal.com
GNU Affero General Public License v3.0
87 stars 8 forks source link

邮件发送冷却在点击按钮后开始计时而非请求完成后开始计时 #19

Closed ghost closed 11 months ago

ghost commented 11 months ago

Describe the bug 注册账号时,邮件发送冷却在点击按钮后开始计时而非请求完成后开始计时,即使请求失败,仍需等冷却结束后再发送请求

Expected behavior 在客户端收到响应后开始计时,若请求失败,则不进行计时

KUN1007 commented 11 months ago

Thank you very much for your report.

The reason for this error was that I did not use watch for responsive monitoring in the Code component. It has now been resolved.

// The parent component instructs it to send the verification code, and it will do so.
const props = defineProps<{
  email: string
  isSendCode: boolean
}>()

const isSending = ref(false)

const countdown = ref(0)

watch(
  () => props.isSendCode,
  async () => {
    if (!isSending.value) {
      isSending.value = true
      countdown.value = 30

      const countdownInterval = setInterval(() => {
        countdown.value -= 1
        if (countdown.value === 0) {
          clearInterval(countdownInterval)
          isSending.value = false
        }
      }, 1000)

      // Send the verification code
      await useKUNGalgameUserStore().sendCode(props.email)

      info.info('AlertInfo.code.code')
    }
  }
)