feat: 商品详情页图片缩放显示改进
- 添加缩略图列表切换功能 - 点击主图可放大预览 - 添加缩放提示文字 - 优化移动端样式 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,26 +5,39 @@
|
||||
<el-row :gutter="32">
|
||||
<el-col :span="12">
|
||||
<div class="product-images">
|
||||
<el-carousel v-if="productImages.length > 1" height="400px" :autoplay="false" indicator-position="outside">
|
||||
<el-carousel-item v-for="(img, index) in productImages" :key="index">
|
||||
<el-image :src="img" fit="contain" class="carousel-image" :preview-src-list="productImages" :initial-index="index">
|
||||
<!-- 主图显示 -->
|
||||
<div class="main-image-wrap">
|
||||
<el-image
|
||||
:src="currentImage"
|
||||
fit="contain"
|
||||
class="main-image"
|
||||
:preview-src-list="productImages"
|
||||
:initial-index="currentImageIndex"
|
||||
:z-index="9999"
|
||||
>
|
||||
<template #error>
|
||||
<div class="image-placeholder">
|
||||
<el-icon size="80"><Goods /></el-icon>
|
||||
</div>
|
||||
</template>
|
||||
</el-image>
|
||||
</el-carousel-item>
|
||||
</el-carousel>
|
||||
<el-image v-else-if="productImages.length === 1" :src="productImages[0]" fit="contain" class="single-image" :preview-src-list="productImages">
|
||||
<template #error>
|
||||
<div class="image-placeholder">
|
||||
<el-icon size="80"><Goods /></el-icon>
|
||||
</div>
|
||||
</template>
|
||||
</el-image>
|
||||
<div v-else class="image-placeholder">
|
||||
<el-icon size="80"><Goods /></el-icon>
|
||||
<!-- 缩略图列表 -->
|
||||
<div class="thumbnail-list" v-if="productImages.length > 1">
|
||||
<div
|
||||
v-for="(img, index) in productImages"
|
||||
:key="index"
|
||||
class="thumbnail-item"
|
||||
:class="{ active: currentImageIndex === index }"
|
||||
@click="currentImageIndex = index"
|
||||
>
|
||||
<el-image :src="img" fit="cover" class="thumbnail-image" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- 单图提示 -->
|
||||
<div class="image-tip" v-if="productImages.length > 0">
|
||||
<el-icon><ZoomIn /></el-icon>
|
||||
<span>点击图片放大查看</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
@@ -65,7 +78,7 @@
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Goods } from '@element-plus/icons-vue'
|
||||
import { Goods, ZoomIn } from '@element-plus/icons-vue'
|
||||
import { productApi, userApi } from '../../api'
|
||||
import { useCartStore } from '../../store/cart'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -79,12 +92,17 @@ const cartStore = useCartStore()
|
||||
const product = ref<any>(null)
|
||||
const quantity = ref(1)
|
||||
const userCredits = ref(0)
|
||||
const currentImageIndex = ref(0)
|
||||
|
||||
const productImages = computed(() => {
|
||||
if (!product.value?.images) return []
|
||||
return product.value.images.split(',').map((s: string) => s.trim()).filter(Boolean).map((url: string) => getImageUrl(url))
|
||||
})
|
||||
|
||||
const currentImage = computed(() => {
|
||||
return productImages.value[currentImageIndex.value] || ''
|
||||
})
|
||||
|
||||
// 检查用户是否有足够资格购买
|
||||
function hasEnoughCredit(): boolean {
|
||||
if (!product.value || !product.value.require_credit) return true
|
||||
@@ -139,17 +157,68 @@ function buyNow() {
|
||||
.product-detail-page { padding: 0; }
|
||||
.detail-card { background: #2d2d44; border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 32px; }
|
||||
.product-images {
|
||||
height: 400px;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
|
||||
.carousel-image, .single-image {
|
||||
width: 100%;
|
||||
.main-image-wrap {
|
||||
height: 400px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
|
||||
.main-image {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.thumbnail-list {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding: 12px;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
|
||||
.thumbnail-item {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
border: 2px solid transparent;
|
||||
transition: all 0.2s;
|
||||
opacity: 0.6;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
&.active {
|
||||
border-color: #4e6ef2;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.thumbnail-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.image-tip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
padding: 8px;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
font-size: 12px;
|
||||
|
||||
.el-icon {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.image-placeholder {
|
||||
@@ -208,15 +277,16 @@ h1 { font-size: 28px; color: #fff; margin-bottom: 16px; }
|
||||
}
|
||||
|
||||
.product-images {
|
||||
.main-image-wrap {
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
.carousel-image, .single-image {
|
||||
height: 300px;
|
||||
.thumbnail-list {
|
||||
.thumbnail-item {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
}
|
||||
|
||||
.image-placeholder {
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
|
||||
Reference in New Issue
Block a user