个人中心修改密码后台对接

master
pan 4 years ago
parent 85b0ebf6fe
commit 01e47901fa
  1. 12
      components/account/register.vue
  2. 59
      components/center/security.vue
  3. 8
      nuxt.config.js

@ -6,7 +6,7 @@
<el-form-item :label="$t('account.form.password')" prop="password">
<el-input v-model="form.password" type="password" :placeholder="$t('input_please',{keyword:$t('account.form.password')})"></el-input>
</el-form-item>
<el-form-item class="is-required" :label="$t('account.form.confirmPwd')" prop="confirmPwd">
<el-form-item :label="$t('account.form.confirmPwd')" prop="confirmPwd">
<el-input v-model="form.confirmPwd" type="password" :placeholder="$t('input_confirm',{keyword:$t('account.form.password')})"></el-input>
</el-form-item>
<el-form-item>
@ -42,18 +42,18 @@
message: this.$t('input_please', { keyword: this.$t('account.form.password') })
}],
confirmPwd:[{
required:true,
message: this.$t('input_confirm', { keyword: this.$t('account.form.password') })
},{
validator:(rule, value, callback) => {
if (value === '') {
if (value !== that.form.password) {
callback(new Error(rule.msg.a));
} else if (value !== that.form.password) {
callback(new Error(rule.msg.b));
} else {
callback();
}
},
msg:{
a:this.$t('input_confirm', { keyword: this.$t('account.form.password') }),
b:this.$t('account.form.tip.tow_diff')
a:this.$t('account.form.tip.tow_diff')
}
}]
}

@ -31,6 +31,7 @@
export default Vue.extend({
name: 'security',
data() {
let that = this
return {
form: {
oldpwd: '',
@ -44,7 +45,7 @@
message: this.$t('input_please', { keyword: this.$t('center.security.oldpwd') }),
trigger: 'blur'
},
{ min: 3, max: 5, message: this.$t('center.security.rules.password',{min:3,max:5}), trigger: 'blur' }
{ min: 3, max: 5, message: this.$t('center.security.rules.password', { min: 3, max: 5 }), trigger: 'blur' }
],
newpwd: [
{
@ -52,27 +53,69 @@
message: this.$t('input_please', { keyword: this.$t('center.security.newpwd') }),
trigger: 'blur'
},
{ min: 3, max: 5, message: this.$t('center.security.rules.password',{min:3,max:5}), trigger: 'blur' }
{
validator: (rule, value, callback) => {
if (value === that.form.oldpwd) {
callback(new Error(rule.msg.b))
} else {
callback()
}
},
msg: {
b: this.$t('center.security.tip.same_err')
}
},
{ min: 3, max: 5, message: this.$t('center.security.rules.password', { min: 3, max: 5 }), trigger: 'blur' }
],
confirmpwd: [
{
required: true,
message: this.$t('input_confirm', { keyword: this.$t('center.security.newpwd') }),
trigger: 'blur'
},
{ min: 3, max: 5, message: this.$t('center.security.rules.password',{min:3,max:5}), trigger: 'blur' }
{
validator: (rule, value, callback) => {
if (value !== that.form.newpwd) {
callback(new Error(rule.msg.a))
} else {
callback()
}
},
msg: {
a: this.$t('account.form.tip.tow_diff')
}
},
{ min: 3, max: 5, message: this.$t('center.security.rules.password', { min: 3, max: 5 }), trigger: 'blur' }
]
}
}
},
methods: {
onSubmit() {
this.$refs.form.validate((valid: boolean)=>{
let that=this
this.$refs.form.validate((valid: boolean) => {
if (valid) {
this.$alert(this.$t('center.security.tip.ok').toString())
this.GLOBAL.fetchJSON('/v1/api/users/update','PUT',{
oldpwd:this.form.oldpwd,
newpwd:this.form.newpwd
},function(res) {
if(res.code==='200'){
that.$message.info(that.$t('center.security.tip.ok').toString())
that.$cookies.remove(that.GLOBAL.user_key)
that.$router.push(that.localePath('/account'))
}else if(res.msg!==null){
that.$message.error(res.msg)
}
else{
that.$message.error(that.$t('center.security.tip.fail').toString())
}
})
} else {
console.log('error submit!!');
return false;
this.$message.error({
message:this.$t('form_err').toString(),
duration:2000
})
return false
}
})

@ -142,7 +142,9 @@ export default {
"password": "长度在 {min} 到 {max} 个字符之间"
},
"tip": {
"ok": "密码修改成功"
"fail": "密码修改失败",
"ok": "密码修改成功,请重新登录",
"same_err": "新密码不能和旧密码一致"
}
}
},
@ -307,7 +309,9 @@ export default {
"password": ""
},
"tip": {
"ok": ""
"fail": "",
"ok": "",
"same_err": ""
}
}
},

Loading…
Cancel
Save