Files
FiDA_Front/src/views/login/visible-code.vue

124 lines
2.7 KiB
Vue
Raw Normal View History

2026-02-04 10:01:50 +08:00
<template>
<div class="visible-code">
2026-02-04 17:00:58 +08:00
<div class="title">{{ $t('Login.verifyEmail') }}</div>
<div class="tip" v-html="$t('Login.verifyCodeHasSent', { email: props.email })"></div>
2026-02-04 10:01:50 +08:00
<input-code @submit="onVerify" v-model="code" />
2026-02-04 17:00:58 +08:00
<el-button class="verify" @click="onVerify">{{ $t('Login.verify') }}</el-button>
<p class="time" v-if="time > 0">{{ $t('Login.resendCodeIn', { time: timeStr }) }}</p>
<p class="time" v-if="time === 0">
<span @click="onResend">{{ $t('Login.resendCode') }}</span>
2026-02-04 10:01:50 +08:00
</p>
</div>
</template>
<script setup lang="ts">
2026-02-23 10:08:37 +08:00
import { SendVerificationCode } from '@/api/login'
2026-02-04 10:01:50 +08:00
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { CountDown } from '@/utils/tools'
import InputCode from '@/components/input-code.vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const emit = defineEmits(['submit'])
const props = defineProps({
email: ''
})
const code = ref('')
const time = ref(60)
const timeStr = computed(() => CountDown(time.value))
const timeout = ref(null)
const setTime = (s = 120) => {
clearTime()
time.value = s
timeout.value = setInterval(() => {
time.value--
if (time.value <= 0) {
clearTime()
time.value = 0
}
}, 1000)
}
const clearTime = () => {
time.value = -1
clearTimeout(timeout.value)
}
onBeforeUnmount(() => {
clearTime()
})
onMounted(() => {
2026-02-24 14:54:41 +08:00
// onSendCode()
2026-02-04 10:01:50 +08:00
})
2026-02-23 10:08:37 +08:00
const onSendCode = async () => {
const email = props.email
if (!email) {
console.warn('请输入邮箱')
2026-02-24 14:54:41 +08:00
return Promise.reject('请输入邮箱')
2026-02-23 10:08:37 +08:00
}
await SendVerificationCode({ email })
2026-02-24 14:54:41 +08:00
setTime()
return Promise.resolve()
2026-02-23 10:08:37 +08:00
}
2026-02-04 10:01:50 +08:00
const onResend = () => {
if (time.value > 0) return
2026-02-23 10:08:37 +08:00
onSendCode()
2026-02-04 10:01:50 +08:00
}
const onVerify = () => {
if (code.value.length !== 6) return
emit('submit', code.value)
}
2026-02-24 14:54:41 +08:00
defineExpose({
onSendCode
})
2026-02-04 10:01:50 +08:00
</script>
<style lang="less" scoped>
.visible-code {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
> .title {
font-weight: 600;
font-size: 4rem;
color: #252727;
2026-02-05 13:55:37 +08:00
font-family: SemiBold;
2026-02-04 10:01:50 +08:00
}
> .tip {
margin-top: 2rem;
font-size: 1.8rem;
color: #666;
2026-02-05 13:55:37 +08:00
font-family: Regular;
2026-02-09 14:55:55 +08:00
&:deep(span) {
2026-02-04 10:01:50 +08:00
color: #252727;
2026-02-05 13:55:37 +08:00
font-family: Medium;
2026-02-04 10:01:50 +08:00
}
}
> .input-code {
margin: 8.6rem 0;
}
> .verify {
width: 100%;
height: 6rem;
background: #252727;
font-size: 2rem;
border-radius: 0.8rem;
color: #fff;
font-weight: 600;
2026-02-05 13:55:37 +08:00
font-family: SemiBold;
2026-02-04 10:01:50 +08:00
}
> .time {
user-select: none;
margin-top: 2rem;
font-size: 1.6rem;
color: #666;
2026-02-05 13:55:37 +08:00
font-family: Regular;
2026-02-04 10:01:50 +08:00
> span {
color: #ff7a50;
text-decoration: underline;
cursor: pointer;
font-weight: 500;
2026-02-05 13:55:37 +08:00
font-family: Medium;
2026-02-04 10:01:50 +08:00
}
}
}
</style>