import { defineComponent, onMounted, reactive, ref } from 'vue'; import styles from './sendSms.module.less'; import smsTop from '../images/sms-top.png'; import closeAble from '../images/closeAble.png'; import { NButton, NForm, NFormItem, NGi, NGrid, NImage, NInput, NSpace } from 'naive-ui'; import { sendImgCode, sendSmsVerify } from '../api'; export default defineComponent({ name: 'sendSms', props: { phone: { type: String, default: '' }, clientId: { type: String, default: 'cooleshow-teacher' }, type: { type: String, default: 'LOGIN' } }, emits: ['close', 'sendCode'], setup(props, { emit }) { const state = reactive({ identifyingCode: null as any, code: null as any }); const formRef = ref(); const getSendImgCode = async () => { const { data } = await sendImgCode({ phone: props.phone }); state.identifyingCode = data; }; const onSubmit = async () => { formRef.value.validate(async (errors: any) => { if (errors) return; try { await sendSmsVerify({ code: state.code, clientId: props.clientId, type: props.type, mobile: props.phone }); emit('close'); emit('sendCode'); } catch { state.code = ''; setTimeout(() => { getSendImgCode(); }, 500); } }); }; onMounted(() => { getSendImgCode(); }); return () => (