feat: 支付密码设置逻辑调整
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* 用户信息相关接口
|
* 用户信息相关接口
|
||||||
*/
|
*/
|
||||||
import type { CouponBean, LoginParams, LoginResult, RegisterParams, TerminalBean, SetPayPasswordParams, PayPasswordResponse } from './types';
|
import type { CouponBean, LoginParams, LoginResult, RegisterParams, TerminalBean, SetPayPasswordParams} from './types';
|
||||||
import { get, post } from '@/utils/request';
|
import { get, post } from '@/utils/request';
|
||||||
import { UserBean } from '@/store/modules/user/types';
|
import { UserBean } from '@/store/modules/user/types';
|
||||||
|
|
||||||
@@ -35,7 +35,6 @@ enum URL {
|
|||||||
cardLink = '/wc/wechat/get_card_url',
|
cardLink = '/wc/wechat/get_card_url',
|
||||||
registerCoupon = '/couponsStrategy/wx_register_coupon',
|
registerCoupon = '/couponsStrategy/wx_register_coupon',
|
||||||
setPayPassword = '/app/pay/set_paypwd',
|
setPayPassword = '/app/pay/set_paypwd',
|
||||||
payPasswordStatus = '/user/pay-password/status',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getUserProfile = () => get<UserBean>({ url: URL.profile });
|
export const getUserProfile = () => get<UserBean>({ url: URL.profile });
|
||||||
@@ -86,10 +85,3 @@ export const setPayPassword = (data: SetPayPasswordParams) => post<PayPasswordRe
|
|||||||
url: URL.setPayPassword,
|
url: URL.setPayPassword,
|
||||||
data
|
data
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取支付密码状态
|
|
||||||
*/
|
|
||||||
export const getPayPasswordStatus = () => get<{ hasPassword: boolean }>({
|
|
||||||
url: URL.payPasswordStatus
|
|
||||||
});
|
|
||||||
|
@@ -120,12 +120,7 @@ export interface TerminalBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SetPayPasswordParams {
|
export interface SetPayPasswordParams {
|
||||||
paywithpwd: number
|
paywithpwd: number // 0: 开启支付密码, 1: 关闭支付密码
|
||||||
oldpwd: string,
|
oldpwd: string,
|
||||||
newpwd: string
|
newpwd: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PayPasswordResponse {
|
|
||||||
success: boolean
|
|
||||||
message: string
|
|
||||||
}
|
|
||||||
|
@@ -2,19 +2,29 @@
|
|||||||
<uni-popup ref="popup" type="center" :safe-area="true" :mask-click="false">
|
<uni-popup ref="popup" type="center" :safe-area="true" :mask-click="false">
|
||||||
<view class="pay-password-dialog">
|
<view class="pay-password-dialog">
|
||||||
<view class="dialog-header">
|
<view class="dialog-header">
|
||||||
<text class="title">设置支付密码</text>
|
<text class="title">{{ getDialogTitle }}</text>
|
||||||
<u-icon name="close" size="20" color="#999" @click="hide" />
|
<u-icon name="close" size="20" color="#999" @click="hide" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="form-container">
|
<view class="form-container">
|
||||||
|
<!-- 关闭支付密码选项 -->
|
||||||
|
<view class="switch-item" v-if="hasOldPassword">
|
||||||
|
<text>关闭支付密码</text>
|
||||||
|
<u-switch
|
||||||
|
v-model="isClosePassword"
|
||||||
|
activeColor="#F32B2B"
|
||||||
|
@change="handleSwitchChange"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
|
||||||
<!-- 旧密码 -->
|
<!-- 旧密码 -->
|
||||||
<view class="form-item">
|
<view class="form-item" v-if="hasOldPassword && !isClosePassword">
|
||||||
<text class="label">旧密码:</text>
|
<text class="label">原密码:</text>
|
||||||
<view class="input-wrapper">
|
<view class="input-wrapper">
|
||||||
<u-input
|
<u-input
|
||||||
v-model="oldPassword"
|
v-model="oldPassword"
|
||||||
:type="showOldPassword ? 'text' : 'password'"
|
:type="showOldPassword ? 'text' : 'password'"
|
||||||
placeholder="请输入旧密码"
|
placeholder="请输入原密码"
|
||||||
:maxlength="6"
|
:maxlength="6"
|
||||||
:border="false"
|
:border="false"
|
||||||
fontSize="28rpx"
|
fontSize="28rpx"
|
||||||
@@ -28,55 +38,58 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 新密码 -->
|
<!-- 新密码和确认密码部分只在非关闭模式下显示 -->
|
||||||
<view class="form-item">
|
<template v-if="showNewPasswordInputs">
|
||||||
<text class="label">新密码:</text>
|
<!-- 新密码 -->
|
||||||
<view class="input-wrapper">
|
<view class="form-item">
|
||||||
<u-input
|
<text class="label">新密码:</text>
|
||||||
v-model="newPassword"
|
<view class="input-wrapper">
|
||||||
:type="showNewPassword ? 'text' : 'password'"
|
<u-input
|
||||||
placeholder="请输入6位数字密码"
|
v-model="newPassword"
|
||||||
maxlength="6"
|
:type="showNewPassword ? 'text' : 'password'"
|
||||||
:border="false"
|
placeholder="请输入6位数字密码"
|
||||||
fontSize="28rpx"
|
maxlength="6"
|
||||||
@input="validateInput"
|
:border="false"
|
||||||
/>
|
fontSize="28rpx"
|
||||||
<u-icon
|
@input="validateInput"
|
||||||
:name="showNewPassword ? 'eye-fill' : 'eye-off'"
|
/>
|
||||||
size="22"
|
<u-icon
|
||||||
color="#999"
|
:name="showNewPassword ? 'eye-fill' : 'eye-off'"
|
||||||
@click="showNewPassword = !showNewPassword"
|
size="22"
|
||||||
/>
|
color="#999"
|
||||||
|
@click="showNewPassword = !showNewPassword"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- 确认密码 -->
|
<!-- 确认密码 -->
|
||||||
<view class="form-item">
|
<view class="form-item">
|
||||||
<text class="label">确认密码:</text>
|
<text class="label">确认密码:</text>
|
||||||
<view class="input-wrapper">
|
<view class="input-wrapper">
|
||||||
<u-input
|
<u-input
|
||||||
v-model="confirmPassword"
|
v-model="confirmPassword"
|
||||||
:type="showConfirmPassword ? 'text' : 'password'"
|
:type="showConfirmPassword ? 'text' : 'password'"
|
||||||
placeholder="请再次输入密码"
|
placeholder="请再次输入密码"
|
||||||
maxlength="6"
|
maxlength="6"
|
||||||
:border="false"
|
:border="false"
|
||||||
fontSize="28rpx"
|
fontSize="28rpx"
|
||||||
@input="validateInput"
|
@input="validateInput"
|
||||||
/>
|
/>
|
||||||
<u-icon
|
<u-icon
|
||||||
:name="showConfirmPassword ? 'eye-fill' : 'eye-off'"
|
:name="showConfirmPassword ? 'eye-fill' : 'eye-off'"
|
||||||
size="22"
|
size="22"
|
||||||
color="#999"
|
color="#999"
|
||||||
@click="showConfirmPassword = !showConfirmPassword"
|
@click="showConfirmPassword = !showConfirmPassword"
|
||||||
/>
|
/>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="footer">
|
<view class="footer">
|
||||||
<button
|
<button
|
||||||
:class="{'primary-button': isValid, 'disabled-button': !isValid}"
|
:class="{'primary-button': isFormValid, 'disabled-button': !isFormValid}"
|
||||||
:disabled="!isValid"
|
:disabled="!isFormValid"
|
||||||
@click.stop='handleConfirm'
|
@click.stop='handleConfirm'
|
||||||
>
|
>
|
||||||
完成
|
完成
|
||||||
@@ -104,13 +117,40 @@ const newPassword = ref('')
|
|||||||
const confirmPassword = ref('')
|
const confirmPassword = ref('')
|
||||||
|
|
||||||
// 是否有旧密码
|
// 是否有旧密码
|
||||||
const hasOldPassword = computed(() => userStore.userInfo.hasPayPassword)
|
const hasOldPassword = ref(false)
|
||||||
|
|
||||||
// 表单验证
|
// 是否关闭支付密码
|
||||||
const isValid = computed(() => {
|
const isClosePassword = ref(false)
|
||||||
if (!newPassword.value || !confirmPassword.value) return false
|
|
||||||
if (newPassword.value.length !== 6 || confirmPassword.value.length !== 6) return false
|
// 是否显示新密码输入框
|
||||||
return newPassword.value === confirmPassword.value
|
const showNewPasswordInputs = computed(() => {
|
||||||
|
// 当没有旧密码时(首次设置),或者有旧密码且不是关闭操作时,显示新密码输入框
|
||||||
|
return !hasOldPassword.value || (hasOldPassword.value && !isClosePassword.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取弹框标题
|
||||||
|
const getDialogTitle = computed(() => {
|
||||||
|
if (!hasOldPassword.value) return '设置支付密码'
|
||||||
|
if (isClosePassword.value) return '关闭支付密码'
|
||||||
|
return '修改支付密码'
|
||||||
|
})
|
||||||
|
|
||||||
|
// 表单验证逻辑更新
|
||||||
|
const isFormValid = computed(() => {
|
||||||
|
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
|
||||||
|
if (oldPassword.value.length !== 6 || newPassword.value.length !== 6 || confirmPassword.value.length !== 6) return false
|
||||||
|
return newPassword.value === confirmPassword.value
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 输入验证(只允许数字)
|
// 输入验证(只允许数字)
|
||||||
@@ -122,7 +162,17 @@ const validateInput = (value: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置表单
|
// 处理开关切换
|
||||||
|
const handleSwitchChange = (value: boolean) => {
|
||||||
|
isClosePassword.value = value
|
||||||
|
// 切换时重置新密码输入
|
||||||
|
if (value) {
|
||||||
|
newPassword.value = ''
|
||||||
|
confirmPassword.value = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置表单更新
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
oldPassword.value = ''
|
oldPassword.value = ''
|
||||||
newPassword.value = ''
|
newPassword.value = ''
|
||||||
@@ -130,11 +180,13 @@ const resetForm = () => {
|
|||||||
showOldPassword.value = false
|
showOldPassword.value = false
|
||||||
showNewPassword.value = false
|
showNewPassword.value = false
|
||||||
showConfirmPassword.value = false
|
showConfirmPassword.value = false
|
||||||
|
isClosePassword.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示弹框
|
// 显示弹框
|
||||||
const show = () => {
|
const show = async () => {
|
||||||
console.log('show pay password dialog')
|
console.log('show pay password dialog')
|
||||||
|
hasOldPassword.value = userStore.userInfo.paywithpwd===1
|
||||||
popup.value?.open('center')
|
popup.value?.open('center')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,23 +203,23 @@ const handleCancel = () => {
|
|||||||
resetForm()
|
resetForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确认
|
// 确认按钮处理更新
|
||||||
const handleConfirm = async () => {
|
const handleConfirm = async () => {
|
||||||
try {
|
try {
|
||||||
await userStore.setPayPassword({
|
await userStore.setPayPassword({
|
||||||
paywithpwd:'0',
|
paywithpwd: isClosePassword.value ? 0 : 1, // 0:关闭 1:开启
|
||||||
oldpwd: oldPassword.value,
|
oldpwd: hasOldPassword.value ? oldPassword.value : '',
|
||||||
newpwd: newPassword.value,
|
newpwd: isClosePassword.value ? '' : newPassword.value,
|
||||||
})
|
})
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '设置成功',
|
title: isClosePassword.value ? '已关闭支付密码' : '设置成功',
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
})
|
})
|
||||||
hide()
|
hide()
|
||||||
resetForm()
|
resetForm()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '设置失败',
|
title: '操作失败',
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -202,6 +254,19 @@ defineExpose({
|
|||||||
}
|
}
|
||||||
|
|
||||||
.form-container {
|
.form-container {
|
||||||
|
.switch-item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 20rpx 0;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
|
||||||
|
text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.form-item {
|
.form-item {
|
||||||
margin-bottom: 30rpx;
|
margin-bottom: 30rpx;
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
"modules": {}
|
"modules": {}
|
||||||
},
|
},
|
||||||
"mp-weixin": {
|
"mp-weixin": {
|
||||||
"appid": "wx67a750d0ceed4d88",
|
"appid": "wx92e663dc11d0c0a8",
|
||||||
"setting": {
|
"setting": {
|
||||||
"urlCheck": false
|
"urlCheck": false
|
||||||
},
|
},
|
||||||
|
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '@/utils/auth';
|
} from '@/utils/auth';
|
||||||
import type { RegisterParams, TerminalBean,SetPayPasswordParams } from '@/api/user/types';
|
import type { RegisterParams, TerminalBean,SetPayPasswordParams } from '@/api/user/types';
|
||||||
import { getCompanyInfo } from '@/api/company';
|
import { getCompanyInfo } from '@/api/company';
|
||||||
import { setPayPassword, getPayPasswordStatus } from '@/api/user'
|
import { setPayPassword } from '@/api/user'
|
||||||
|
|
||||||
const useUserStore = defineStore('user', {
|
const useUserStore = defineStore('user', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -204,17 +204,11 @@ const useUserStore = defineStore('user', {
|
|||||||
async setPayPassword(params: SetPayPasswordParams) {
|
async setPayPassword(params: SetPayPasswordParams) {
|
||||||
const res = await setPayPassword(params)
|
const res = await setPayPassword(params)
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
this.userInfo.hasPayPassword = true
|
this.userInfo.paywithpwd = 1
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取支付密码状态
|
|
||||||
async getPayPasswordStatus() {
|
|
||||||
const res = await getPayPasswordStatus()
|
|
||||||
this.userInfo.hasPayPassword = res.hasPassword
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ export interface UserBean {
|
|||||||
useCouponsPrice: number;
|
useCouponsPrice: number;
|
||||||
wirelinedTelephone: string;
|
wirelinedTelephone: string;
|
||||||
userDiscount: number;
|
userDiscount: number;
|
||||||
hasPayPassword: boolean;
|
paywithpwd: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type providerType =
|
export type providerType =
|
||||||
|
Reference in New Issue
Block a user