<route lang="json5" type="page">
|
{
|
layout: 'default',
|
needLogin: true,
|
"style": {
|
"navigationBarTitleText": "修改密码"
|
}
|
}
|
</route>
|
|
<template>
|
<view class="container">
|
<wd-form ref="formRef" :model="form">
|
<wd-cell-group custom-class="cell-group" border>
|
<wd-input
|
label="旧密码"
|
label-width="100px"
|
clearable
|
show-word-limit
|
prop="oldPassword"
|
show-password
|
v-model="form.oldPassword"
|
placeholder="请输入旧密码"
|
:rules="[{ required: true, message: '旧密码不能为空' }]"
|
/>
|
<wd-input
|
label="新密码"
|
label-width="100px"
|
clearable
|
show-word-limit
|
prop="newPassword"
|
show-password
|
v-model="form.newPassword"
|
placeholder="请输入新密码"
|
:rules="[
|
{ required: true, message: '新密码不能为空' },
|
{ validator: validatePassword },
|
]"
|
/>
|
<wd-input
|
label="确认新密码"
|
label-width="100px"
|
clearable
|
show-word-limit
|
prop="confirmNewPassword"
|
show-password
|
v-model="form.confirmNewPassword"
|
placeholder="请再次输入新密码"
|
:rules="[
|
{ required: true, message: '确认新密码不能为空' },
|
{ validator: validatePassword },
|
{
|
validator: (value) => value === form.newPassword,
|
message: '两次输入的密码不一致'
|
}
|
]"
|
/>
|
</wd-cell-group>
|
<view class="footer">
|
<wd-button type="primary" class="mt-6" size="large" block @click="submit">提交</wd-button>
|
</view>
|
</wd-form>
|
</view>
|
</template>
|
|
<script lang="ts" setup>
|
import { ref, reactive } from 'vue'
|
import { updatePassword } from '@/service/app/user'
|
import { useUserStore, useAccessStore, useSystemConfigStore } from '@/store'
|
|
|
const userStore = useUserStore()
|
const accessStore = useAccessStore()
|
const configStore = useSystemConfigStore()
|
|
const form = reactive({
|
oldPassword: '',
|
newPassword: '',
|
confirmNewPassword: ''
|
})
|
const formRef = ref()
|
|
const validatePassword = (value) => {
|
if (value.length < 6) {
|
return Promise.reject('密码长度不能少于6位')
|
}
|
if (value.length > 20) {
|
return Promise.reject('密码长度不能超过20位')
|
}
|
return Promise.resolve()
|
}
|
|
const submit = () => {
|
|
formRef.value.validate().then(({ valid, errors }) => {
|
if (valid) {
|
updatePassword(form.oldPassword, form.newPassword)
|
.then((response) => {
|
if (response.code === 200) {
|
uni.showToast({
|
title: '修改密码成功',
|
icon: 'success',
|
})
|
userStore.clearUserInfo()
|
accessStore.clearAccessInfo()
|
configStore.clearConfigInfo()
|
uni.reLaunch({
|
url: '/pages/login/index',
|
})
|
} else {
|
uni.showToast({
|
title: response.msg || '修改密码失败',
|
icon: 'error',
|
})
|
}
|
})
|
.catch((error) => {
|
uni.showToast({
|
title: error.msg || '修改密码失败',
|
icon: 'error',
|
})
|
})
|
}
|
})
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.footer {
|
margin: 20px;
|
}
|
</style>
|