From 98c9463efacf78e5d30fcd5451d14a039f6cbc4f Mon Sep 17 00:00:00 2001 From: xiaowang Date: Thu, 26 Feb 2026 11:16:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=B1=95=E7=A4=BA=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E5=BC=A0=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/src/api/index.ts | 8 ++ Frontend/src/views/ProductDetailView.vue | 126 +++++++++++++++++- Frontend/src/views/ProductListView.vue | 46 ++++++- Frontend/src/views/admin/ProductsView.vue | 80 +++++++---- .../xiaowang/yuminailcore/utils/JwtUtil.java | 2 +- 5 files changed, 228 insertions(+), 34 deletions(-) diff --git a/Frontend/src/api/index.ts b/Frontend/src/api/index.ts index 777b0764..148f5056 100644 --- a/Frontend/src/api/index.ts +++ b/Frontend/src/api/index.ts @@ -138,4 +138,12 @@ api.interceptors.response.use( } ) +export const fileApi = { + getSignedUrl: (fileId: number, expiryTimeInMinutes?: number) => { + return api.get(`/file/get-signed-url/${fileId}`, { + params: { expiryTimeInMinutes } + }) + } +} + export default api diff --git a/Frontend/src/views/ProductDetailView.vue b/Frontend/src/views/ProductDetailView.vue index da10814e..e9a5f71b 100644 --- a/Frontend/src/views/ProductDetailView.vue +++ b/Frontend/src/views/ProductDetailView.vue @@ -12,14 +12,32 @@ - +
- + +
{{ product.title ? product.title[0] : '商' }}
@@ -78,6 +96,7 @@ import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right } from '@elemen import { useRouter, useRoute } from 'vue-router' import { ElMessage } from 'element-plus' import { productApi, type ProductVO } from '@/api/product' +import { fileApi } from '@/api/index' const router = useRouter() const route = useRoute() @@ -103,6 +122,9 @@ const product = ref({ }) const isFavorite = ref(false) +const currentImageIndex = ref(0) +const productImages = ref([]) +const imageIdCache = ref>({}) // 从后端获取商品详情 const fetchProductDetail = async () => { @@ -119,12 +141,46 @@ const fetchProductDetail = async () => { imageUrls: productData.imageUrls || [], tagList: productData.tagList || [] } + + // 加载所有图片的签名链接 + await loadProductImages() } catch (error) { console.error('获取商品详情失败:', error) ElMessage.error('未登录,请先登录') } } +// 加载商品图片 +const loadProductImages = async () => { + if (product.value.imageFileIds) { + const ids = product.value.imageFileIds.split(',') + const urls: string[] = [] + + for (const id of ids) { + if (id) { + try { + // 检查缓存 + if (!imageIdCache.value[id]) { + const signedUrl = await fileApi.getSignedUrl(Number(id)) + imageIdCache.value[id] = signedUrl + } + urls.push(imageIdCache.value[id]) + } catch (error) { + console.error('获取签名链接失败:', error) + } + } + } + + productImages.value = urls + currentImageIndex.value = 0 + } +} + +// 处理图片点击 +const handleImageClick = (index: number) => { + currentImageIndex.value = index +} + const handleBackClick = () => { console.log('返回按钮被点击') router.back() @@ -202,6 +258,38 @@ onMounted(() => { height: 300px; background: white; position: relative; + overflow: hidden; +} + +.image-carousel { + width: 100%; + height: 100%; + position: relative; + display: flex; + overflow-x: auto; + scroll-snap-type: x mandatory; + scrollbar-width: none; +} + +.image-carousel::-webkit-scrollbar { + display: none; +} + +.carousel-item { + flex: 0 0 auto; + width: 100%; + height: 100%; + scroll-snap-align: start; + cursor: pointer; + transition: opacity 0.3s; +} + +.carousel-item.active { + opacity: 1; +} + +.carousel-item:not(.active) { + opacity: 0.6; } .product-image { @@ -210,6 +298,30 @@ onMounted(() => { object-fit: cover; } +.carousel-indicators { + position: absolute; + bottom: 12px; + left: 50%; + transform: translateX(-50%); + display: flex; + gap: 8px; +} + +.indicator { + width: 8px; + height: 8px; + border-radius: 50%; + background: rgba(255, 255, 255, 0.5); + cursor: pointer; + transition: all 0.3s; +} + +.indicator.active { + background: white; + width: 24px; + border-radius: 4px; +} + .product-image-placeholder { width: 100%; height: 100%; diff --git a/Frontend/src/views/ProductListView.vue b/Frontend/src/views/ProductListView.vue index 76923930..d321cb9b 100644 --- a/Frontend/src/views/ProductListView.vue +++ b/Frontend/src/views/ProductListView.vue @@ -42,8 +42,8 @@
@@ -138,6 +138,7 @@ import { import { message } from 'ant-design-vue' import { productApi, type ProductVO } from '@/api/product' import { tagApi, type TagVO } from '@/api/tag' +import { fileApi } from '@/api/index' const router = useRouter() @@ -159,6 +160,10 @@ const hasMore = ref(true) // 加载状态 const loading = ref(false) +// 图片缓存 +const imageIdCache = ref>({}) +const productImagesCache = ref>({}) + // 从后端获取标签列表 const fetchTags = async () => { try { @@ -200,6 +205,9 @@ const fetchProducts = async () => { console.log('Processed products:', products.value) + // 预加载所有商品的图片 + await loadProductImages(products.value) + hasMore.value = false } catch (error) { console.error('获取商品失败:', error) @@ -209,6 +217,40 @@ const fetchProducts = async () => { } } +// 加载商品图片 +const loadProductImages = async (products: ProductVO[]) => { + for (const product of products) { + if (product.imageFileIds) { + const ids = product.imageFileIds.split(',') + const urls: string[] = [] + + for (const id of ids) { + if (id) { + try { + // 检查缓存 + if (!imageIdCache.value[id]) { + const signedUrl = await fileApi.getSignedUrl(Number(id)) + imageIdCache.value[id] = signedUrl + } + urls.push(imageIdCache.value[id]) + } catch (error) { + console.error('获取签名链接失败:', error) + } + } + } + + productImagesCache.value[product.id] = urls + } else { + productImagesCache.value[product.id] = [] + } + } +} + +// 获取商品图片 +const getProductImages = (product: ProductVO): string[] => { + return productImagesCache.value[product.id] || [] +} + // 处理返回按钮点击 const handleBackClick = () => { console.log('返回按钮被点击') diff --git a/Frontend/src/views/admin/ProductsView.vue b/Frontend/src/views/admin/ProductsView.vue index 479a7745..4ea3202b 100644 --- a/Frontend/src/views/admin/ProductsView.vue +++ b/Frontend/src/views/admin/ProductsView.vue @@ -30,12 +30,25 @@ >