feat: 完善支付密码逻辑

This commit is contained in:
Waiting 2025-01-21 23:45:15 +08:00
parent b50eb2f1c2
commit 1c8de323fe

View File

@ -17,8 +17,8 @@
/>
</view>
<!-- 旧密码 -->
<view class="form-item" v-if="hasOldPassword && !isClosePassword">
<!-- 旧密码 - 只在修改密码或关闭密码时显示 -->
<view class="form-item" v-if="hasOldPassword">
<text class="label">原密码</text>
<view class="input-wrapper">
<u-input
@ -28,18 +28,20 @@
:maxlength="6"
:border="false"
fontSize="28rpx"
:disabled="isClosePassword"
/>
<u-icon
:name="showOldPassword ? 'eye-fill' : 'eye-off'"
size="22"
color="#999"
v-if="!isClosePassword"
@click="showOldPassword = !showOldPassword"
/>
</view>
</view>
<!-- 新密码和确认密码部分只在非关闭模式下显示 -->
<template v-if="showNewPasswordInputs">
<!-- 新密码和确认密码部分 -->
<template v-if="!isClosePassword">
<!-- 新密码 -->
<view class="form-item">
<text class="label">新密码</text>
@ -116,18 +118,12 @@ const oldPassword = ref('')
const newPassword = ref('')
const confirmPassword = ref('')
//
//
const hasOldPassword = ref(false)
//
const isClosePassword = ref(false)
//
const showNewPasswordInputs = computed(() => {
// ()
return !hasOldPassword.value || (hasOldPassword.value && !isClosePassword.value)
})
//
const getDialogTitle = computed(() => {
if (!hasOldPassword.value) return '设置支付密码'
@ -137,14 +133,14 @@ const getDialogTitle = 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.length !== 6 || confirmPassword.value.length !== 6) return false
return newPassword.value === confirmPassword.value
} else if (isClosePassword.value) {
//
return oldPassword.value.length === 6
} else {
//
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) => {
isClosePassword.value = value
//
//
if (value) {
newPassword.value = ''
confirmPassword.value = ''
oldPassword.value = generateRandomPassword() // 6
} else {
oldPassword.value = ''
}
}
@ -186,7 +190,8 @@ const resetForm = () => {
//
const show = async () => {
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')
}
@ -207,10 +212,12 @@ const handleCancel = () => {
const handleConfirm = async () => {
try {
await userStore.setPayPassword({
paywithpwd: isClosePassword.value ? 0 : 1, // 0: 1:
paywithpwd: isClosePassword.value ? 0 : 1,
oldpwd: hasOldPassword.value ? oldPassword.value : '',
newpwd: isClosePassword.value ? '' : newPassword.value,
})
//
userStore.userInfo.paywithpwd = isClosePassword.value ? 0 : 1
uni.showToast({
title: isClosePassword.value ? '已关闭支付密码' : '设置成功',
icon: 'success',