zhgdyunapp_vue3/pages/my/changePassword/changePassword.vue

247 lines
6.3 KiB
Vue

<template>
<view>
<headers :showBack="true">
<view class="headerName">
修改密码
</view>
</headers>
<view class="userLogin">
<u-form style="width: 100%;" :rules="rules" :error-type="['message']" :model="formData" ref="uForm">
<u-form-item prop="account" class="uni-form-item disabled" :border-bottom="false">
<view>当前账号</view>
<input class="uni-input" name="userInfo" readonly :disabled="true" v-model="userInfo.account"
placeholder="请输入您的账号" />
</u-form-item>
<u-form-item prop="pw" class="uni-form-item" :border-bottom="false">
<view>当前密码</view>
<input class="uni-input" name="pw" v-model="formData.pw" :password="showPassword"
placeholder="请输入您的密码" />
<div class="text-right">
<u-icon :name="showPassword ? 'eye-off' : 'eye-fill'"
@click="showPassword = !showPassword"></u-icon>
</div>
</u-form-item>
<u-form-item prop="newpw" class="uni-form-item" :border-bottom="false">
<view>新密码</view>
<input class="uni-input" name="newpw" :password="showPassword1" v-model="formData.newpw"
placeholder="请输入新密码" />
<div class="text-right">
<u-icon :name="showPassword1 ? 'eye-off' : 'eye-fill'"
@click="showPassword1 = !showPassword1"></u-icon>
</div>
</u-form-item>
<u-form-item prop="newpwaff" class="uni-form-item" :border-bottom="false">
<view>确认新密码</view>
<input class="uni-input" name="newpwaff" :password="showPassword2" v-model="formData.newpwaff"
placeholder="请输入再次新密码" />
<div class="text-right">
<u-icon :name="showPassword2 ? 'eye-off' : 'eye-fill'"
@click="showPassword2 = !showPassword2"></u-icon>
</div>
</u-form-item>
<!-- <u-form-item prop="email" class="uni-form-item" :border-bottom="false">
<image class="icon" mode="widthFix" src="@/static/login/email.png"></image>
<input class="uni-input" type="email" name="email" v-model="formData.email" placeholder="请输入您的电子邮箱" />
</u-form-item> -->
<view class="uni-form-item submit">
<button type="primary" class="btn" @click="formSubmit">完成</button>
</view>
</u-form>
</view>
</view>
</template>
<script>
import headers from '../../../components/headers/headers.vue';
import {
exitApp
} from "@/utils/tool.js"
export default {
components: {
headers
},
data() {
return {
showPassword: true,
showPassword1: true,
showPassword2: true,
userInfo: {},
formData: {
account: '',
pw: '',
newpw: "",
newpwaff: "",
email: ''
},
rules: {
pw: [{
required: true,
message: '请输入密码',
trigger: ['change', 'blur'],
},
{
pattern: /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&*()_+~`\-={}[\]:";'<>?,./])[a-zA-Z\d!@#$%^&*()_+~`\-={}[\]:";'<>?,./]{8,}$/,
// 正则检验前先将值转为字符串
transform(value) {
return String(value);
},
message: '密码必须包含至少一个字母、一个数字、一个特殊字符以及长度至少为8位数'
}
],
newpw: [{
required: true,
message: '请输入密码',
trigger: ['change', 'blur'],
},
{
pattern: /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&*()_+~`\-={}[\]:";'<>?,./])[a-zA-Z\d!@#$%^&*()_+~`\-={}[\]:";'<>?,./]{8,}$/,
// 正则检验前先将值转为字符串
transform: (value) => {
return String(value);
},
message: '密码必须包含至少一个字母、一个数字、一个特殊字符以及长度至少为8位数'
}
],
newpwaff: [{
required: true,
message: '请输入密码',
trigger: ['change', 'blur'],
}, {
pattern: /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&*()_+~`\-={}[\]:";'<>?,./])[a-zA-Z\d!@#$%^&*()_+~`\-={}[\]:";'<>?,./]{8,}$/,
// 正则检验前先将值转为字符串
transform: (value) => {
// console.log(value,this.formData);
if (value != this.formData.newpw) {
return false
}
return String(value);
},
message: '两次密码不一致'
}],
email: [{
required: true,
message: '请输入邮箱',
trigger: ['change', 'blur'],
},
{
type: "email",
required: true,
message: '邮箱格式错误',
trigger: ['change', 'blur'],
}
],
}
};
},
onLoad(option) {
console.log(option)
this.userInfo = option.userInfo ? JSON.parse(option.userInfo) : JSON.parse(uni.getStorageSync('userInfo'));
},
onReady() {
this.$refs.uForm.setRules(this.rules);
},
methods: {
formSubmit() {
// 表单验证 -> 下一步
this.$refs.uForm.validate(valid => {
if (valid) {
// 修改密码
this.sendRequest({
url: "xmgl/systemUser/xz/updatePw",
header: {
Authorization: "Bearer " + this.userInfo.token
},
data: {
userId: this.userInfo.userId,
oldPassword: this.formData.pw,
showPassword: this.formData.newpwaff,
isCheckCode: 0
},
method: "POST",
success: (res) => {
console.log(res);
if (res.code == 200) {
uni.showToast({
title: '修改成功!'
})
setTimeout(() => {
this.logout();
}, 1000)
}
}
})
}
});
},
logout() {
this.sendRequest({
url: "xmgl/base/logout",
data: {
id: this.userInfo.userId
},
method: "POST",
success() {
exitApp()
},
fail() {
exitApp()
}
})
}
}
}
</script>
<style lang="scss" scoped>
.text-right {
flex: 1;
text-align: right;
}
.userLogin {
padding: 30rpx;
.uni-form-item.disabled {
color: #707070;
}
.uni-form-item {
display: flex;
padding: 20rpx 10rpx;
width: 100%;
// border-bottom: 1rpx solid #ddd;
&.submit {
border: none;
margin-top: 80rpx;
padding-left: 48rpx;
padding-right: 48rpx;
.btn {
background-color: #2D8EF3;
}
}
:deep( .u-form-item__message ){
line-height: 32rpx;
}
.icon {
width: 40rpx;
height: auto;
margin: auto 0;
}
.uni-input {
width: 70%;
padding: 15rpx;
}
.btn {
font-size: 32rpx;
width: 100%;
}
}
}
</style>