杂务:打包并提交当前改动

This commit is contained in:
xiaowang
2026-03-19 20:51:07 +08:00
parent de50394960
commit 8330ea1c83
47 changed files with 1190 additions and 450 deletions
+96 -27
View File
@@ -1,6 +1,5 @@
<template>
<div class="mobile-container">
<!-- 头部区域 -->
<header class="header">
<a-button class="back-btn" type="text" @click="handleBackClick">
<LeftOutlined :style="{ fontSize: '20px' }" />
@@ -9,7 +8,6 @@
<div class="empty"></div>
</header>
<!-- 密码设置表单 -->
<div class="password-form">
<a-card :bordered="false" class="form-card">
<a-form
@@ -19,6 +17,28 @@
layout="vertical"
@finish="handleSubmit"
>
<a-form-item label="手机号">
<a-input :value="userPhone || '未绑定手机号'" disabled size="large" />
</a-form-item>
<a-form-item label="验证码" name="verificationCode">
<a-input
v-model:value="formState.verificationCode"
placeholder="请输入验证码"
size="large"
>
<template #suffix>
<a-button
type="link"
:disabled="countdown > 0 || !userPhone"
@click="handleSendVerificationCode"
>
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
</a-button>
</template>
</a-input>
</a-form-item>
<a-form-item label="新密码" name="password">
<a-input-password
v-model:value="formState.password"
@@ -31,7 +51,7 @@
</template>
</a-input-password>
<div class="password-tip">
密码长度至少8位,包含字母和数字
密码长度至少 8 位,且需包含字母和数字
</div>
</a-form-item>
@@ -66,7 +86,7 @@
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue'
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { LeftOutlined, LockOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
@@ -77,12 +97,18 @@ import { userApi } from '@/api/user'
const router = useRouter()
const formRef = ref<FormInstance>()
const loading = ref(false)
const countdown = ref(0)
const userInfo = ref<{ phone?: string } | null>(null)
let countdownTimer: ReturnType<typeof setInterval> | null = null
const formState = reactive({
verificationCode: '',
password: '',
confirmPassword: ''
})
const userPhone = computed(() => userInfo.value?.phone || '')
const validateConfirmPassword = (_rule: any, value: string) => {
if (value !== formState.password) {
return Promise.reject(new Error('两次输入的密码不一致'))
@@ -91,6 +117,10 @@ const validateConfirmPassword = (_rule: any, value: string) => {
}
const formRules: Record<string, Rule[]> = {
verificationCode: [
{ required: true, message: '请输入验证码', trigger: 'blur' },
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
],
password: [
{ required: true, message: '请输入新密码', trigger: 'blur' },
{ min: 8, message: '密码长度至少8位', trigger: 'blur' },
@@ -102,21 +132,64 @@ const formRules: Record<string, Rule[]> = {
]
}
const startCountdown = () => {
countdown.value = 60
if (countdownTimer) {
clearInterval(countdownTimer)
}
countdownTimer = setInterval(() => {
countdown.value -= 1
if (countdown.value <= 0 && countdownTimer) {
clearInterval(countdownTimer)
countdownTimer = null
}
}, 1000)
}
const fetchUserInfo = async () => {
try {
const res = await userApi.getUserInfo()
userInfo.value = res as unknown as { phone?: string }
} catch (error: any) {
console.error('获取用户信息失败:', error)
message.error(error.message || '获取用户信息失败')
}
}
const handleSendVerificationCode = async () => {
if (!userPhone.value) {
message.error('请先绑定手机号')
return
}
try {
await userApi.sendVerificationCode({ phone: userPhone.value })
message.success('验证码发送成功')
startCountdown()
} catch (error: any) {
console.error('发送验证码失败:', error)
message.error(error.message || '发送验证码失败')
}
}
const handleSubmit = async () => {
if (!formRef.value) return
try {
await formRef.value.validate()
if (!userPhone.value) {
message.error('请先绑定手机号')
return
}
loading.value = true
await userApi.updatePassword({
password: formState.password
password: formState.password,
verificationCode: formState.verificationCode
})
message.success('密码设置成功')
// 清除需要设置密码的标识
localStorage.removeItem('needSetPassword')
// 跳转回个人中心
router.push('/profile')
} catch (error: any) {
console.error('设置密码失败:', error)
@@ -129,6 +202,16 @@ const handleSubmit = async () => {
const handleBackClick = () => {
router.back()
}
onMounted(() => {
fetchUserInfo()
})
onUnmounted(() => {
if (countdownTimer) {
clearInterval(countdownTimer)
}
})
</script>
<style scoped>
@@ -171,23 +254,9 @@ const handleBackClick = () => {
background: white;
}
.form-card :deep(.ant-card-body) {
padding: 24px;
}
.password-tip {
font-size: 12px;
color: #999;
margin-top: 8px;
color: #999;
font-size: 12px;
}
.form-card :deep(.ant-btn-primary) {
height: 48px;
border-radius: 12px;
font-size: 15px;
font-weight: 600;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
</style>
</style>