一些问题的修复

This commit is contained in:
xiaowang
2026-03-19 14:10:59 +08:00
parent 580a89c64d
commit 3527e248d1
50 changed files with 847 additions and 165 deletions
@@ -340,6 +340,12 @@ const handleSendVerificationCode = async () => {
return
}
const phoneRegex = /^1[3-9]\d{9}$/
if (!phoneRegex.test(bindPhoneForm.phone)) {
message.error('手机号格式不正确')
return
}
try {
await userApi.sendVerificationCode({ phone: bindPhoneForm.phone })
message.success('验证码发送成功')
@@ -357,6 +363,12 @@ const handleSendChangePhoneVerificationCode = async () => {
return
}
const phoneRegex = /^1[3-9]\d{9}$/
if (!phoneRegex.test(changePhoneForm.newPhone)) {
message.error('手机号格式不正确')
return
}
try {
await userApi.sendVerificationCode({ phone: changePhoneForm.newPhone })
message.success('验证码发送成功')
@@ -374,6 +386,12 @@ const handleSendChangePasswordVerificationCode = async () => {
return
}
const phoneRegex = /^1[3-9]\d{9}$/
if (!phoneRegex.test(userInfo.value.phone)) {
message.error('手机号格式不正确')
return
}
try {
await userApi.sendVerificationCode({ phone: userInfo.value.phone })
message.success('验证码发送成功')
+169 -5
View File
@@ -303,6 +303,85 @@
</div>
</a-form>
</div>
<!-- 忘记密码弹窗 -->
<a-modal
v-model:visible="forgotPasswordVisible"
title="忘记密码"
:footer="null"
width="90%"
:destroyOnClose="true"
>
<a-form
:model="forgotPasswordForm"
:rules="forgotPasswordRules"
@finish="handleResetPassword"
layout="vertical"
>
<a-form-item name="phone" label="手机号">
<a-input
v-model:value="forgotPasswordForm.phone"
placeholder="请输入绑定的手机号"
size="large"
>
<template #prefix>
<UserOutlined style="color: #999" />
</template>
</a-input>
</a-form-item>
<a-form-item name="verificationCode" label="验证码">
<a-input
v-model:value="forgotPasswordForm.verificationCode"
placeholder="请输入验证码"
size="large"
>
<template #prefix>
<LockOutlined style="color: #999" />
</template>
<template #suffix>
<a-button
type="link"
:disabled="forgotCountdown > 0 || !forgotPasswordForm.phone"
@click="handleSendForgotCode"
>
{{ forgotCountdown > 0 ? `${forgotCountdown}秒后重发` : '发送验证码' }}
</a-button>
</template>
</a-input>
</a-form-item>
<a-form-item name="newPassword" label="新密码">
<a-input-password
v-model:value="forgotPasswordForm.newPassword"
placeholder="请输入新密码"
size="large"
>
<template #prefix>
<LockOutlined style="color: #999" />
</template>
</a-input-password>
</a-form-item>
<a-form-item>
<a-button
type="primary"
html-type="submit"
size="large"
block
:loading="resettingPassword"
>
重置密码
</a-button>
</a-form-item>
<a-form-item>
<a-button size="large" block @click="forgotPasswordVisible = false">
取消
</a-button>
</a-form-item>
</a-form>
</a-modal>
</div>
</template>
@@ -327,6 +406,16 @@ const accountStatus = ref<any>(null)
const phoneUserStatus = ref<any>(null)
const countdown = ref(0)
const forgotPasswordVisible = ref(false)
const forgotCountdown = ref(0)
const resettingPassword = ref(false)
const forgotPasswordForm = reactive({
phone: '',
verificationCode: '',
newPassword: ''
})
const formData = reactive({
account: '',
password: '',
@@ -342,6 +431,14 @@ const validatePassword = async (_rule: any, value: string) => {
if (value.length < 6) {
return Promise.reject('密码长度不能少于6位')
}
let count = 0
if (/\d/.test(value)) count++
if (/[a-z]/.test(value)) count++
if (/[A-Z]/.test(value)) count++
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(value)) count++
if (count < 3) {
return Promise.reject('密码必须包含数字、小写字母、大写字母和符号中的至少3种')
}
return Promise.resolve()
}
@@ -357,9 +454,7 @@ const validateConfirmPassword = async (_rule: any, value: string) => {
const rules: Record<string, Rule[]> = {
account: [
{ required: true, message: '请输入账号', trigger: 'blur' },
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' },
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
{ required: true, message: '请输入账号', trigger: 'blur' }
],
phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' },
@@ -379,13 +474,28 @@ const rules: Record<string, Rule[]> = {
],
nickname: [
{ required: true, message: '请输入昵称', trigger: 'blur' },
{ min: 2, max: 20, message: '昵称长度在2到20个字符', trigger: 'blur' }
{ min: 2, max: 20, message: '昵称长度在2到20个字符', trigger: 'blur' },
{ pattern: /^[\u4e00-\u9fa5a-zA-Z0-9_]+$/, message: '昵称不能包含特殊符号', trigger: 'blur' }
],
shopId: [
{ required: true, message: '请选择店铺', trigger: 'change' }
]
}
const forgotPasswordRules: Record<string, Rule[]> = {
phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' },
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
],
verificationCode: [
{ required: true, message: '请输入验证码', trigger: 'blur' },
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
],
newPassword: [
{ required: true, message: '请输入新密码', trigger: 'blur' }
]
}
const fetchShops = async () => {
loadingShops.value = true
try {
@@ -474,7 +584,55 @@ const handleSubmit = async () => {
}
const handleForgotPassword = () => {
message.info('忘记密码功能开发中')
forgotPasswordVisible.value = true
}
const handleSendForgotCode = async () => {
if (!forgotPasswordForm.phone) {
message.error('请输入手机号')
return
}
const phoneRegex = /^1[3-9]\d{9}$/
if (!phoneRegex.test(forgotPasswordForm.phone)) {
message.error('手机号格式不正确')
return
}
try {
await authApi.sendVerificationCode({ phone: forgotPasswordForm.phone })
message.success('验证码已发送')
forgotCountdown.value = 60
const timer = setInterval(() => {
forgotCountdown.value--
if (forgotCountdown.value <= 0) {
clearInterval(timer)
}
}, 1000)
} catch (error: any) {
message.error(error.response?.data?.message || '发送验证码失败')
}
}
const handleResetPassword = async () => {
resettingPassword.value = true
try {
await authApi.resetPasswordByPhone({
phone: forgotPasswordForm.phone,
verificationCode: forgotPasswordForm.verificationCode,
newPassword: forgotPasswordForm.newPassword
})
message.success('密码重置成功,请使用新密码登录')
forgotPasswordVisible.value = false
forgotPasswordForm.phone = ''
forgotPasswordForm.verificationCode = ''
forgotPasswordForm.newPassword = ''
} catch (error: any) {
message.error(error.response?.data?.message || '重置密码失败')
} finally {
resettingPassword.value = false
}
}
const handleWeChatLogin = () => {
@@ -542,6 +700,12 @@ const handleSendVerificationCode = async () => {
return
}
const phoneRegex = /^1[3-9]\d{9}$/
if (!phoneRegex.test(formData.phone)) {
message.error('手机号格式不正确')
return
}
try {
await userApi.sendVerificationCode({ phone: formData.phone })
message.success('验证码已发送')
+144 -58
View File
@@ -42,6 +42,18 @@
<h3 class="item-name" @click="handleProductClick(item)" style="cursor: pointer;">{{ item.productTitle }}</h3>
<p class="item-price">¥{{ item.price.toFixed(2) }}</p>
<!-- 美甲师选择 -->
<div class="artist-selector" @click="showArtistSelection(item)">
<span v-if="item.artist" class="selected-artist">
<img v-if="item.artist.avatar" :src="item.artist.avatar" class="artist-avatar-small" />
<span class="artist-name">{{ item.artist.name }}</span>
</span>
<span v-else class="select-artist">
选择美甲师
</span>
<RightOutlined class="arrow-icon" />
</div>
<!-- 数量控制和删除按钮 -->
<div class="item-actions">
<div class="quantity-control">
@@ -83,7 +95,7 @@
<div class="coupon-header" @click="showCouponModal = true">
<span class="coupon-title">优惠券</span>
<div class="coupon-value">
{{ selectedCoupon ? '已选择: ' + selectedCoupon.couponName : '请选择' }}
{{ selectedCoupon ? selectedCoupon.couponName : '使用优惠券' }}
<RightOutlined :style="{ marginLeft: '4px' }" />
</div>
</div>
@@ -122,14 +134,14 @@
block
@click="handleCheckout"
>
结算 ({{ selectedCount }}) - ¥{{ totalAmount.toFixed(2) }}
确认 {{ selectedCount }} 笔订单- 预计金额 ¥{{ totalAmount.toFixed(2) }}
</a-button>
</div>
<!-- 优惠券选择弹窗 -->
<a-modal
v-model:visible="showCouponModal"
title="选择优惠券"
title="使用优惠券"
width="90%"
@ok="confirmCouponSelection"
@cancel="cancelCouponSelection"
@@ -192,11 +204,10 @@
<!-- 美甲师选择弹窗 -->
<a-modal
v-model:visible="showArtistModal"
title="选择美甲师"
:title='currentEditingItem ? `为"${currentEditingItem.productTitle}"选择美甲师` : "选择美甲师"'
width="90%"
@ok="selectArtistAndCheckout"
@ok="confirmArtistSelection"
@cancel="closeArtistModal"
>
<div class="artist-modal-content">
<a-empty v-if="availableArtists.length === 0" description="暂无可用美甲师" />
@@ -206,8 +217,8 @@
v-for="artist in availableArtists"
:key="artist.id"
class="artist-item"
:class="{ 'selected': selectedArtist && selectedArtist.id === artist.id }"
@click="toggleArtistSelection(artist)"
:class="{ 'selected': currentEditingItem && currentEditingItem.artistId === artist.id }"
@click="selectArtist(artist)"
>
<div class="artist-card">
<div class="artist-avatar">
@@ -238,7 +249,7 @@
<span class="skill-tag" v-for="skill in getArtistSkills(artist)" :key="skill">{{ skill }}</span>
</div>
</div>
<div class="artist-selection-indicator" v-if="selectedArtist && selectedArtist.id === artist.id">
<div class="artist-selection-indicator" v-if="currentEditingItem && currentEditingItem.artistId === artist.id">
<CheckCircleOutlined style="color: #1890ff; font-size: 20px;" />
</div>
</div>
@@ -283,6 +294,18 @@ interface CartItem {
totalPrice: number
tags: string
selected: boolean
artistId?: number
artist?: {
id: number
name: string
avatar?: string
signature?: string
shopName?: string
status?: number
experience?: number
skills?: string
rating?: number
}
}
const router = useRouter()
@@ -516,7 +539,7 @@ const cancelCouponSelection = () => {
// 美甲师选择相关状态
const showArtistModal = ref(false)
const selectedArtist = ref<{id: number, name: string, avatar?: string, signature?: string, shopName?: string, status?: number, experience?: number, skills?: string, rating?: number} | null>(null)
const currentEditingItem = ref<CartItem | null>(null)
const availableArtists = ref<{id: number, name: string, avatar?: string, signature?: string, shopName?: string, status?: number, experience?: number, skills?: string, rating?: number}[]>([])
// 标签列表
const tagList = ref<TagVO[]>([])
@@ -592,28 +615,30 @@ const handleCheckout = async () => {
return
}
// 加载可用美甲师
await loadAvailableArtists()
// 显示美甲师选择弹窗
showArtistModal.value = true
}
// 选择美甲师并创建订单
const selectArtistAndCheckout = async () => {
if (!selectedArtist.value) {
message.warning('请选择美甲师')
// 检查所有选中的作品是否都选择了美甲师
const itemsWithoutArtist = selectedItems.filter(item => !item.artistId)
if (itemsWithoutArtist.length > 0) {
message.warning(`请为"${itemsWithoutArtist.map(item => item.productTitle).join('、')}"选择美甲师`)
return
}
// 创建订单
try {
await orderApi.createOrder({
couponId: selectedCoupon.value ? selectedCoupon.value.id : undefined,
artistId: selectedArtist.value.id
items: selectedItems.map(item => ({
productId: item.productId,
quantity: item.quantity,
artistId: item.artistId
}))
})
message.success('订单创建成功')
showArtistModal.value = false
// 更新购物车数量(因为订单创建后购物车会被清空)
// 从购物车中移除已购买的商品
const selectedIds = selectedItems.map(item => item.id)
await cartApi.batchRemoveFromCart(selectedIds)
// 更新购物车数据
await loadCartItems()
// 更新购物车数量
await updateCartCount()
router.push('/profile')
} catch (error) {
@@ -621,10 +646,31 @@ const selectArtistAndCheckout = async () => {
}
}
// 显示美甲师选择弹窗
const showArtistSelection = (item: CartItem) => {
currentEditingItem.value = item
loadAvailableArtists()
showArtistModal.value = true
}
// 选择美甲师
const selectArtist = (artist: any) => {
if (currentEditingItem.value) {
currentEditingItem.value.artistId = artist.id
currentEditingItem.value.artist = artist
}
}
// 确认选择
const confirmArtistSelection = () => {
showArtistModal.value = false
currentEditingItem.value = null
}
// 关闭美甲师选择弹窗
const closeArtistModal = () => {
showArtistModal.value = false
selectedArtist.value = null
currentEditingItem.value = null
}
// 获取美甲师头像
@@ -670,17 +716,6 @@ const getArtistSkills = (artist: any) => {
})
}
// 切换美甲师选择状态
const toggleArtistSelection = (artist: any) => {
if (selectedArtist.value && selectedArtist.value.id === artist.id) {
// 取消选择
selectedArtist.value = null
} else {
// 选择新的美甲师
selectedArtist.value = artist
}
}
// 监听选中作品变化,重新加载可用优惠券
watch(
() => cartItems.value.map(item => ({ id: item.id, selected: item.selected, quantity: item.quantity })),
@@ -807,6 +842,55 @@ onMounted(() => {
font-size: 16px;
}
.artist-selector {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px;
background: #f8f9ff;
border-radius: 8px;
margin-bottom: 10px;
cursor: pointer;
transition: all 0.3s ease;
}
.artist-selector:hover {
background: #e6f7ff;
}
.selected-artist {
display: flex;
align-items: center;
gap: 8px;
color: #1890ff;
font-weight: 500;
}
.artist-avatar-small {
width: 24px;
height: 24px;
border-radius: 50%;
object-fit: cover;
}
.select-artist {
color: #999;
font-size: 13px;
display: flex;
align-items: center;
gap: 4px;
}
.arrow-icon {
color: #999;
font-size: 12px;
transition: transform 0.3s ease;
}
.artist-selector:hover .arrow-icon {
transform: translateX(4px);
}
.item-duration {
color: #666;
font-size: 13px;
@@ -907,7 +991,7 @@ onMounted(() => {
display: flex;
justify-content: space-between;
align-items: center;
padding: 18px 20px;
padding: 12px 16px;
cursor: pointer;
background: linear-gradient(135deg, #f6f9ff 0%, #ffffff 100%);
border-bottom: 1px solid #e6f7ff;
@@ -918,29 +1002,29 @@ onMounted(() => {
}
.coupon-title {
font-size: 16px;
font-size: 14px;
font-weight: 600;
color: #333;
display: flex;
align-items: center;
gap: 8px;
gap: 6px;
}
.coupon-title::before {
content: "🎁";
font-size: 18px;
font-size: 14px;
}
.coupon-value {
font-size: 13px;
font-size: 12px;
font-weight: 500;
color: #1890ff;
display: flex;
align-items: center;
gap: 6px;
padding: 6px 12px;
gap: 4px;
padding: 4px 10px;
background: rgba(24, 144, 255, 0.1);
border-radius: 20px;
border-radius: 16px;
transition: all 0.3s ease;
box-shadow: 0 1px 3px rgba(24, 144, 255, 0.2);
}
@@ -952,7 +1036,7 @@ onMounted(() => {
}
.coupon-discount {
padding: 14px 20px;
padding: 10px 16px;
background-color: #f0f9ff;
border-top: 1px solid #e6f7ff;
display: flex;
@@ -961,20 +1045,20 @@ onMounted(() => {
}
.discount-label {
font-size: 14px;
font-size: 12px;
color: #666;
display: flex;
align-items: center;
gap: 6px;
gap: 4px;
}
.discount-label::before {
content: "💰";
font-size: 14px;
font-size: 12px;
}
.discount-amount {
font-size: 18px;
font-size: 16px;
font-weight: 700;
color: #1890ff;
text-shadow: 0 1px 2px rgba(24, 144, 255, 0.3);
@@ -1014,15 +1098,17 @@ onMounted(() => {
.coupon-content {
display: flex;
align-items: center;
padding: 16px;
gap: 16px;
padding: 10px;
gap: 10px;
}
.coupon-value {
font-size: 24px;
font-size: 18px;
font-weight: 600;
color: #ff4d4f;
flex-shrink: 0;
min-width: 50px;
text-align: center;
}
.coupon-info {
@@ -1031,29 +1117,29 @@ onMounted(() => {
}
.coupon-name {
font-size: 15px;
font-size: 13px;
font-weight: 600;
color: #333;
margin-bottom: 4px;
margin-bottom: 2px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.coupon-condition {
font-size: 13px;
font-size: 11px;
color: #666;
margin-bottom: 4px;
margin-bottom: 2px;
}
.coupon-time {
font-size: 12px;
font-size: 10px;
color: #999;
}
.coupon-select {
color: #1890ff;
font-size: 20px;
font-size: 16px;
flex-shrink: 0;
}
+19
View File
@@ -33,6 +33,10 @@
<div class="item-info">
<div class="item-title">{{ item.productTitle }}</div>
<div class="item-price">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
<div v-if="item.artistName" class="item-artist">
<img v-if="item.artistAvatar" :src="item.artistAvatar" class="artist-avatar-small" />
<span>美甲师: {{ item.artistName }}</span>
</div>
</div>
</div>
</div>
@@ -299,6 +303,21 @@ onMounted(() => {
color: #666;
}
.item-artist {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: #1890ff;
}
.artist-avatar-small {
width: 20px;
height: 20px;
border-radius: 50%;
object-fit: cover;
}
.order-footer {
display: flex;
justify-content: space-between;
+3 -3
View File
@@ -8,7 +8,7 @@
</div>
<h1>{{ product.name || '作品详情' }}</h1>
<div class="actions">
<el-icon @click="handleFavoriteClick" :style="{ fontSize: '20px' }" :class="{ active: isFavorite }"><Star /></el-icon>
<el-icon @click="handleFavoriteClick" :style="{ fontSize: '20px' }" :class="{ active: isFavorite }"><StarFilled /></el-icon>
</div>
</header>
@@ -115,7 +115,7 @@
<script setup lang="ts">
import { ref, onMounted, inject } from 'vue'
import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right } from '@element-plus/icons-vue'
import { ArrowLeft, StarFilled, Clock, Collection, ShoppingCart, Right } from '@element-plus/icons-vue'
import { Icon } from '@iconify/vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
@@ -388,7 +388,7 @@ onMounted(() => {
}
.actions .el-icon.active {
color: #f56c6c;
color: #fadb14;
}
.product-image-container {
+2 -2
View File
@@ -36,7 +36,7 @@
<!-- Empty Wishlist Message -->
<div v-if="wishlistItems.length === 0" class="empty-wishlist">
<el-icon :size="60"><Star /></el-icon>
<el-icon :size="60" :style="{ color: '#fadb14' }"><StarFilled /></el-icon>
<p>收藏列表为空</p>
<el-button type="primary" @click="handleBrowseProducts">
浏览作品
@@ -47,7 +47,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ArrowLeft, Delete, Star } from '@element-plus/icons-vue'
import { ArrowLeft, Delete, StarFilled } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { wishlistApi, type WishlistItem } from '@/api/wishlist'