import { defineComponent } from 'vue'; import { CellGroup, Field, Button, showToast } from 'vant'; import request from '@/helpers/request'; import { setLogin, state } from '@/state'; import { checkPhone } from '@/helpers/utils'; import loginLogo from './images/login-logo.png'; import iconPhone from './images/icon-phone.png'; import iconPassword from './images/icon-password.png'; import { storage } from '@/helpers/storage'; import { ACCESS_TOKEN } from '@/store/mutation-types'; import styles from './login.module.less'; import MPopup from '@/components/m-popup'; import Code from './code'; import router from '@/router'; type loginType = 'PWD' | 'SMS'; export default defineComponent({ name: 'layout-login', data() { const { isRegister } = this.$route.query; return { isRegister: isRegister as any, loginType: 'SMS' as loginType, username: '', password: '', smsCode: '', countDownStatus: true, // 是否发送验证码 countDownTime: 1000 * 120, // 倒计时时间 imgCodeStatus: false, isAgree: true }; }, mounted() { storage.remove(ACCESS_TOKEN); this.directNext(); }, methods: { directNext() { if (state.user.status === 'login' || state.user.status === 'error') { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { returnUrl, isRegister, ...rest } = this.$route.query; console.log("🚀 ~ this.$route.query:", this.$route.query) this.$router.replace({ path: returnUrl as any, query: { ...rest } }); } }, async onLogin() { try { if (!checkPhone(this.username)) { return showToast('请输入正确的手机号码'); } const forms: any = { username: this.username, client_id: 'cooleshow-student', client_secret: 'cooleshow-student', password: this.loginType === 'PWD' ? this.password : this.smsCode, grant_type: 'password', loginType: this.loginType === 'PWD' ? 'PASSWORD' : 'SMS' }; const { data } = await request.post('/edu-oauth/userlogin', { requestType: 'form', data: { ...forms } }); storage.set(ACCESS_TOKEN, data.token_type + ' ' + data.access_token); const userCash = await request.get('/edu-app/user/getUserInfo', { initRequest: true // 初始化接口 }); setLogin(userCash.data); this.directNext(); } catch (e: any) { // console.log(e); } }, async onSendCode() { // 发送验证码 if (!this.isAgree) { return showToast('请阅读并同意以下协议'); } if (!checkPhone(this.username)) { return showToast('请输入正确的手机号码'); } this.imgCodeStatus = true; }, onChange() { if (this.loginType === 'PWD') { this.loginType = 'SMS'; } else if (this.loginType === 'SMS') { this.loginType = 'PWD'; } } }, render() { return (
{
this.imgCodeStatus = false
if (val) {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
this.directNext()
})
})
}
}}
onConfirm={this.directNext}
/>