feat: 优化修改密码输入框

This commit is contained in:
Waiting 2025-02-13 23:32:57 +08:00
parent 2d3147d65d
commit 8352b02110
5 changed files with 91 additions and 108 deletions

View File

@ -5,39 +5,22 @@
<text class="title">{{ getDialogTitle }}</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"> <view class="switch-item" v-if="hasOldPassword">
<text>关闭支付密码</text> <text>关闭支付密码</text>
<u-switch <u-switch v-model="isClosePassword" activeColor="#F32B2B" @change="handleSwitchChange" />
v-model="isClosePassword"
activeColor="#F32B2B"
@change="handleSwitchChange"
/>
</view> </view>
<!-- 旧密码 - 只在修改密码或关闭密码时显示 --> <!-- 旧密码 - 只在修改密码或关闭密码时显示 -->
<view class="form-item" v-if="hasOldPassword"> <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 v-model="oldPassword" type="number" :border="false" placeholder="请输入原密码" :maxlength="6"
v-model="oldPassword" :disabled="isClosePassword" :password="!showOldPassword" @input="handleInput($event, 'oldPassword')" />
type="text" <u-icon :name="showOldPassword ? 'eye-off' : 'eye-fill'" size="20" color="#999"
placeholder="请输入原密码" v-if="hasOldPassword && !isClosePassword" @click="showOldPassword = !showOldPassword" />
:maxlength="6"
:border="false"
fontSize="28rpx"
:disabled="isClosePassword"
:password="!showOldPassword"
/>
<u-icon
:name="showOldPassword ? 'eye-fill' : 'eye-off'"
size="22"
color="#999"
v-if="!isClosePassword"
@click="showOldPassword = !showOldPassword"
/>
</view> </view>
</view> </view>
@ -47,22 +30,10 @@
<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="newPassword" type="number" placeholder="请输入6位数字密码" maxlength="6" :border="false"
v-model="newPassword" :password="!showNewPassword" @input="handleInput($event, 'newPassword')" />
type="text" <u-icon :name="showNewPassword ? 'eye-off' : 'eye-fill'" size="20" color="#999"
placeholder="请输入6位数字密码" @click="showNewPassword = !showNewPassword" />
maxlength="6"
:border="false"
fontSize="28rpx"
:password="!showNewPassword"
@input="validateInput"
/>
<u-icon
:name="showNewPassword ? 'eye-fill' : 'eye-off'"
size="22"
color="#999"
@click="showNewPassword = !showNewPassword"
/>
</view> </view>
</view> </view>
@ -70,36 +41,21 @@
<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" type="number" :border="false" placeholder="请再次输入密码" maxlength="6"
v-model="confirmPassword" :password="!showConfirmPassword" @input="handleInput($event, 'confirmPassword')" />
type="text" <u-icon :name="showConfirmPassword ? 'eye-off' : 'eye-fill'" size="20" color="#999"
placeholder="请再次输入密码" @click="showConfirmPassword = !showConfirmPassword" />
maxlength="6"
:border="false"
fontSize="28rpx"
:password="!showConfirmPassword"
@input="validateInput"
/>
<u-icon
:name="showConfirmPassword ? 'eye-fill' : 'eye-off'"
size="22"
color="#999"
@click="showConfirmPassword = !showConfirmPassword"
/>
</view> </view>
</view> </view>
</template> </template>
</view> </view>
<view class="footer"> <view class="footer">
<button <button :class="{ 'primary-button': isFormValid, 'disabled-button': !isFormValid }" :disabled="!isFormValid"
:class="{'primary-button': isFormValid, 'disabled-button': !isFormValid}" @click.stop='handleConfirm'>
:disabled="!isFormValid"
@click.stop='handleConfirm'
>
完成 完成
</button> </button>
</view> </view>
</view> </view>
</uni-popup> </uni-popup>
</template> </template>
@ -111,11 +67,18 @@ import { useUserStore } from '@/store'
const userStore = useUserStore() const userStore = useUserStore()
const popup = ref<any>(null) const popup = ref<any>(null)
// // -
const showOldPassword = ref(false) const showOldPassword = ref(false)
const showNewPassword = ref(false) const showNewPassword = ref(false)
const showConfirmPassword = ref(false) const showConfirmPassword = ref(false)
//
const resetPasswordVisibility = () => {
showOldPassword.value = false
showNewPassword.value = false
showConfirmPassword.value = false
}
// //
const oldPassword = ref('') const oldPassword = ref('')
const newPassword = ref('') const newPassword = ref('')
@ -152,31 +115,28 @@ const isFormValid = computed(() => {
} }
}) })
// // 6
const validateInput = (value: string) => { const handleInput = (value: string, field: 'oldPassword' | 'newPassword' | 'confirmPassword') => {
const numericValue = value.replace(/\D/g, '') // 6
if (value !== numericValue) { const numericValue = value?.replace(/[^\d]/g, '').slice(0, 6)
newPassword.value = numericValue
confirmPassword.value = numericValue //
switch (field) {
case 'oldPassword':
oldPassword.value = numericValue
break
case 'newPassword':
newPassword.value = numericValue
break
case 'confirmPassword':
confirmPassword.value = numericValue
break
} }
} }
// 6 // 6
const generateRandomPassword = () => { const generateRandomPassword = () => {
return Math.floor(100000 + Math.random() * 900000).toString() return Math.floor(Math.random() * 1000000).toString().padStart(6, '0')
}
//
const handleSwitchChange = (value: boolean) => {
isClosePassword.value = value
//
if (value) {
newPassword.value = ''
confirmPassword.value = ''
oldPassword.value = generateRandomPassword() // 6
} else {
oldPassword.value = ''
}
} }
// //
@ -184,33 +144,24 @@ const resetForm = () => {
oldPassword.value = '' oldPassword.value = ''
newPassword.value = '' newPassword.value = ''
confirmPassword.value = '' confirmPassword.value = ''
showOldPassword.value = false resetPasswordVisibility()
showNewPassword.value = false
showConfirmPassword.value = false
isClosePassword.value = false isClosePassword.value = false
} }
// //
const show = async () => { const show = async () => {
console.log('show pay password dialog')
hasOldPassword.value = userStore.userInfo.paywithpwd === 1 hasOldPassword.value = userStore.userInfo.paywithpwd === 1
isClosePassword.value = false isClosePassword.value = false
resetPasswordVisibility()
popup.value?.open('center') popup.value?.open('center')
} }
// //
const hide = () => { const hide = () => {
console.log('hide pay password dialog')
popup.value?.close() popup.value?.close()
resetForm() resetForm()
} }
//
const handleCancel = () => {
hide()
resetForm()
}
// //
const handleConfirm = async () => { const handleConfirm = async () => {
try { try {
@ -235,6 +186,20 @@ const handleConfirm = async () => {
} }
} }
//
const handleSwitchChange = (value: boolean) => {
isClosePassword.value = value
//
if (value) {
newPassword.value = ''
confirmPassword.value = ''
oldPassword.value = generateRandomPassword() // 6
resetPasswordVisibility()
} else {
oldPassword.value = ''
}
}
// 使 // 使
defineExpose({ defineExpose({
show, show,
@ -249,20 +214,20 @@ defineExpose({
background-color: #fff; background-color: #fff;
border-radius: 24rpx; border-radius: 24rpx;
position: relative; position: relative;
.dialog-header { .dialog-header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 40rpx; margin-bottom: 40rpx;
.title { .title {
font-size: 36rpx; font-size: 36rpx;
font-weight: bold; font-weight: bold;
color: #333; color: #333;
} }
} }
.form-container { .form-container {
.switch-item { .switch-item {
display: flex; display: flex;
@ -270,23 +235,23 @@ defineExpose({
align-items: center; align-items: center;
padding: 20rpx 0; padding: 20rpx 0;
margin-bottom: 20rpx; margin-bottom: 20rpx;
text { text {
font-size: 28rpx; font-size: 28rpx;
color: #333; color: #333;
} }
} }
.form-item { .form-item {
margin-bottom: 30rpx; margin-bottom: 30rpx;
.label { .label {
font-size: 30rpx; font-size: 30rpx;
color: #333; color: #333;
margin-bottom: 16rpx; margin-bottom: 16rpx;
display: block; display: block;
} }
.input-wrapper { .input-wrapper {
display: flex; display: flex;
align-items: center; align-items: center;
@ -294,22 +259,32 @@ defineExpose({
border-radius: 12rpx; border-radius: 12rpx;
padding: 20rpx; padding: 20rpx;
height: 50rpx; height: 50rpx;
:deep(.u-border) {
border-style: hidden;
}
:deep(.u-input) { :deep(.u-input) {
flex: 1; flex: 1;
height: 100%; height: 100%;
background-color: transparent;
border: none;
font-size: 10rpx;
} }
:deep(.u-input__input) { :deep(.u-input__input) {
height: 100%; height: 100%;
line-height: 60rpx; line-height: 60rpx;
font-size: 10rpx;
border: none;
padding: 0;
} }
} }
} }
} }
.footer { .footer {
padding: 0 30rpx; padding: 0 30rpx;
} }
} }
</style> </style>

View File

@ -25,7 +25,7 @@
"usingComponents": true, "usingComponents": true,
"plugins": { "plugins": {
"sqb-pay": { "sqb-pay": {
"version": "1.3.0", "version": "1.3.1",
"provider": "wx55540b288c5ce319" "provider": "wx55540b288c5ce319"
} }
} }

View File

@ -4,7 +4,8 @@
"^u--(.*)": "uview-plus/components/u-$1/u-$1.vue", "^u--(.*)": "uview-plus/components/u-$1/u-$1.vue",
"^up-(.*)": "uview-plus/components/u-$1/u-$1.vue", "^up-(.*)": "uview-plus/components/u-$1/u-$1.vue",
"^u-([^-].*)": "uview-plus/components/u-$1/u-$1.vue", "^u-([^-].*)": "uview-plus/components/u-$1/u-$1.vue",
"^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)": "z-paging/components/z-paging$1/z-paging$1.vue" "^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)": "z-paging/components/z-paging$1/z-paging$1.vue",
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
} }
}, },
"pages": [ "pages": [

View File

@ -156,7 +156,6 @@ onShow(async () => {
const { cardurl } = await getCardLink(); const { cardurl } = await getCardLink();
cardLink.value = cardurl; cardLink.value = cardurl;
await userStore.getProfile(); await userStore.getProfile();
await userStore.getPayPasswordStatus();
} }
}); });

View File

@ -76,9 +76,17 @@ page {
justify-content: center; justify-content: center;
min-width: 80%; min-width: 80%;
color: #FFFFFF; color: #FFFFFF;
border: none !important;
outline: none;
&::after {
display: none;
}
} }
.disabled-button { .disabled-button {
@extend .primary-button; @extend .primary-button;
background: #cccccc; background: #cccccc;
&::after {
display: none;
}
} }