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>
<!-- 旧密码 --> <!-- 旧密码 - 只在修改密码或关闭密码时显示 -->
<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',