SmartStorage/pages/fixPwd/fixPwd.vue

134 lines
3.1 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<view class="form-area">
<uni-forms
ref="pwdForm"
:modelValue="pwdFormData"
:rules="pwdFormRules"
label-position="top"
>
<uni-forms-item name="oldPassword" required label="旧密码" label-width="100">
<uni-easyinput type="password" placeholder="请输入" maxlength="60"
v-model="pwdFormData.oldPassword"></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="newPassword" required label="新密码(最少8位包括至少1个大写字母1个小写字母1个数字1个特殊字符)" label-width="100">
<uni-easyinput type="password" placeholder="请输入" maxlength="60"
v-model="pwdFormData.newPassword"></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="confirmNewPassword" required label="确认新密码" label-width="100">
<uni-easyinput type="password" placeholder="请输入" maxlength="60"
v-model="pwdFormData.confirmNewPassword"></uni-easyinput>
</uni-forms-item>
<view
class="sub-btn"
@click="submitForm"
>
保存
</view>
</uni-forms>
</view>
</view>
</template>
<script>
export default {
data() {
return {
pwdFormData: {
oldPassword: '',
newPassword: '',
confirmNewPassword: ''
},
pwdFormRules: {
oldPassword: {
rules: [
{
required: true,
errorMessage: '请输入旧密码!'
}
]
},
newPassword: {
rules: [
{
required: true,
errorMessage: '请输入新密码!'
}
]
},
confirmNewPassword: {
rules: [
{
required: true,
errorMessage: '请确认新密码!'
}
]
}
},
strongPwdReg: /^\S*(?=\S{8,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/
}
},
methods: {
submitForm() {
let that = this
that.$refs.pwdForm.validate().then(formData => {
if (!that.strongPwdReg.test(formData.newPassword)) {
uni.showToast({
icon: 'none',
title: '新密码格式有误!'
})
} else if (formData.newPassword != formData.confirmNewPassword) {
uni.showToast({
icon: 'none',
title: '确认密码与新密码不一致!'
})
} else {
console.log(formData);
that.$api.user.fixPwd({
oldPassword: formData.oldPassword,
newPassword: formData.newPassword
}).then(res => {
console.log(res);
if (res.data.code == 200) {
uni.showToast({
icon: 'none',
title: '修改成功!',
success: () => {
uni.navigateBack()
}
})
} else {
uni.showToast({
icon: 'none',
title: res.data.msg
})
}
}).catch(err => {
console.log(err);
})
}
})
}
}
}
</script>
<style lang="scss">
.form-area{
width: 90%;
margin: 40rpx auto;
.sub-btn{
width: 40%;
margin: 100rpx auto;
box-sizing: border-box;
padding: 15rpx 30rpx;
display: flex;
justify-content: center;
align-items: center;
border-radius: 15rpx;
background-color: #3888FF;
color: #fff;
}
}
</style>