|
@@ -3,13 +3,25 @@
|
|
|
<div class="logo">
|
|
|
<img src="../../assets/images/logo.png" alt="">
|
|
|
</div>
|
|
|
+ <div class="container" v-show="isTrue">
|
|
|
+ <div class="input-group">
|
|
|
+ <input type="number" @keyup="onKeyUp()" placeholder="请输入手机号" class="input" v-model="phoneNumber" pattern="[0-9]" />
|
|
|
+ </div>
|
|
|
+ <div class="input-group">
|
|
|
+ <input type="password" @keyup="onKeyUp()" placeholder="请输入密码" class="input" v-model="password" />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <van-button round size="large" @click="onLogin" :disabled="pwdDisable">登录</van-button>
|
|
|
+ <span class="login-change" @click="isTrue = false">验证码登录</span>
|
|
|
+ <span class="login-change" @click="onRegister" style="float: left;">立即注册</span>
|
|
|
+ </div>
|
|
|
|
|
|
- <div class="container">
|
|
|
+ <div class="container" v-show="!isTrue">
|
|
|
<div class="input-group">
|
|
|
- <input type="number" @blur="codeBlur" placeholder="请输入手机号" class="input" v-model="phoneNumber" pattern="[0-9]">
|
|
|
+ <input type="number" @keyup="onKeyUp()" placeholder="请输入手机号" class="input" v-model="phoneNumber" pattern="[0-9]">
|
|
|
</div>
|
|
|
<div class="input-group">
|
|
|
- <input type="text" @blur="codeBlur" placeholder="请输入验证码" class="input" v-model="code" >
|
|
|
+ <input type="text" @keyup="onKeyUp()" placeholder="请输入验证码" class="input" v-model="code" >
|
|
|
<span class="code-text" v-show="countDownStatus" @click="onSendCode">{{ codeText }}</span>
|
|
|
<span class="code-text" v-show="!countDownStatus">
|
|
|
<van-count-down
|
|
@@ -22,20 +34,25 @@
|
|
|
</div>
|
|
|
|
|
|
<van-button round size="large" @click="onCodeLogin" :disabled="codeDisable">登录</van-button>
|
|
|
+ <span class="login-change" @click="isTrue = true">密码登录</span>
|
|
|
+ <span class="login-change" @click="onRegister" style="float: left;">立即注册</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import {sendSms, smsLogin, queryUserByPhone } from '@/api/app'
|
|
|
+/* eslint-disable */
|
|
|
+import { usernameLogin, sendSms, verifySmsCode, smsLogin, queryUserByPhone } from '@/api/app'
|
|
|
export default {
|
|
|
name: 'login',
|
|
|
data() {
|
|
|
return {
|
|
|
groupId: this.$route.query.groupId,
|
|
|
+ pwdDisable: true, // 密码登录按钮状态
|
|
|
codeDisable: true, // 验证码登录按钮状态
|
|
|
+ isTrue: true,
|
|
|
countDownStatus: true, // 到计时状态
|
|
|
phoneNumber: null,
|
|
|
- isRegister: 0, // 默认没有注册
|
|
|
+ password: null,
|
|
|
code: null,
|
|
|
codeText: '获取验证码',
|
|
|
countDownTime: 1000 * 120, // 倒计时时间
|
|
@@ -46,29 +63,33 @@ export default {
|
|
|
// 登录时删除无用的token
|
|
|
localStorage.removeItem('userInfo')
|
|
|
localStorage.removeItem('Authorization')
|
|
|
- },
|
|
|
- watch: {
|
|
|
- phoneNumber(newValue) {
|
|
|
- this.onKeyUp(newValue, this.code)
|
|
|
- },
|
|
|
- code(newValue) {
|
|
|
- this.onKeyUp(this.phoneNumber, newValue)
|
|
|
- }
|
|
|
+ // 登录时间判断用户是Token是否有效
|
|
|
+
|
|
|
},
|
|
|
methods: {
|
|
|
- codeBlur() {
|
|
|
- setTimeout(() => {
|
|
|
- const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
|
|
|
- window.scrollTo(0, Math.max(scrollHeight - 1, 0));
|
|
|
- }, 100);
|
|
|
- },
|
|
|
- onKeyUp(phoneNumber, code) {
|
|
|
- if(!phoneNumber || !code) {
|
|
|
- this.codeDisable = true
|
|
|
+ onKeyUp() {
|
|
|
+ if(this.isTrue) {
|
|
|
+ if(!this.phoneNumber || !this.password) {
|
|
|
+ this.pwdDisable = true
|
|
|
+ } else {
|
|
|
+ this.pwdDisable = false
|
|
|
+ }
|
|
|
} else {
|
|
|
- this.codeDisable = false
|
|
|
+ if(!this.phoneNumber || !this.code) {
|
|
|
+ this.codeDisable = true
|
|
|
+ } else {
|
|
|
+ this.codeDisable = false
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
+ onRegister() {
|
|
|
+ this.$router.push({
|
|
|
+ path: '/appRegister',
|
|
|
+ query: {
|
|
|
+ groupId: this.groupId
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
onSendCode() { // 发送验证码
|
|
|
if(!this.checkPhone(this.phoneNumber)) {
|
|
|
return
|
|
@@ -84,23 +105,13 @@ export default {
|
|
|
} else {
|
|
|
this.$toast(result.msg)
|
|
|
}
|
|
|
- })
|
|
|
+ })
|
|
|
},
|
|
|
onCodeLogin() { // 短信登录
|
|
|
if(this.isClick) {
|
|
|
return
|
|
|
}
|
|
|
this.isClick = true
|
|
|
- queryUserByPhone({ mobile: this.phoneNumber }).then(res => {
|
|
|
- let result = res.data
|
|
|
- if(result.code == 200) {
|
|
|
- this.isRegister = result.data
|
|
|
- }
|
|
|
- this.onLogin()
|
|
|
- })
|
|
|
-
|
|
|
- },
|
|
|
- onLogin() {
|
|
|
let params = {
|
|
|
clientId: 'student',
|
|
|
clientSecret: 'student',
|
|
@@ -108,9 +119,6 @@ export default {
|
|
|
smsCode: this.code,
|
|
|
channel: 'H5'
|
|
|
}
|
|
|
- if(this.isRegister == 0) {
|
|
|
- params.isLessee = 'true'
|
|
|
- }
|
|
|
smsLogin(params).then(sms => {
|
|
|
let s = sms.data
|
|
|
this.isClick = false
|
|
@@ -119,6 +127,66 @@ export default {
|
|
|
let auth = s.data.authentication
|
|
|
localStorage.setItem('userInfo', auth.token_type + ' ' + auth.access_token)
|
|
|
|
|
|
+ if(s.password) {
|
|
|
+ this.$router.push({
|
|
|
+ path: '/classDetail',
|
|
|
+ query: {
|
|
|
+ groupId: this.groupId
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.$router.push({
|
|
|
+ path: '/appSetInfo',
|
|
|
+ query: {
|
|
|
+ groupId: this.groupId
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$toast(s.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // queryUserByPhone({ mobile: this.phoneNumber }).then(res => {
|
|
|
+ // let result = res.data
|
|
|
+ // if(result.code == 200) {
|
|
|
+ // this.isRegister = result.data
|
|
|
+ // }
|
|
|
+ // if(this.isRegister == 1) {
|
|
|
+ // this.onLoginStr()
|
|
|
+ // } else {
|
|
|
+ // this.$dialog.confirm({
|
|
|
+ // message: '此手机号尚未注册<br/>是否注册?',
|
|
|
+ // confirmButtonText: '注册'
|
|
|
+ // }).then(() => {
|
|
|
+ // this.$router.push({
|
|
|
+ // path: '/appRegister',
|
|
|
+ // query: {
|
|
|
+ // groupId: this.groupId
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // }).catch(() => { });
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ },
|
|
|
+ onLogin() { // 账号登录
|
|
|
+ if(this.isClick) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.isClick = true
|
|
|
+
|
|
|
+ usernameLogin({
|
|
|
+ clientId: 'student',
|
|
|
+ clientSecret: 'student',
|
|
|
+ username: this.phoneNumber,
|
|
|
+ password: this.password
|
|
|
+ }).then(sms => {
|
|
|
+ let s = sms.data
|
|
|
+ this.isClick = false
|
|
|
+ // 保存用户信息
|
|
|
+ if(s.code == 200) {
|
|
|
+ let auth = s.data.authentication
|
|
|
+ localStorage.setItem('userInfo', auth.token_type + ' ' + auth.access_token)
|
|
|
+
|
|
|
this.$router.push({
|
|
|
path: '/classDetail',
|
|
|
query: {
|