cultivationApp/pages/updatePassword/updatePassword.vue

140 lines
3.7 KiB
Vue
Raw Normal View History

2023-11-21 18:54:33 +08:00
<template>
<view class="content">
<view class="reset-password">
<u--form ref="formRef" :rules="rules" :model="formData">
<u-form-item label="原密码" labelWidth="140rpx" borderBottom prop="old_password">
<u--input v-model="formData.old_password" :password="!pwdShow.old_password" placeholder="请输入原密码"
maxlength="18">
<!-- #ifdef APP-PLUS -->
<!-- <template slot="suffix">
<uni-icons :type="pwdShow.old_password?'eye-filled':'eye-slash-filled'" @click="pwdShow.old_password=!pwdShow.old_password" color="#999"></uni-icons>
</template> -->
<!-- #endif -->
</u--input>
</u-form-item>
<u-form-item label="新密码" labelWidth="140rpx" borderBottom prop="password">
<u--input v-model="formData.password" :password="!pwdShow.password" placeholder="请输入新密码"
maxlength="18">
<!-- #ifdef APP-PLUS -->
<!-- <template slot="suffix">
<u--icon :name="pwdShow.password?'eye-off':'eye-fill'" @click="pwdShow.old_password=!pwdShow.old_password" color="#999"></u--icon>
</template> -->
<!-- #endif -->
</u--input>
</u-form-item>
<u-form-item label="确认密码" labelWidth="140rpx" borderBottom prop="password_confirm">
<u--input v-model="formData.password_confirm" :password="!pwdShow.password_confirm"
placeholder="请确认新密码" maxlength="18">
<!-- #ifdef APP-PLUS -->
<!-- <template slot="suffix">
<u--icon :name="pwdShow.password_confirm?'eye-off':'eye-fill'" @click="pwdShow.old_password=!pwdShow.old_password" color="#999"></u--icon>
</template> -->
<!-- #endif -->
</u--input>
</u-form-item>
<u-button style="margin-top: 28rpx;background-color:#34D190;color: #fff;" @click="submit">提交</u-button>
</u--form>
</view>
</view>
</template>
<script>
import {
changePassword
} from '@/api/file.js'
2023-11-21 18:54:33 +08:00
export default {
data() {
return {
pwdShow: {
old_password: false,
password: false,
password_confirm: false,
},
formData: {
old_password: '', // 原密码
password: '', // 新密码
password_confirm: '', // 确认密码
},
rules: {
old_password: {
type: 'string',
required: true,
min: 6,
max: 18,
message: '请输入6-18位密码',
trigger: ['change', 'blur']
},
password: {
type: 'string',
required: true,
min: 6,
max: 18,
message: '请输入6-18位密码',
trigger: ['change', 'blur']
},
password_confirm: {
type: 'string',
required: true,
min: 6,
max: 18,
message: '请输入6-18位密码',
trigger: ['change', 'blur']
},
}
}
},
methods: {
submit() {
this.$refs.formRef.validate().then(async (e) => {
if (e) {
if (this.formData.password == this.formData.old_password) return uni.$u.toast('新密码不能与原密码一致');
if (this.formData.password !== this.formData.password_confirm) return uni.$u.toast(
2023-11-21 18:54:33 +08:00
'两次新密码不一致');
2023-11-21 18:54:33 +08:00
await changePassword({
...this.formData
});
uni.$u.toast('修改成功');
2023-11-21 18:54:33 +08:00
this.$u.sleep(500).then(() => {
uni.showLoading({
mask: true,
title: '加载中'
})
uni.switchTab({
url: '/pages/index/index',
2023-11-21 18:54:33 +08:00
success: () => {
2023-11-21 18:54:33 +08:00
uni.hideLoading()
}
})
2023-11-21 18:54:33 +08:00
})
2023-11-21 18:54:33 +08:00
}
})
}
}
}
</script>
<style lang="scss" scoped>
.content {
padding-top: 10rpx;
background-color: $theme-bg-color;
height: 100vh;
}
.reset-password {
margin: 28rpx;
padding: 28rpx;
background-color: #fff;
border-radius: 14rpx;
}
</style>