Files
yunzerwebsiteallinone/uniapp/pages/profile/changePassword.vue
T
2026-11-16 17:22:50 +08:00

278 lines
5.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="page">
<view class="nav" :style="headPad">
<view class="nav-back" @tap="goBack">
<FaIcon name="chevron-left" color="#1e293b" :size="18" />
<text class="nav-text">返回</text>
</view>
</view>
<view class="header">
<text class="title">修改密码</text>
<text class="subtitle">统一认证账号密码,修改后全端同步生效</text>
</view>
<view class="form-card">
<view class="field">
<text class="label">当前密码</text>
<view class="input-wrap">
<FaIcon name="lock" color="#94a3b8" :size="15" />
<input
v-model="form.old_password"
class="input"
:password="!showPassword"
placeholder="请输入当前密码"
placeholder-class="ph"
/>
<view class="eye" @tap="showPassword = !showPassword">
<FaIcon
:name="showPassword ? 'eye-slash' : 'eye'"
color="#a7b1c7"
:size="15"
/>
</view>
</view>
</view>
<view class="field">
<text class="label">新密码</text>
<view class="input-wrap">
<FaIcon name="key" color="#94a3b8" :size="15" />
<input
v-model="form.new_password"
class="input"
:password="!showPassword"
placeholder="至少 6 位字符"
placeholder-class="ph"
/>
</view>
</view>
<view class="field">
<text class="label">确认新密码</text>
<view class="input-wrap">
<FaIcon name="key" color="#94a3b8" :size="15" />
<input
v-model="form.confirm_password"
class="input"
:password="!showPassword"
placeholder="再次输入新密码"
placeholder-class="ph"
/>
</view>
</view>
<text v-if="errorText" class="error-text">{{ errorText }}</text>
<view class="submit" :class="{ disabled: submitting }" @tap="submit">
{{ submitting ? '提交中…' : '确认修改' }}
</view>
<view class="tip">
<FaIcon name="circle-info" color="#94a3b8" :size="12" />
<text class="tip-text">修改成功后手机端、Web 后台与小程序密码同时更新,无需重新登录。</text>
</view>
</view>
</view>
</template>
<script setup>
import { reactive, ref } from 'vue'
import { mpHeadPad } from '@/utils/mpHead.js'
import { changePassword } from '@/api/auth.js'
const headPad = mpHeadPad()
const form = reactive({
old_password: '',
new_password: '',
confirm_password: ''
})
const showPassword = ref(false)
const submitting = ref(false)
const errorText = ref('')
async function submit() {
if (submitting.value) return
errorText.value = ''
if (!form.old_password) {
errorText.value = '请输入当前密码'
return
}
if (!form.new_password || form.new_password.length < 6) {
errorText.value = '新密码长度不能少于 6 位'
return
}
if (form.new_password !== form.confirm_password) {
errorText.value = '两次输入的新密码不一致'
return
}
if (form.new_password === form.old_password) {
errorText.value = '新密码不能与当前密码相同'
return
}
submitting.value = true
try {
await changePassword({
old_password: form.old_password,
new_password: form.new_password,
confirm_password: form.confirm_password
})
uni.showToast({ title: '密码已修改', icon: 'success' })
setTimeout(() => {
goBack()
}, 700)
} catch (e) {
errorText.value = (e && e.message) || '修改失败,请重试'
} finally {
submitting.value = false
}
}
function goBack() {
uni.navigateBack({ fail: () => uni.reLaunch({ url: '/pages/nav/nav' }) })
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
padding: 0 $page-padding-x calc(env(safe-area-inset-bottom, 0px) + 40rpx);
box-sizing: border-box;
}
.nav {
padding-top: calc(var(--status-bar-height, 44px) + 16rpx);
/* #ifdef MP-WEIXIN */
padding-top: calc(env(safe-area-inset-top, 25px) + 80rpx);
/* #endif */
}
.nav-back {
display: flex;
align-items: center;
gap: 4rpx;
padding: 8rpx 0;
width: fit-content;
}
.nav-text {
font-size: 28rpx;
color: $color-text;
}
.header {
padding: 20rpx 0 32rpx;
}
.title {
display: block;
font-size: 44rpx;
font-weight: 600;
color: $color-text;
}
.subtitle {
display: block;
margin-top: 10rpx;
font-size: 24rpx;
color: $color-text-muted;
}
.form-card {
@include card;
padding: 32rpx 28rpx;
}
.field {
margin-bottom: 28rpx;
}
.label {
display: block;
margin-bottom: 12rpx;
font-size: 26rpx;
font-weight: 500;
color: $color-text-secondary;
}
.input-wrap {
display: flex;
align-items: center;
gap: 12rpx;
padding: 0 20rpx;
border-radius: $radius-md;
background: $color-bg-page;
border: 1rpx solid $color-border;
}
.input {
flex: 1;
min-width: 0;
height: 92rpx;
font-size: 30rpx;
color: $color-text;
}
.ph {
color: #adb6c9;
font-size: 28rpx;
}
.eye {
width: 52rpx;
height: 52rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.error-text {
display: block;
margin-bottom: 8rpx;
font-size: 24rpx;
color: $color-danger;
}
.submit {
height: 96rpx;
margin-top: 16rpx;
border-radius: $radius-md;
background: $color-primary;
display: flex;
align-items: center;
justify-content: center;
font-size: 32rpx;
font-weight: 600;
color: #ffffff;
&:active {
background: $color-primary-dark;
}
&.disabled {
opacity: 0.7;
}
}
.tip {
display: flex;
align-items: flex-start;
gap: 8rpx;
margin-top: 24rpx;
}
.tip-text {
flex: 1;
font-size: 22rpx;
line-height: 1.6;
color: $color-text-muted;
}
</style>