feat 个人中心

This commit is contained in:
Ironsp
2026-10-10 09:57:56 +08:00
parent 53f23d4e69
commit 0f038e7818
35 changed files with 2346 additions and 1656 deletions

View File

@@ -0,0 +1,283 @@
<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { storeToRefs } from 'pinia'
import { ElMessage } from 'element-plus'
import { PasswordStrength } from '@/components'
import { isValidPassword, getPasswordLevel } from '@/utils/validate'
import { useProfileStore } from '@/stores/modules/profile'
import { useCountDown } from '@/composables/useCountDown'
const router = useRouter()
const profileStore = useProfileStore()
const { profile } = storeToRefs(profileStore)
const phone = ref('')
const code = ref('')
const password = ref('')
const confirm = ref('')
const agree = ref(false)
const { seconds, isCounting, start } = useCountDown(60)
function onGetCode(): void {
if (!phone.value) {
ElMessage.warning('请输入手机号')
return
}
start(60)
ElMessage.success('验证码已发送')
}
function onSubmit(): void {
if (!phone.value) {
ElMessage.warning('请输入手机号')
return
}
if (!code.value) {
ElMessage.warning('请输入验证码')
return
}
if (!password.value) {
ElMessage.warning('请输入新密码')
return
}
if (password.value !== confirm.value) {
ElMessage.warning('两次密码不一致')
return
}
if (!isValidPassword(password.value) || getPasswordLevel(password.value) === 'weak') {
ElMessage.warning('密码等级过低,请重新输入')
return
}
if (!agree.value) {
ElMessage.warning('请先阅读并同意《用户协议》和《隐私政策》')
return
}
void profileStore.changePassword({ code: code.value, password: password.value }).then(() => {
void router.push('/profile/security')
})
}
</script>
<template>
<div class="change-pwd-page">
<h2 class="change-pwd-page__title">
修改密码
</h2>
<form class="change-pwd-page__form" @submit.prevent="onSubmit">
<div class="change-pwd-page__field">
<label class="change-pwd-page__label">手机号</label>
<input
v-model="phone"
class="change-pwd-page__input"
type="text"
:placeholder="profile?.phone ?? '请输入手机号'"
maxlength="20"
>
</div>
<div class="change-pwd-page__field">
<label class="change-pwd-page__label">验证码</label>
<div class="change-pwd-page__code">
<input
v-model="code"
class="change-pwd-page__input"
type="text"
placeholder="请输入验证码"
maxlength="6"
>
<button
type="button"
class="change-pwd-page__get-code"
:disabled="isCounting"
@click="onGetCode"
>
{{ isCounting ? `${seconds}秒后重获` : '获取验证码' }}
</button>
</div>
</div>
<div class="change-pwd-page__field">
<label class="change-pwd-page__label">设置密码</label>
<input
v-model="password"
class="change-pwd-page__input"
type="password"
placeholder="请设置8-20位密码"
maxlength="20"
>
<PasswordStrength :password="password" :show-label="false" />
</div>
<div class="change-pwd-page__field change-pwd-page__field--last">
<label class="change-pwd-page__label">确认密码</label>
<input
v-model="confirm"
class="change-pwd-page__input"
type="password"
placeholder="请设置8-20位密码"
maxlength="20"
>
</div>
<label class="change-pwd-page__agree">
<input v-model="agree" type="checkbox">
<span>已阅读并同意<em>《用户协议》</em>和<em>《隐私政策》</em></span>
</label>
<button type="submit" class="change-pwd-page__submit">
确认修改
</button>
</form>
</div>
</template>
<style lang="less" scoped>
.change-pwd-page {
.flex(column, flex-start, stretch);
&__title {
position: relative;
padding-left: 14px;
margin-bottom: 24px;
font-size: @font-size-base;
font-weight: 600;
color: @profile-ink;
line-height: 20px;
&::before {
content: '';
position: absolute;
left: 0;
top: 3px;
width: 4px;
height: 14px;
border-radius: 2px;
background: @primary-strong;
}
}
&__form {
width: 860px;
max-width: 100%;
}
&__field {
.flex(column, flex-start);
margin-bottom: 20px;
&--last {
margin-top: 30px;
}
}
&__label {
margin-bottom: 12px;
font-size: @font-size-sm;
font-weight: 500;
color: @profile-ink;
line-height: 14px;
}
&__input {
width: 100%;
height: 38px;
padding: 0 14px;
border: 1px solid @profile-input-border;
border-radius: @profile-radius;
background: @white;
font-size: 13px;
color: @profile-ink;
outline: none;
transition: border-color 0.2s;
box-sizing: border-box;
&:focus {
border-color: @primary-strong;
}
&::placeholder {
color: @finance-axis-text;
}
}
&__code {
position: relative;
width: 100%;
.change-pwd-page__input {
padding-right: 124px;
}
}
&__get-code {
position: absolute;
top: 0;
right: 0;
width: 107px;
height: 38px;
border: 1px solid @primary-strong;
border-radius: @profile-radius;
background: @white;
color: @primary-strong;
font-size: 13px;
cursor: pointer;
transition: all 0.2s;
&:hover:not(:disabled) {
background: @primary-strong;
color: @white;
}
&:disabled {
border-color: @text-color-disabled;
color: @text-color-disabled;
cursor: not-allowed;
}
}
:deep(.pwd-strength) {
margin-top: 12px;
}
&__agree {
.flex(row, flex-start, center);
gap: 8px;
margin-top: 4px;
font-size: @font-size-sm;
color: @finance-muted-text;
cursor: pointer;
input {
width: 14px;
height: 14px;
accent-color: @primary-strong;
}
em {
font-style: normal;
color: @primary-strong;
}
}
&__submit {
width: 100%;
height: 48px;
margin-top: 18px;
border: none;
border-radius: @profile-radius;
background: @primary-strong;
color: @white;
font-size: @font-size-base;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
&:hover {
background: darken(@primary-strong, 6%);
}
}
}
</style>