zhengyiming
2 天以前 64eb1c2ebfc25f11f5757a0eef04de230fa8fa15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<template>
  <ProForm :model="form" ref="formRef" class="el-message-box__input">
    <ProFormItemV2
      prop="code"
      :check-rules="[{ message: '请输入验证码' }]"
      label-width="0px"
      class="pro-form-item-label-hidden"
    >
      <ProFormText v-model.trim="form.code" placeholder="请输入验证码">
        <template #suffix>
          <ProFormCaptcha
            :onGetCaptcha="onGetCaptcha"
            phonePropName="loginKey"
            class="code-btn"
            link
          ></ProFormCaptcha>
        </template>
      </ProFormText>
    </ProFormItemV2>
    <div class="el-message-box__btns" style="padding-top: 0">
      <el-button type="primary" @click="handleConfirm" :loading="loading">确定</el-button>
    </div>
  </ProForm>
</template>
 
<script setup lang="ts">
import { ProForm, ProFormText, ProFormCaptcha, ProFormItemV2 } from '@bole-core/components';
import { FormInstance } from 'element-plus';
import * as accountServices from '@/services/api/Account';
import { useUserStore } from '@/store/modules/user';
 
defineOptions({
  name: 'SendVerificationCodeView',
});
 
type Props = {
  /** 登录密钥 */
  loginKey?: string;
  /** 手机号 */
  phoneNumber?: string;
};
 
const props = withDefaults(defineProps<Props>(), {});
 
const emit = defineEmits<{
  (e: 'success'): void;
}>();
 
const form = reactive({
  loginKey: props.loginKey,
  code: '',
});
 
const loading = ref(false);
 
async function onGetCaptcha() {
  await accountServices.twoFactorLoginSendVerificationCode(
    {
      loginKey: props.loginKey,
    },
    { showLoading: false }
  );
}
 
const formRef = ref<FormInstance>();
 
const handleConfirm = () => {
  if (!formRef.value) return;
  formRef.value.validate((valid) => {
    if (valid) {
      twoFactorLoginSms();
    } else {
      return;
    }
  });
};
 
const userStore = useUserStore();
 
async function twoFactorLoginSms() {
  try {
    loading.value = true;
    await userStore.twoFactorLoginSms({
      loginKey: props.loginKey,
      code: form.code,
    });
    emit('success');
  } catch (error) {
  } finally {
    loading.value = false;
  }
}
</script>
 
<style lang="scss" scoped>
@use '@/style/common.scss' as *;
</style>