|
|
@@ -1,16 +1,22 @@
|
|
|
<template>
|
|
|
<div class="page-container login-container">
|
|
|
- <el-card class="login-card">
|
|
|
- <h2 class="login-card__title login-card__item">登 录</h2>
|
|
|
- <el-input v-model="phone" placeholder="请输入手机号" class="login-card__item"></el-input>
|
|
|
- <el-input v-model="password" placeholder="请输入密码" class="login-card__item"></el-input>
|
|
|
- <el-input v-model="password" placeholder="请输入验证码" class="login-card__short-item"></el-input>
|
|
|
- <div class="login-card__canvas" @click="refreshCode">
|
|
|
- <SIdentify :identifyCode="identifyCode"></SIdentify>
|
|
|
- </div>
|
|
|
- <el-button type="primary" class="login-card__item" round>登 录</el-button>
|
|
|
- <div class="login-card__link"><router-link to="/register">立即注册</router-link></div>
|
|
|
- </el-card>
|
|
|
+ <el-card class="login-card">
|
|
|
+ <h2 class="login-card__title login-card__item">登 录</h2>
|
|
|
+ <el-input v-model="phone" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入手机号" minlength='11' maxlength='11' class="login-card__item"></el-input>
|
|
|
+ <el-input v-model="password" placeholder="请输入密码" maxlength="20" class="login-card__item"></el-input>
|
|
|
+ <el-input v-model="iCode" placeholder="请输入验证码" class="login-card__short-item"></el-input>
|
|
|
+
|
|
|
+ <div class="login-card__canvas" @click="refreshCode" ref="canvas">
|
|
|
+ <SIdentify :identifyCode="identifyCode" :contentWidth="canvasWidth"></SIdentify>
|
|
|
+ </div>
|
|
|
+ <div class="login-card__item">
|
|
|
+ <el-checkbox v-model="rememberPassword"></el-checkbox> 记住密码
|
|
|
+ <router-link to="/resetPassword" class="login-card__right-link">找回密码</router-link>
|
|
|
+ </div>
|
|
|
+ <el-button type="primary" class="login-card__item" :loading="loading" round>登 录</el-button>
|
|
|
+ <div class="login-card__bottom"><router-link to="/register" class="login-card__link">立即注册</router-link></div>
|
|
|
+ </el-card>
|
|
|
+ <div class="clear"></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -25,7 +31,11 @@
|
|
|
phone: '',
|
|
|
password: '',
|
|
|
identifyCodes: ['0','1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
|
|
- identifyCode: ''
|
|
|
+ identifyCode: '',
|
|
|
+ iCode: '',
|
|
|
+ rememberPassword: false,
|
|
|
+ loading: false,
|
|
|
+ canvasWidth: 0,
|
|
|
}
|
|
|
},
|
|
|
components: {
|
|
|
@@ -34,6 +44,16 @@
|
|
|
mounted(){
|
|
|
this.identifyCode = "";
|
|
|
this.makeCode(this.identifyCodes, 4);
|
|
|
+ this.canvasWidth = this.$refs.canvas.clientWidth;
|
|
|
+ if(localStorage.phone){
|
|
|
+ localStorage.phone = this.phone;
|
|
|
+ }
|
|
|
+ if(localStorage.password){
|
|
|
+ localStorage.password = this.password;
|
|
|
+ }
|
|
|
+ if(localStorage.rememberPassword){
|
|
|
+ localStorage.rememberPassword = this.rememberPassword;
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
randomNum(min, max) {
|
|
|
@@ -51,22 +71,34 @@
|
|
|
}
|
|
|
},
|
|
|
login() {
|
|
|
+ this.loading = true;
|
|
|
this.$api.$post('/user/login', {
|
|
|
phone: this.phone,
|
|
|
password: this.password
|
|
|
}).then((res) =>
|
|
|
{
|
|
|
if(res.code === 0){
|
|
|
- console.log(JSON.stringify(res.data));
|
|
|
+ localStorage.phone=this.phone;
|
|
|
+ if(this.rememberPassword){
|
|
|
+ localStorage.password = this.password;
|
|
|
+ localStorage.rememberPassword = this.rememberPassword;
|
|
|
+ }else{
|
|
|
+ localStorage.removeItem("password");
|
|
|
+ }
|
|
|
+
|
|
|
this.$store.commit("saveUser", res.data.user);
|
|
|
this.$store.commit("saveToken", res.data.token);
|
|
|
- console.log(this.$store.state.token, this.$store.state.user);
|
|
|
}else{
|
|
|
- console.log(res.message);
|
|
|
+ this.$message({
|
|
|
+ showClose: true,
|
|
|
+ message: res.message,
|
|
|
+ type: 'error'
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- )
|
|
|
+ );
|
|
|
+ this.loading = false;
|
|
|
},
|
|
|
}
|
|
|
};
|