标签功能初版实现
This commit is contained in:
@@ -6,72 +6,67 @@
|
||||
<div class="back-btn" @click="handleBackClick">
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
</div>
|
||||
<h1>Product Detail</h1>
|
||||
<h1>{{ product.title || '商品详情' }}</h1>
|
||||
<div class="actions">
|
||||
<el-icon @click="handleFavoriteClick"><Star /></el-icon>
|
||||
<el-icon @click="handleFavoriteClick" :style="{ fontSize: '20px' }" :class="{ active: isFavorite }"><Star /></el-icon>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Product Image -->
|
||||
<div class="product-image" :style="{ backgroundColor: product.bgColor }">
|
||||
<span class="product-letter">{{ product.name[0] }}</span>
|
||||
<div class="product-image-container">
|
||||
<img
|
||||
v-if="product.imageUrls && product.imageUrls.length > 0"
|
||||
:src="product.imageUrls[0]"
|
||||
:alt="product.title"
|
||||
class="product-image"
|
||||
/>
|
||||
<div v-else class="product-image-placeholder">
|
||||
<span class="product-letter">{{ product.title ? product.title[0] : '商' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Product Info -->
|
||||
<div class="product-info">
|
||||
<div class="info-header">
|
||||
<h2 class="product-name">{{ product.name }}</h2>
|
||||
<div class="price-tag">${{ product.price }}</div>
|
||||
<h2 class="product-name">{{ product.title }}</h2>
|
||||
<div class="price-tag">¥{{ product.price }}</div>
|
||||
</div>
|
||||
<div class="rating">
|
||||
<el-rate v-model="product.rating" disabled show-score text-color="#ff9900" />
|
||||
<div class="shop-info">
|
||||
<span class="shop-name">{{ product.shopName }}</span>
|
||||
</div>
|
||||
<div class="product-meta">
|
||||
<div class="duration">
|
||||
<el-icon><Clock /></el-icon>
|
||||
<span>{{ product.approximateDuration }}</span>
|
||||
</div>
|
||||
<div class="stats">
|
||||
<span class="like-count">
|
||||
<el-icon><Star /></el-icon>
|
||||
{{ product.likeCount }} 赞
|
||||
</span>
|
||||
<span class="collect-count">
|
||||
<el-icon><Collection /></el-icon>
|
||||
{{ product.collectCount }} 收藏
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tags">
|
||||
<el-tag v-for="(tag, index) in product.tagList" :key="index" size="small" effect="light" style="margin-right: 8px; margin-bottom: 8px">
|
||||
{{ tag }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<p class="description">{{ product.description }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Size Selection -->
|
||||
<div class="size-section">
|
||||
<h3>Size</h3>
|
||||
<div class="size-options">
|
||||
<div v-for="size in sizes" :key="size"
|
||||
class="size-option"
|
||||
:class="{ active: selectedSize === size }"
|
||||
@click="handleSizeClick(size)">
|
||||
{{ size }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Color Selection -->
|
||||
<div class="color-section">
|
||||
<h3>Color</h3>
|
||||
<div class="color-options">
|
||||
<div v-for="color in colors" :key="color.name"
|
||||
class="color-option"
|
||||
:class="{ active: selectedColor === color.name }"
|
||||
:style="{ backgroundColor: color.value }"
|
||||
@click="handleColorClick(color.name)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quantity -->
|
||||
<div class="quantity-section">
|
||||
<h3>Quantity</h3>
|
||||
<div class="quantity-control">
|
||||
<el-button @click="decreaseQuantity" :disabled="quantity <= 1">-</el-button>
|
||||
<span class="quantity">{{ quantity }}</span>
|
||||
<el-button @click="increaseQuantity">+</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="action-buttons">
|
||||
<el-button class="add-cart-btn" @click="handleAddToCart">
|
||||
Add to Cart
|
||||
<el-icon><ShoppingCart /></el-icon>
|
||||
添加到购物车
|
||||
</el-button>
|
||||
<el-button class="buy-now-btn" type="primary" @click="handleBuyNow">
|
||||
Buy Now
|
||||
<el-icon><Right /></el-icon>
|
||||
立即购买
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -79,94 +74,103 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ArrowLeft, Star } from '@element-plus/icons-vue'
|
||||
import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right } from '@element-plus/icons-vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const product = ref({
|
||||
id: 1,
|
||||
name: 'Watch',
|
||||
price: 40,
|
||||
bgColor: '#ffe4d6',
|
||||
rating: 4.5,
|
||||
description: 'This is a premium quality watch with excellent design and durability. Perfect for any occasion.'
|
||||
const product = ref<ProductVO>({
|
||||
id: 0,
|
||||
shopId: 0,
|
||||
shopName: '',
|
||||
title: '',
|
||||
description: '',
|
||||
imageFileIds: '',
|
||||
imageUrls: [],
|
||||
price: 0,
|
||||
tags: '',
|
||||
tagList: [],
|
||||
likeCount: 0,
|
||||
collectCount: 0,
|
||||
approximateDuration: '',
|
||||
bookableArtists: '',
|
||||
availableCoupons: '',
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
const sizes = ['S', 'M', 'L', 'XL']
|
||||
const colors = [
|
||||
{ name: 'red', value: '#ff6b6b' },
|
||||
{ name: 'blue', value: '#4ecdc4' },
|
||||
{ name: 'black', value: '#2c3e50' },
|
||||
{ name: 'white', value: '#ecf0f1' }
|
||||
]
|
||||
const isFavorite = ref(false)
|
||||
|
||||
const selectedSize = ref('M')
|
||||
const selectedColor = ref('black')
|
||||
const quantity = ref(1)
|
||||
|
||||
onMounted(() => {
|
||||
// 从后端获取商品详情
|
||||
const fetchProductDetail = async () => {
|
||||
const productId = route.params.id
|
||||
console.log('产品ID:', productId)
|
||||
})
|
||||
|
||||
try {
|
||||
const response = await productApi.getProductById(Number(productId))
|
||||
|
||||
// 处理返回的数据
|
||||
const productData = response as any
|
||||
product.value = {
|
||||
...productData,
|
||||
imageUrls: productData.imageUrls || [],
|
||||
tagList: productData.tagList || []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取商品详情失败:', error)
|
||||
ElMessage.error('获取商品详情失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackClick = () => {
|
||||
console.log('返回按钮被点击')
|
||||
router.back()
|
||||
}
|
||||
|
||||
const handleFavoriteClick = () => console.log('收藏按钮被点击')
|
||||
|
||||
const handleSizeClick = (size: string) => {
|
||||
console.log('选择尺码:', size)
|
||||
selectedSize.value = size
|
||||
}
|
||||
|
||||
const handleColorClick = (color: string) => {
|
||||
console.log('选择颜色:', color)
|
||||
selectedColor.value = color
|
||||
}
|
||||
|
||||
const decreaseQuantity = () => {
|
||||
if (quantity.value > 1) {
|
||||
quantity.value--
|
||||
console.log('数量减少:', quantity.value)
|
||||
}
|
||||
}
|
||||
|
||||
const increaseQuantity = () => {
|
||||
quantity.value++
|
||||
console.log('数量增加:', quantity.value)
|
||||
const handleFavoriteClick = () => {
|
||||
isFavorite.value = !isFavorite.value
|
||||
console.log('收藏状态:', isFavorite.value)
|
||||
ElMessage.success(isFavorite.value ? '已收藏' : '已取消收藏')
|
||||
}
|
||||
|
||||
const handleAddToCart = () => {
|
||||
console.log('添加到购物车:', {
|
||||
product: product.value,
|
||||
size: selectedSize.value,
|
||||
color: selectedColor.value,
|
||||
quantity: quantity.value
|
||||
})
|
||||
console.log('添加到购物车:', product.value.title)
|
||||
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
||||
}
|
||||
|
||||
const handleBuyNow = () => {
|
||||
console.log('立即购买:', {
|
||||
product: product.value,
|
||||
size: selectedSize.value,
|
||||
color: selectedColor.value,
|
||||
quantity: quantity.value
|
||||
})
|
||||
console.log('立即购买:', product.value.title)
|
||||
// 这里可以跳转到订单确认页面
|
||||
ElMessage.success('跳转到订单确认页面')
|
||||
}
|
||||
|
||||
// 页面挂载时获取商品详情
|
||||
onMounted(() => {
|
||||
fetchProductDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px 20px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
background: white;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
@@ -174,10 +178,13 @@ const handleBuyNow = () => {
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.actions {
|
||||
width: 40px;
|
||||
display: flex;
|
||||
@@ -186,124 +193,153 @@ const handleBuyNow = () => {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
.actions .active {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.product-image-container {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
background: white;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.product-image-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 80px;
|
||||
font-weight: bold;
|
||||
color: rgba(0,0,0,0.1);
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
.product-info {
|
||||
padding: 20px;
|
||||
background: white;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.info-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
font-size: 24px;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
.price-tag {
|
||||
font-size: 24px;
|
||||
color: var(--primary-color);
|
||||
font-size: 22px;
|
||||
color: #ff4d4f;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rating {
|
||||
margin-bottom: 15px;
|
||||
|
||||
.shop-info {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.shop-name {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
background: #f8f8f8;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.product-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
padding: 12px;
|
||||
background: #f8f8f8;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.duration {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.like-count, .collect-count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.tags {
|
||||
margin-bottom: 16px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.description {
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.size-section, .color-section, .quantity-section {
|
||||
padding: 20px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
.size-section h3, .color-section h3, .quantity-section h3 {
|
||||
margin: 0 0 15px 0;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.size-options {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.size-option {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
.size-option.active {
|
||||
border-color: var(--primary-color);
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.color-options {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
}
|
||||
.color-option {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
border: 3px solid transparent;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
.color-option.active {
|
||||
border-color: var(--primary-color);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.quantity-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
}
|
||||
.quantity {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
min-width: 30px;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
padding-bottom: 20px;
|
||||
background: white;
|
||||
margin-top: 10px;
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
z-index: 90;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.add-cart-btn, .buy-now-btn {
|
||||
flex: 1;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.add-cart-btn {
|
||||
background-color: #f5f5f5;
|
||||
border: none;
|
||||
border: 1px solid #e8e8e8;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.buy-now-btn {
|
||||
background-color: var(--primary-color);
|
||||
background-color: #ff4d4f;
|
||||
border: none;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user