...
|
...
|
@@ -16,6 +16,9 @@ |
|
|
<Icon type="ios-locked-outline" slot="prepend"></Icon>
|
|
|
</Input>
|
|
|
</Form-item>
|
|
|
<Form-item>
|
|
|
<captcha v-if="isCaptcha" @change="captchaChange"></captcha>
|
|
|
</Form-item>
|
|
|
<Form-item class="login-btn">
|
|
|
<Button type="primary" :loading="loading" @click="handleSubmit('formInline')">
|
|
|
登录
|
...
|
...
|
@@ -29,47 +32,65 @@ |
|
|
|
|
|
<script>
|
|
|
import Vue from 'vue';
|
|
|
import _ from 'lodash';
|
|
|
import {Captcha} from './components';
|
|
|
|
|
|
export default {
|
|
|
name: 'login',
|
|
|
data() {
|
|
|
return {
|
|
|
loading: false,
|
|
|
isCaptcha: false,
|
|
|
captcha: '',
|
|
|
formInline: {
|
|
|
user: '',
|
|
|
password: ''
|
|
|
},
|
|
|
ruleInline: {
|
|
|
user: [
|
|
|
{ required: true, message: '请填写用户名', trigger: 'blur' }
|
|
|
],
|
|
|
password: [
|
|
|
{ required: true, message: '请填写密码', trigger: 'blur' },
|
|
|
{ type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
|
|
|
]
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
created() {
|
|
|
this.isCaptcha = this.$cookie.get('_captcha');
|
|
|
},
|
|
|
methods: {
|
|
|
handleSubmit(name) {
|
|
|
this.$refs[name].validate((valid) => {
|
|
|
if (valid) {
|
|
|
this.login(this.formInline.user, this.formInline.password);
|
|
|
if (this.isCaptcha && !this.captcha) {
|
|
|
this.$Message.error('请将图形验证码翻转至正确方向');
|
|
|
return;
|
|
|
}
|
|
|
this.login(this.formInline.user, this.formInline.password, this.captcha);
|
|
|
} else {
|
|
|
this.$Message.error('表单验证失败!');
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
login(username, password) {
|
|
|
captchaChange(vals) {
|
|
|
this.captcha = _.join(vals, '');
|
|
|
},
|
|
|
login(username, password, captcha) {
|
|
|
this.loading = true;
|
|
|
Vue.passport.local(username, password).then(() => {
|
|
|
Vue.passport.local(username, password, captcha).then(() => {
|
|
|
this.loading = false;
|
|
|
this.$router.push('/');
|
|
|
}, (error) => {
|
|
|
this.isCaptcha = error.captcha;
|
|
|
this.loading = false;
|
|
|
this.$Message.error(error.message);
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
loading: false,
|
|
|
formInline: {
|
|
|
user: '',
|
|
|
password: ''
|
|
|
},
|
|
|
ruleInline: {
|
|
|
user: [
|
|
|
{ required: true, message: '请填写用户名', trigger: 'blur' }
|
|
|
],
|
|
|
password: [
|
|
|
{ required: true, message: '请填写密码', trigger: 'blur' },
|
|
|
{ type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
|
|
|
]
|
|
|
}
|
|
|
};
|
|
|
components: {
|
|
|
Captcha
|
|
|
}
|
|
|
};
|
|
|
</script>
|
...
|
...
|
@@ -104,10 +125,16 @@ export default { |
|
|
|
|
|
.login-btn {
|
|
|
text-align: right;
|
|
|
|
|
|
button {
|
|
|
width: 100%;
|
|
|
height: 36px;
|
|
|
font-size: 14px;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
.login-card {
|
|
|
height: 250px;
|
|
|
min-height: 250px;
|
|
|
}
|
|
|
}
|
|
|
</style> |
...
|
...
|
|