import { Teleport, defineComponent, nextTick, onMounted, reactive, watch } from 'vue'; import styles from './login.module.less'; import loginLogo from './images/login-logo.png'; import { Button, CellGroup, Icon, NumberKeyboard, PasswordInput, showToast } from 'vant'; import request from '@/helpers/request'; import { useRouter } from 'vue-router'; import { storage } from '@/helpers/storage'; import { ACCESS_TOKEN } from '@/store/mutation-types'; import { setLogin } from '@/state'; import MImgCode from '@/components/m-img-code'; export default defineComponent({ name: 'layout-code', props: { phone: { type: String, default: '' }, isRegister: { type: String, default: '' } }, emits: ['close', 'confirm'], setup(props, { emit }) { const router = useRouter(); const forms = reactive({ imgCodeStatus: false, smsCode: '', showKeyboard: false, countDownStatus: true, countDownTime: 120, // 倒计时时间 countTimer: null as any }); // const onSendSms = async () => { // try { // await request.post('/edu-app/open/sendSmsVerify', { // requestType: 'form', // data: { // clientId: 'cooleshow-student', // type: props.isRegister ? 'REGISTER' : 'LOGIN', // mobile: props.phone, // code: '' // } // }); // onCountDown(); // setTimeout(() => { // showToast('验证码已发送'); // }, 100); // } catch { // forms.countDownStatus = true; // } // }; const onCountDown = () => { forms.countDownStatus = false; forms.countTimer = setInterval(() => { if (forms.countDownTime > 0) { forms.countDownTime--; } else { forms.countDownStatus = true; clearInterval(forms.countTimer); } }, 1000); forms.showKeyboard = true; }; const onLogin = async () => { try { const params: any = { username: props.phone, client_id: 'cooleshow-student', client_secret: 'cooleshow-student', password: forms.smsCode, grant_type: 'password', loginType: 'SMS' }; const { data } = await request.post('/edu-app/userlogin', { requestType: 'form', data: { ...params } }); storage.set(ACCESS_TOKEN, data.token_type + ' ' + data.access_token); const userCash = await request.get('/edu-app/user/getUserInfo', { initRequest: true // 初始化接口 }); setLogin(userCash.data); emit('close', true); } catch { // } }; watch( () => forms.smsCode, (val: any) => { if (val && val.length === 6) { onLogin(); } } ); onMounted(() => { nextTick(async () => { forms.imgCodeStatus = true; // await onSendSms(); // forms.showKeyboard = true; }); }); return () => (
emit('close')} />

输入验证码

已发送6位验证码至{props.phone}

{ forms.showKeyboard = true; }} focused={forms.showKeyboard} length={6} gutter={12} /> { forms.showKeyboard = false; }}>
{forms.imgCodeStatus ? ( { forms.imgCodeStatus = false; }} onSendCode={onCountDown} /> ) : null}
); } });