Browse Source

登录校验密码是否符合密码策略,不符合则修改密码

hella_online_20241011
bjang03 2 months ago
parent
commit
ed92c7c78f
  1. 15
      src/api/request2.js
  2. 7
      src/pages.json
  3. 126
      src/pages/setter/loginPwdUpdate.vue

15
src/api/request2.js

@ -81,6 +81,7 @@ export function getUserProfile() {
method: 'get'
})
}
/**
* 修改个人用户密码
*/
@ -95,7 +96,19 @@ export function updateUserPwd(oldPassword, newPassword) {
data: data
})
}
export function loginUpdateUserPwd(userName,oldPassword, password,againPassword) {
const data = {
userName,
oldPassword,
password,
againPassword
}
return request({
url: baseApi + '/system/user/updatePassword',
method: 'PUT',
data: data
})
}
/**
* 获取仓库代码
* @param {*}

7
src/pages.json

@ -156,6 +156,13 @@
"enablePullDownRefresh": false
}
},
{
"path": "pages/setter/loginPwdUpdate",
"style": {
"navigationBarTitleText": "修改密码",
"enablePullDownRefresh": false
}
},
{
"path": "pages/supplierDeliver/record/supplierDeliverRecord",
"style": {

126
src/pages/setter/loginPwdUpdate.vue

@ -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…
Cancel
Save