feat: 完善支付密码逻辑
This commit is contained in:
parent
b50eb2f1c2
commit
1c8de323fe
@ -17,8 +17,8 @@
|
|||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 旧密码 -->
|
<!-- 旧密码 - 只在修改密码或关闭密码时显示 -->
|
||||||
<view class="form-item" v-if="hasOldPassword && !isClosePassword">
|
<view class="form-item" v-if="hasOldPassword">
|
||||||
<text class="label">原密码:</text>
|
<text class="label">原密码:</text>
|
||||||
<view class="input-wrapper">
|
<view class="input-wrapper">
|
||||||
<u-input
|
<u-input
|
||||||
@ -28,18 +28,20 @@
|
|||||||
:maxlength="6"
|
:maxlength="6"
|
||||||
:border="false"
|
:border="false"
|
||||||
fontSize="28rpx"
|
fontSize="28rpx"
|
||||||
|
:disabled="isClosePassword"
|
||||||
/>
|
/>
|
||||||
<u-icon
|
<u-icon
|
||||||
:name="showOldPassword ? 'eye-fill' : 'eye-off'"
|
:name="showOldPassword ? 'eye-fill' : 'eye-off'"
|
||||||
size="22"
|
size="22"
|
||||||
color="#999"
|
color="#999"
|
||||||
|
v-if="!isClosePassword"
|
||||||
@click="showOldPassword = !showOldPassword"
|
@click="showOldPassword = !showOldPassword"
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 新密码和确认密码部分只在非关闭模式下显示 -->
|
<!-- 新密码和确认密码部分 -->
|
||||||
<template v-if="showNewPasswordInputs">
|
<template v-if="!isClosePassword">
|
||||||
<!-- 新密码 -->
|
<!-- 新密码 -->
|
||||||
<view class="form-item">
|
<view class="form-item">
|
||||||
<text class="label">新密码:</text>
|
<text class="label">新密码:</text>
|
||||||
@ -116,18 +118,12 @@ const oldPassword = ref('')
|
|||||||
const newPassword = ref('')
|
const newPassword = ref('')
|
||||||
const confirmPassword = ref('')
|
const confirmPassword = ref('')
|
||||||
|
|
||||||
// 是否有旧密码
|
// 是否有旧密码(是否已开启支付密码)
|
||||||
const hasOldPassword = ref(false)
|
const hasOldPassword = ref(false)
|
||||||
|
|
||||||
// 是否关闭支付密码
|
// 是否关闭支付密码
|
||||||
const isClosePassword = ref(false)
|
const isClosePassword = ref(false)
|
||||||
|
|
||||||
// 是否显示新密码输入框
|
|
||||||
const showNewPasswordInputs = computed(() => {
|
|
||||||
// 当没有旧密码时(首次设置),或者有旧密码且不是关闭操作时,显示新密码输入框
|
|
||||||
return !hasOldPassword.value || (hasOldPassword.value && !isClosePassword.value)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取弹框标题
|
// 获取弹框标题
|
||||||
const getDialogTitle = computed(() => {
|
const getDialogTitle = computed(() => {
|
||||||
if (!hasOldPassword.value) return '设置支付密码'
|
if (!hasOldPassword.value) return '设置支付密码'
|
||||||
@ -137,14 +133,14 @@ const getDialogTitle = computed(() => {
|
|||||||
|
|
||||||
// 表单验证逻辑更新
|
// 表单验证逻辑更新
|
||||||
const isFormValid = computed(() => {
|
const isFormValid = computed(() => {
|
||||||
if (!hasOldPassword.value) {
|
if (isClosePassword.value) {
|
||||||
|
// 关闭支付密码时,只要有开关就可以点击完成
|
||||||
|
return true
|
||||||
|
} else if (!hasOldPassword.value) {
|
||||||
// 首次设置密码
|
// 首次设置密码
|
||||||
if (!newPassword.value || !confirmPassword.value) return false
|
if (!newPassword.value || !confirmPassword.value) return false
|
||||||
if (newPassword.value.length !== 6 || confirmPassword.value.length !== 6) return false
|
if (newPassword.value.length !== 6 || confirmPassword.value.length !== 6) return false
|
||||||
return newPassword.value === confirmPassword.value
|
return newPassword.value === confirmPassword.value
|
||||||
} else if (isClosePassword.value) {
|
|
||||||
// 关闭支付密码
|
|
||||||
return oldPassword.value.length === 6
|
|
||||||
} else {
|
} else {
|
||||||
// 修改密码
|
// 修改密码
|
||||||
if (!oldPassword.value || !newPassword.value || !confirmPassword.value) return false
|
if (!oldPassword.value || !newPassword.value || !confirmPassword.value) return false
|
||||||
@ -162,13 +158,21 @@ const validateInput = (value: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 生成随机6位数字
|
||||||
|
const generateRandomPassword = () => {
|
||||||
|
return Math.floor(100000 + Math.random() * 900000).toString()
|
||||||
|
}
|
||||||
|
|
||||||
// 处理开关切换
|
// 处理开关切换
|
||||||
const handleSwitchChange = (value: boolean) => {
|
const handleSwitchChange = (value: boolean) => {
|
||||||
isClosePassword.value = value
|
isClosePassword.value = value
|
||||||
// 切换时重置新密码输入
|
// 切换时重置密码输入
|
||||||
if (value) {
|
if (value) {
|
||||||
newPassword.value = ''
|
newPassword.value = ''
|
||||||
confirmPassword.value = ''
|
confirmPassword.value = ''
|
||||||
|
oldPassword.value = generateRandomPassword() // 生成随机6位数字
|
||||||
|
} else {
|
||||||
|
oldPassword.value = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +190,8 @@ const resetForm = () => {
|
|||||||
// 显示弹框
|
// 显示弹框
|
||||||
const show = async () => {
|
const show = async () => {
|
||||||
console.log('show pay password dialog')
|
console.log('show pay password dialog')
|
||||||
hasOldPassword.value = userStore.userInfo.paywithpwd===1
|
hasOldPassword.value = userStore.userInfo.paywithpwd === 1
|
||||||
|
isClosePassword.value = false
|
||||||
popup.value?.open('center')
|
popup.value?.open('center')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,10 +212,12 @@ const handleCancel = () => {
|
|||||||
const handleConfirm = async () => {
|
const handleConfirm = async () => {
|
||||||
try {
|
try {
|
||||||
await userStore.setPayPassword({
|
await userStore.setPayPassword({
|
||||||
paywithpwd: isClosePassword.value ? 0 : 1, // 0:关闭 1:开启
|
paywithpwd: isClosePassword.value ? 0 : 1,
|
||||||
oldpwd: hasOldPassword.value ? oldPassword.value : '',
|
oldpwd: hasOldPassword.value ? oldPassword.value : '',
|
||||||
newpwd: isClosePassword.value ? '' : newPassword.value,
|
newpwd: isClosePassword.value ? '' : newPassword.value,
|
||||||
})
|
})
|
||||||
|
// 更新本地状态
|
||||||
|
userStore.userInfo.paywithpwd = isClosePassword.value ? 0 : 1
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: isClosePassword.value ? '已关闭支付密码' : '设置成功',
|
title: isClosePassword.value ? '已关闭支付密码' : '设置成功',
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
|
Loading…
Reference in New Issue
Block a user