Skip to content

Commit

Permalink
fix: 补充重构邮箱登录后遗漏的行为验证码
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Nov 11, 2024
1 parent 387ddac commit f140810
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
36 changes: 26 additions & 10 deletions src/views/login/components/email/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@
</a-space>
</a-form-item>
</a-form>
<Verify
ref="VerifyRef"
:captcha-type="captchaType"
:mode="captchaMode"
:img-size="{ width: '330px', height: '155px' }"
@success="getCaptcha"
/>
</template>

<script setup lang="ts">
// import { getEmailCaptcha } from '@/apis'
import { type FormInstance, Message } from '@arco-design/web-vue'
import type { BehaviorCaptchaReq } from '@/apis'
// import { type BehaviorCaptchaReq, getEmailCaptcha } from '@/apis'
import { useTabsStore, useUserStore } from '@/stores'
import * as Regexp from '@/utils/regexp'
Expand Down Expand Up @@ -64,7 +72,7 @@ const handleLogin = async () => {
await userStore.emailLogin(form)
tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query
router.push({
await router.push({
path: (redirect as string) || '/',
query: {
...othersQuery,
Expand All @@ -78,6 +86,19 @@ const handleLogin = async () => {
}
}
const VerifyRef = ref<InstanceType<any>>()
const captchaType = ref('blockPuzzle')
const captchaMode = ref('pop')
const captchaLoading = ref(false)
// 弹出行为验证码
const onCaptcha = async () => {
if (captchaLoading.value) return
const isInvalid = await formRef.value?.validateField('email')
if (isInvalid) return
VerifyRef.value.show()
}
const captchaTimer = ref()
const captchaTime = ref(60)
const captchaBtnName = ref('获取验证码')
Expand All @@ -90,18 +111,13 @@ const resetCaptcha = () => {
captchaDisable.value = false
}
const captchaLoading = ref(false)
// 获取验证码
const onCaptcha = async () => {
if (captchaLoading.value) return
const isInvalid = await formRef.value?.validateField('email')
if (isInvalid) return
// eslint-disable-next-line unused-imports/no-unused-vars
const getCaptcha = async (captchaReq: BehaviorCaptchaReq) => {
try {
captchaLoading.value = true
captchaBtnName.value = '发送中...'
// await getEmailCaptcha({
// email: form.email
// })
// await getEmailCaptcha(form.email, captchaReq)
captchaLoading.value = false
captchaDisable.value = true
captchaBtnName.value = `获取验证码(${(captchaTime.value -= 1)}s)`
Expand Down
12 changes: 6 additions & 6 deletions src/views/login/components/phone/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
</template>

<script setup lang="ts">
// import { getSmsCaptcha } from '@/apis'
import { type FormInstance, Message } from '@arco-design/web-vue'
import type { BehaviorCaptchaReq } from '@/apis'
// import { type BehaviorCaptchaReq, getSmsCaptcha } from '@/apis'
import { useTabsStore, useUserStore } from '@/stores'
import * as Regexp from '@/utils/regexp'
Expand Down Expand Up @@ -71,7 +72,7 @@ const handleLogin = async () => {
await userStore.phoneLogin(form)
tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query
router.push({
await router.push({
path: (redirect as string) || '/',
query: {
...othersQuery,
Expand Down Expand Up @@ -110,13 +111,12 @@ const resetCaptcha = () => {
}
// 获取验证码
const getCaptcha = async () => {
// eslint-disable-next-line unused-imports/no-unused-vars
const getCaptcha = async (captchaReq: BehaviorCaptchaReq) => {
try {
captchaLoading.value = true
captchaBtnName.value = '发送中...'
// await getSmsCaptcha({
// phone: form.phone
// })
// await getSmsCaptcha(form.phone, captchaReq)
captchaLoading.value = false
captchaDisable.value = true
captchaBtnName.value = `获取验证码(${(captchaTime.value -= 1)}s)`
Expand Down

0 comments on commit f140810

Please sign in to comment.