111
This commit is contained in:
@@ -22,18 +22,14 @@
|
||||
import { useI18n } from 'vue-i18n'
|
||||
const { t } = useI18n()
|
||||
const router = useRouter()
|
||||
const emit = defineEmits(['submit-email-code'])
|
||||
const emit = defineEmits(['submit-email-code', 'resend-email-code'])
|
||||
const props = defineProps({
|
||||
email: { type: String, required: true },
|
||||
type: {
|
||||
type: String as () => 'LOGIN' | 'REGISTER' | 'FORGET_PWD',
|
||||
required: true
|
||||
},
|
||||
password: { type: String, default: '' },
|
||||
isShowOtherLogin: { type: Boolean, default: true }
|
||||
})
|
||||
const code = ref('')
|
||||
const time = ref(60)
|
||||
const time = ref(0)
|
||||
const timeStr = computed(() => CountDown(time.value))
|
||||
const timeout = ref(null)
|
||||
const setTime = (s = 120) => {
|
||||
@@ -55,7 +51,8 @@
|
||||
clearTime()
|
||||
})
|
||||
onMounted(() => {
|
||||
onSendCode()
|
||||
// onSendCode()
|
||||
setTime()
|
||||
})
|
||||
const inputCodeRef = ref(null)
|
||||
const resetCode = () => {
|
||||
@@ -68,19 +65,9 @@
|
||||
console.warn('请输入邮箱')
|
||||
return Promise.reject('请输入邮箱')
|
||||
}
|
||||
// const data = {
|
||||
// email,
|
||||
// type: props.type
|
||||
// }
|
||||
// if (props.type === 'LOGIN') {
|
||||
// data['password'] = md5(props.password)
|
||||
// }
|
||||
// const res = await SendVerificationCode(data)
|
||||
// if (!res) {
|
||||
// ElMessage.error(t('Login.sendCodeError'))
|
||||
// return Promise.reject('发送验证码失败')
|
||||
// }
|
||||
emit('resend-email-code', () => {
|
||||
setTime()
|
||||
})
|
||||
return Promise.resolve()
|
||||
}
|
||||
const onResend = () => {
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
@login="onLogin"
|
||||
@register="onRegister"
|
||||
@submit-email-code="onSubmitEmailCode"
|
||||
@resend-email-code="onResendEmailCode"
|
||||
@back="onBack"
|
||||
:name="data.name"
|
||||
:email="data.email"
|
||||
:password="data.password"
|
||||
type="FORGET_PWD"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -128,26 +128,24 @@
|
||||
myEvent.remove('openLoginDialog', open)
|
||||
})
|
||||
|
||||
const onLogin = (res: any) => {
|
||||
AccountSendLoginCode({
|
||||
const onLogin = async (res: any) => {
|
||||
await AccountSendLoginCode({
|
||||
email: res.email,
|
||||
password: md5(res.password)
|
||||
}).then((v) => {
|
||||
})
|
||||
data.value = res
|
||||
data.value.type = TabNames.login
|
||||
currentTab.value = TabNames.email_verify
|
||||
})
|
||||
}
|
||||
const onRegister = (res: any) => {
|
||||
const onRegister = async (res: any) => {
|
||||
const value = {
|
||||
email: res.email,
|
||||
operationType: 'REGISTER'
|
||||
}
|
||||
AccountSendVerifyCode(value).then((v) => {
|
||||
await AccountSendVerifyCode(value)
|
||||
data.value = res
|
||||
data.value.type = TabNames.register
|
||||
currentTab.value = TabNames.email_verify
|
||||
})
|
||||
}
|
||||
const onSubmitEmailCode = (code: string) => {
|
||||
const value = {
|
||||
@@ -167,6 +165,14 @@
|
||||
})
|
||||
}
|
||||
}
|
||||
const onResendEmailCode = async (callback: () => void) => {
|
||||
if (data.value.type === TabNames.login) {
|
||||
await onLogin(data.value)
|
||||
} else if (data.value.type === TabNames.register) {
|
||||
await onRegister(data.value)
|
||||
}
|
||||
callback()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
</el-form>
|
||||
<div class="verify-box" v-if="index === 1">
|
||||
<email-verify
|
||||
type="FORGOT_PWD"
|
||||
:email="formData.email"
|
||||
@submit-email-code="onVerifyCode"
|
||||
@resend-email-code="SendVerifyCode"
|
||||
:is-show-other-login="false"
|
||||
/>
|
||||
</div>
|
||||
@@ -104,10 +104,7 @@
|
||||
const onSubmit1 = () => {
|
||||
form1Ref.value?.validate?.((valid) => {
|
||||
if (valid) {
|
||||
AccountSendVerifyCode({
|
||||
email: formData.email,
|
||||
operationType: 'FORGOT_PWD'
|
||||
}).then(() => {
|
||||
SendVerifyCode().then(() => {
|
||||
index.value = 1
|
||||
})
|
||||
} else {
|
||||
@@ -115,12 +112,18 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
const SendVerifyCode = async () => {
|
||||
await AccountSendVerifyCode({
|
||||
email: formData.email,
|
||||
operationType: 'FORGET_PWD'
|
||||
})
|
||||
}
|
||||
const onVerifyCode = (code: string) => {
|
||||
if (!code) return
|
||||
AccountVerifyCode({
|
||||
email: formData.email,
|
||||
emailVerifyCode: code,
|
||||
operationType: 'FORGOT_PWD'
|
||||
operationType: 'FORGET_PWD'
|
||||
}).then(() => {
|
||||
formData.code = code
|
||||
index.value = 2
|
||||
|
||||
Reference in New Issue
Block a user