给登录界面增加验证码校验

This commit is contained in:
jishenghua
2024-03-05 14:25:38 +08:00
parent 082084313d
commit dc8cab7736
2 changed files with 64 additions and 19 deletions

View File

@@ -23,6 +23,25 @@
</a-input> </a-input>
</a-form-item> </a-form-item>
<a-row :gutter="0">
<a-col :span="14">
<a-form-item>
<a-input
v-decorator="['inputCode']"
size="large"
type="text"
default-value=""
placeholder="请输入验证码">
<a-icon slot="prefix" type="smile" :style="{ color: 'rgba(0,0,0,.25)' }"/>
</a-input>
</a-form-item>
</a-col>
<a-col :span="10" style="text-align: right">
<img v-if="requestCodeSuccess" style="margin-top: 2px;" :src="randCodeImage" @click="handleChangeCheckCode"/>
<img v-else style="margin-top: 2px;" src="../../assets/checkcode.png" @click="handleChangeCheckCode"/>
</a-col>
</a-row>
<a-form-item> <a-form-item>
<a-checkbox :checked="checked" @change="handleChange">记住密码</a-checkbox> <a-checkbox :checked="checked" @change="handleChange">记住密码</a-checkbox>
<router-link v-if="registerFlag==='1'" :to="{ name: 'register'}" class="forge-password" style="float: right;margin-right: 10px;" > <router-link v-if="registerFlag==='1'" :to="{ name: 'register'}" class="forge-password" style="float: right;margin-right: 10px;" >
@@ -30,7 +49,7 @@
</router-link> </router-link>
</a-form-item> </a-form-item>
<a-form-item style="margin-top:30px"> <a-form-item style="margin-top:16px">
<a-button <a-button
size="large" size="large"
type="primary" type="primary"
@@ -103,6 +122,7 @@
currentUsername:"", currentUsername:"",
validate_status:"", validate_status:"",
currdatetime:'', currdatetime:'',
randCode:'',
randCodeImage:'', randCodeImage:'',
registerFlag:'', registerFlag:'',
requestCodeSuccess:false, requestCodeSuccess:false,
@@ -116,6 +136,7 @@
Vue.ls.remove(ACCESS_TOKEN) Vue.ls.remove(ACCESS_TOKEN)
this.getRouterData() this.getRouterData()
this.getRegisterFlag() this.getRegisterFlag()
this.handleChangeCheckCode()
}, },
methods: { methods: {
...mapActions([ "Login", "Logout" ]), ...mapActions([ "Login", "Logout" ]),
@@ -154,30 +175,54 @@
handleChange(e) { handleChange(e) {
this.checked = e.target.checked this.checked = e.target.checked
}, },
handleChangeCheckCode(){
this.currdatetime = new Date().getTime();
getAction(`/user/randomImage/${this.currdatetime}`).then(res=>{
if(res.code == 200){
this.randCode = res.data.codeNum;
this.randCodeImage = res.data.base64;
this.requestCodeSuccess=true
}else{
this.$message.error(res.data)
this.requestCodeSuccess=false
}
}).catch(()=>{
this.requestCodeSuccess=false
})
},
handleSubmit () { handleSubmit () {
let that = this let that = this
let loginParams = {}; let loginParams = {};
that.loginBtn = true; that.loginBtn = true;
// 使用账户密码登陆 // 使用账户密码登陆
if (that.customActiveKey === 'tab1') { if (that.customActiveKey === 'tab1') {
that.form.validateFields([ 'loginName', 'password' ], { force: true }, (err, values) => { that.form.validateFields([ 'loginName', 'password', 'inputCode' ], { force: true }, (err, values) => {
if (!err) { if (!err) {
loginParams.loginName = values.loginName if(values.inputCode === this.randCode) {
loginParams.password = md5(values.password) loginParams.loginName = values.loginName
if(that.checked) { loginParams.password = md5(values.password)
//勾选的时候进行缓存 if(that.checked) {
Vue.ls.set('cache_loginName', values.loginName) //勾选的时候进行缓存
Vue.ls.set('cache_password', values.password) Vue.ls.set('cache_loginName', values.loginName)
Vue.ls.set('cache_password', values.password)
} else {
//没勾选的时候清缓存
Vue.ls.remove('cache_loginName')
Vue.ls.remove('cache_password')
}
that.Login(loginParams).then((res) => {
this.departConfirm(res, loginParams.loginName)
}).catch((err) => {
that.requestFailed(err);
});
} else { } else {
//没勾选的时候清缓存 this.$notification['error']({
Vue.ls.remove('cache_loginName') message: "提示",
Vue.ls.remove('cache_password') description: "验证码错误",
duration: 2
});
this.loginBtn = false
} }
that.Login(loginParams).then((res) => {
this.departConfirm(res, loginParams.loginName)
}).catch((err) => {
that.requestFailed(err);
});
}else { }else {
that.loginBtn = false; that.loginBtn = false;
} }
@@ -374,7 +419,7 @@
} }
.ant-form-item { .ant-form-item {
margin-bottom: 30px; margin-bottom: 16px;
} }
.getCaptcha { .getCaptcha {

View File

@@ -217,7 +217,7 @@
handleSubmit() { handleSubmit() {
this.form.validateFields((err, values) => { this.form.validateFields((err, values) => {
if (!err) { if (!err) {
if(values.inputCode == this.randCode) { if(values.inputCode === this.randCode) {
let register = { let register = {
loginName: values.username, loginName: values.username,
password: md5(values.password) password: md5(values.password)
@@ -306,7 +306,7 @@
.user-layout-register { .user-layout-register {
.ant-form-item { .ant-form-item {
margin-bottom: 18px; margin-bottom: 16px;
} }
& > h3 { & > h3 {