修复一些问题,个人账号功能完善,注册功能完善,收藏,购物车功能完善,初版基本完成,投入测试

This commit is contained in:
xiaowang
2026-03-03 17:50:10 +08:00
parent b301e37468
commit b0470b8f86
23 changed files with 804 additions and 129 deletions
+67 -10
View File
@@ -42,13 +42,13 @@
<!-- 商品图片 -->
<div class="product-img">
<img
v-if="item.image"
:src="item.image"
:alt="item.name"
v-if="getProductImages(item) && getProductImages(item).length > 0"
:src="getProductImages(item)[0]"
:alt="item.title || item.name"
class="product-image"
/>
<div v-else class="product-img-placeholder">
<span>{{ item.name ? item.name[0] : '商' }}</span>
<span>{{ (item.title || item.name) ? (item.title || item.name)[0] : '商' }}</span>
</div>
<a-badge
v-if="item.category"
@@ -59,7 +59,7 @@
</div>
<!-- 商品信息 -->
<div class="product-info">
<p class="name">{{ item.name }}</p>
<p class="name">{{ item.title || item.name }}</p>
<div class="product-meta">
<span class="duration">{{ item.estimatedTime }} 分钟</span>
<div class="stats">
@@ -69,7 +69,28 @@
</div>
<!-- 标签展示 -->
<div class="product-tags">
<template v-if="item.category">
<template v-if="item.tagInfos && item.tagInfos.length > 0">
<a-tag
v-for="tag in item.tagInfos"
:key="tag.id"
size="small"
:style="{
marginRight: '4px',
marginBottom: '4px',
fontSize: '9px',
padding: '1px 6px',
color: tag.textColor || '#333333',
backgroundColor: tag.bgColor || '#F0F0F0',
borderColor: tag.borderColor || '#F0F0F0',
borderWidth: '1px',
borderStyle: 'solid',
borderRadius: '8px'
}"
>
{{ tag.tagName }}
</a-tag>
</template>
<template v-else-if="item.category">
<a-tag
size="small"
:style="{
@@ -136,8 +157,8 @@ import {
import { message } from 'ant-design-vue'
import { productApi, type ProductVO } from '@/api/product'
import { tagApi, type TagVO } from '@/api/tag'
import { cartApi } from '@/api/cart'
import { fileApi } from '@/api/file'
const router = useRouter()
@@ -159,7 +180,10 @@ const hasMore = ref(true)
// 加载状态
const loading = ref(false)
// 图片ID缓存
const imageIdCache = ref<Record<string, string>>({})
const imageUrls = ref<Record<number, string[]>>({})
const DEFAULT_PRODUCT_IMAGE = 'data:image/svg+xml;base64,PHN2ZyB3aW0dPSJodHRwOi8vd3d3Lm9yZy8yMDAwL3N2ZyI+Pjwvc3ZnPg=='
// 从后端获取标签列表
const fetchTags = async () => {
@@ -172,7 +196,38 @@ const fetchTags = async () => {
}
}
// 加载商品图片
const loadImageUrls = async (productList: ProductVO[]) => {
for (const product of productList) {
if (product.imageFileIds) {
const ids = product.imageFileIds.split(',')
const urls: string[] = []
for (const id of ids) {
if (id) {
try {
if (!imageIdCache.value[id]) {
const response = await fileApi.getSignedUrl(Number(id)) as any
imageIdCache.value[id] = response
}
urls.push(imageIdCache.value[id])
} catch (error) {
console.error('获取签名链接失败:', error)
urls.push(DEFAULT_PRODUCT_IMAGE)
}
}
}
imageUrls.value[product.id] = urls
} else {
imageUrls.value[product.id] = [DEFAULT_PRODUCT_IMAGE]
}
}
}
const getProductImages = (product: ProductVO): string[] => {
return imageUrls.value[product.id] || [DEFAULT_PRODUCT_IMAGE]
}
// 从后端获取商品数据
const fetchProducts = async () => {
@@ -191,6 +246,8 @@ const fetchProducts = async () => {
console.log('Products response:', response)
products.value = response || []
await loadImageUrls(products.value)
console.log('Processed products:', products.value)
hasMore.value = false
@@ -226,10 +283,10 @@ const handleProductClick = (item: any) => {
// 处理添加到购物车
const handleAddToCart = async (item: any) => {
console.log('添加到购物车:', item.name)
console.log('添加到购物车:', item.title || item.name)
try {
await cartApi.addToCart({ productId: item.id, quantity: 1 })
message.success(`已将 ${item.name} 添加到购物车`)
message.success(`已将 ${item.title || item.name || '商品'} 添加到购物车`)
} catch (error) {
console.error('添加到购物车失败:', error)
message.error('添加到购物车失败,请重试')