bjang03
2 months ago
3 changed files with 147 additions and 1 deletions
@ -0,0 +1,126 @@ |
|||||
|
<template> |
||||
|
<view class="content passwordpage"> |
||||
|
<uni-forms ref="form" :modelValue="formData" :rules="rules"> |
||||
|
<uni-forms-item label="原密码" name="oldPassword" style="margin: 20rpx 0;"> |
||||
|
<uni-easyinput type="password" v-model="formData.oldPassword" placeholder="请输入原来的密码" /> |
||||
|
</uni-forms-item> |
||||
|
<uni-forms-item label="新密码" name="password" style="border-bottom: 1px solid #eee;"> |
||||
|
<uni-easyinput type="password" v-model="formData.password" placeholder="请输入新密码" /> |
||||
|
</uni-forms-item> |
||||
|
<uni-forms-item label="确认新密码" name="againPassword"> |
||||
|
<uni-easyinput type="password" v-model="formData.againPassword" placeholder="请再次输入密码" /> |
||||
|
</uni-forms-item> |
||||
|
</uni-forms> |
||||
|
<view class="new_btn_bot"> |
||||
|
<button class="new_save_btn" @click="submit">确认修改</button> |
||||
|
</view> |
||||
|
<comMessage ref="comMessage"></comMessage> |
||||
|
</view> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import { loginUpdateUserPwd } from '@/api/request2.js'; |
||||
|
import { |
||||
|
navigateBack, |
||||
|
} from '@/common/basic.js'; |
||||
|
export default { |
||||
|
data() { |
||||
|
return { |
||||
|
// 表单数据 |
||||
|
formData: { |
||||
|
oldPassword: '', |
||||
|
password: '', |
||||
|
againPassword: '' |
||||
|
}, |
||||
|
rules: { |
||||
|
oldPassword: { |
||||
|
rules: [{ |
||||
|
required: true, |
||||
|
errorMessage: '请输入密码', |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
// 对name字段进行必填验证 |
||||
|
password: { |
||||
|
rules: [{ |
||||
|
required: true, |
||||
|
errorMessage: '请输入密码', |
||||
|
}, |
||||
|
{ |
||||
|
minLength: 6, |
||||
|
maxLength: 20, |
||||
|
errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符', |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
// 对email字段进行必填验证 |
||||
|
againPassword: { |
||||
|
rules: [{ |
||||
|
required: true, |
||||
|
errorMessage: '请输入密码', |
||||
|
}, |
||||
|
{ |
||||
|
minLength: 6, |
||||
|
maxLength: 20, |
||||
|
errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符', |
||||
|
}, |
||||
|
{ |
||||
|
validateFunction:function(rule,value,data,callback){ |
||||
|
console.log(value !== data.againPassword) |
||||
|
if (value !== data.againPassword) { |
||||
|
callback('两次输入不同') |
||||
|
} |
||||
|
return true |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
/** |
||||
|
* 复写 binddata 方法,如果只是为了校验,无复杂自定义操作,可忽略此方法 |
||||
|
* @param {String} name 字段名称 |
||||
|
* @param {String} value 表单域的值 |
||||
|
*/ |
||||
|
// binddata(name,value){ |
||||
|
// 通过 input 事件设置表单指定 name 的值 |
||||
|
// this.$refs.form.setValue(name, value) |
||||
|
// }, |
||||
|
// 触发提交表单 |
||||
|
submit() { |
||||
|
this.$refs.form.validate().then(res=>{ |
||||
|
loginUpdateUserPwd(uni.getStorageSync('username'),res.oldPassword,res.password,res.password).then((ress)=>{ |
||||
|
console.log('返回结果:', ress); |
||||
|
if(ress.data){ |
||||
|
this.showCommitSuccessMessage("修改成功") |
||||
|
setTimeout(function (){ |
||||
|
uni.reLaunch({ |
||||
|
url: '../login/index' |
||||
|
}) |
||||
|
},2000) |
||||
|
} |
||||
|
}).catch(err =>{ |
||||
|
this.$refs.comMessage.showErrorMessage(err) |
||||
|
}) |
||||
|
}).catch(err =>{ |
||||
|
console.log('表单错误信息:', err); |
||||
|
}) |
||||
|
}, |
||||
|
showCommitSuccessMessage(hint) { |
||||
|
this.$refs.comMessage.showSuccessMessage(hint, res => { |
||||
|
navigateBack(1) |
||||
|
}) |
||||
|
}, |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style> |
||||
|
.content{ |
||||
|
/* padding: 20rpx; */ |
||||
|
/* background-color: #fff; */ |
||||
|
} |
||||
|
|
||||
|
</style> |
Loading…
Reference in new issue