|
|
@@ -9,6 +9,10 @@
|
|
|
<el-form-item prop="password" :rules="{required: true, message: '请输入密码', trigger: 'blur'}">
|
|
|
<el-input v-model="userInfo.password" placeholder="密码" type="password"></el-input>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item prop="code" :rules="CodeRule">
|
|
|
+ <el-input v-model="userInfo.code" placeholder="验证码" style="width:210px"></el-input>
|
|
|
+ <img @click="randomString" style="widdth:108px;height:39px;vertical-align: middle;margin-left:30px;cursor: pointer;" :src="$baseUrl+'/auth/image?'+autoString" alt>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="记住我">
|
|
|
<el-switch v-model="rememberMe"></el-switch>
|
|
|
</el-form-item>
|
|
|
@@ -28,11 +32,45 @@ export default {
|
|
|
loading: false,
|
|
|
userInfo: {
|
|
|
username: '',
|
|
|
- password: ''
|
|
|
- }
|
|
|
+ password: '',
|
|
|
+ code: ''
|
|
|
+ },
|
|
|
+ CodeRule: [
|
|
|
+ { required: true, message: '请输入图片验证码', trigger: 'blur' },
|
|
|
+ {
|
|
|
+ validator: (rule, value, callback) => {
|
|
|
+ if (!value) {
|
|
|
+ callback(new Error('请输入图片验证码'));
|
|
|
+ } else {
|
|
|
+ this.$http.get({
|
|
|
+ url: '/auth/verify',
|
|
|
+ data: {
|
|
|
+ code: value,
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ callback();
|
|
|
+ } else {
|
|
|
+ callback(new Error('验证码错误'));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, trigger: 'blur'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ autoString: ''
|
|
|
}
|
|
|
},
|
|
|
+ created() {
|
|
|
+ this.randomString()
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ randomString(len) {
|
|
|
+ var pwd = Math.random().toString(36).substr(2);
|
|
|
+
|
|
|
+ console.log(pwd)
|
|
|
+ this.autoString = pwd
|
|
|
+ },
|
|
|
login() {
|
|
|
this.$store.commit('updateLoginHistory', [{
|
|
|
name: '/dashboard',
|
|
|
@@ -54,23 +92,24 @@ export default {
|
|
|
this.$router.replace('/');
|
|
|
} else {
|
|
|
this.$message.error('登录失败');
|
|
|
+ this.randomString()
|
|
|
}
|
|
|
}).catch(() => {
|
|
|
this.loading = false;
|
|
|
})
|
|
|
|
|
|
this.$http.post({
|
|
|
- url: this.$handleDomain+'/auth/login',
|
|
|
+ url: this.$handleDomain + '/auth/login',
|
|
|
data: {
|
|
|
username: this.userInfo.username,
|
|
|
password: this.userInfo.password,
|
|
|
remember: this.rememberMe,
|
|
|
- requireToken:true
|
|
|
+ requireToken: true
|
|
|
}
|
|
|
}).then(res => {
|
|
|
- if(res.success){
|
|
|
- this.$store.commit('updateToken',res.token)
|
|
|
- }
|
|
|
+ if (res.success) {
|
|
|
+ this.$store.commit('updateToken', res.token)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
})
|