diff --git a/components/account/register.vue b/components/account/register.vue index 80ca01b..690478a 100644 --- a/components/account/register.vue +++ b/components/account/register.vue @@ -6,7 +6,7 @@ - + @@ -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') } }] } diff --git a/components/center/security.vue b/components/center/security.vue index f7a9268..cd904f9 100644 --- a/components/center/security.vue +++ b/components/center/security.vue @@ -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 } }) diff --git a/nuxt.config.js b/nuxt.config.js index ab627a4..2fa8b4e 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -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": "" } } },