import { defineComponent } from "vue"; import { CellGroup, Field, Button, CountDown } from "vant"; import ImgCode from "@/components/imgCode"; import request from "@/helpers/request"; import { setLogin, state } from "@/student/state"; import { removeAuth, setAuth } from "@/helpers/utils"; import styles from "./login.module.less"; type loginType = 'PWD' | 'SMS'; export default defineComponent({ name: 'login', data() { return { loginType: 'SMS' as loginType, username: '', password: '', smsCode: '', countDownStatus: true, // 是否发送验证码 countDownTime: 1000 * 120, // 倒计时时间 countDownRef: null as any, // 倒计时实例 imgCodeStatus: false, } }, computed: { codeDisable() { let status = true; if (this.loginType === 'PWD') { this.username && this.password && (status = false); } else { this.username && this.smsCode && (status = false); } return status; }, }, mounted() { removeAuth(); this.directNext(); }, methods: { directNext() { if (state.user.status === "login" || state.user.status === "error") { const { returnUrl, isRegister, ...rest } = this.$route.query; this.$router.replace({ path: returnUrl as any, query: { ...rest, }, }); } }, async onLogin() { try { let res: any; if(this.loginType === 'PWD') { res = await request.post('/api-auth/usernameLogin', { data: { username: this.username, password: this.password, clientId: 'student', clientSecret: 'student' } }); } else { res = await request.post('/api-auth/smsLogin', { data: { clientId: 'student', clientSecret: 'student', phone: this.username, smsCode: this.smsCode, channel: 'H5' } }); } const { authentication } = res.data; setAuth(authentication.token_type + " " + authentication.access_token); let userCash = await request.get('/api-student/userCashAccount/get', { initRequest: true // 初始化接口 }) setLogin(userCash.data) this.directNext(); } catch{ } }, async onSendCode() { // 发送验证码 // if(!checkPhone(this.phoneNumber)) { // return // } this.imgCodeStatus = true }, onCodeSend() { this.countDownStatus = false; this.countDownRef.start(); }, onFinished() { this.countDownStatus = true; this.countDownRef.reset(); }, onChange() { if(this.loginType === 'PWD') { this.loginType = 'SMS' } else if(this.loginType === 'SMS') { this.loginType = 'PWD' } }, }, render() { return (
您好,
欢迎使用酷乐秀
{ this.loginType === 'PWD' ? : ( this.countDownStatus ? : ) }} /> }
{ this.imgCodeStatus ? { this.imgCodeStatus = false }} onSendCode={this.onCodeSend} /> : null }
) } })