修复一些问题,优化前后端交互接口格式,优化首页轮播图图的维护
This commit is contained in:
+121
-18
@@ -38,17 +38,24 @@
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<!-- Banner 区域 -->
|
||||
<div class="banner" @click="handleBannerClick">
|
||||
<div class="banner-content">
|
||||
<a-tag color="red" class="banner-tag">限时优惠</a-tag>
|
||||
<h3>Get Winter Discount</h3>
|
||||
<h2>20% Off</h2>
|
||||
<p>For Children</p>
|
||||
<a-button type="primary" size="small" class="banner-btn">立即购买</a-button>
|
||||
</div>
|
||||
<div class="banner-image">
|
||||
<div class="img-placeholder">Banner</div>
|
||||
<!-- Banner 轮播区域 -->
|
||||
<div class="banner-carousel">
|
||||
<a-carousel v-if="bannerImages.length > 0" autoplay :autoplay-speed="3000" effect="fade">
|
||||
<div v-for="(image, index) in bannerImages" :key="index" class="banner-slide" @click="handleBannerClick">
|
||||
<img :src="image" alt="Banner" class="banner-img" />
|
||||
</div>
|
||||
</a-carousel>
|
||||
<div v-else class="banner" @click="handleBannerClick">
|
||||
<div class="banner-content">
|
||||
<a-tag color="red" class="banner-tag">限时优惠</a-tag>
|
||||
<h3>Get Winter Discount</h3>
|
||||
<h2>20% Off</h2>
|
||||
<p>For Children</p>
|
||||
<a-button type="primary" size="small" class="banner-btn">立即购买</a-button>
|
||||
</div>
|
||||
<div class="banner-image">
|
||||
<div class="img-placeholder">Banner</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -130,6 +137,8 @@ import {
|
||||
} from '@ant-design/icons-vue'
|
||||
import { userApi, type UserVO } from '../api/user'
|
||||
import { productApi } from '../api/product'
|
||||
import { shopApi, type ShopVO } from '../api/shop'
|
||||
import { fileApi } from '../api/file'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
@@ -148,6 +157,9 @@ const userInfo = ref<UserVO>({
|
||||
// 搜索关键词
|
||||
const searchQuery = ref('')
|
||||
|
||||
// Banner图片数据
|
||||
const bannerImages = ref<string[]>([])
|
||||
|
||||
// 精选商品数据
|
||||
const featuredItems = ref<any[]>([])
|
||||
|
||||
@@ -168,6 +180,56 @@ const loadUserInfo = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载Banner图片
|
||||
const loadBannerImages = async () => {
|
||||
try {
|
||||
const fileIdPromises: Promise<string>[] = []
|
||||
|
||||
// 从店铺获取图片
|
||||
const shops = await shopApi.getAllShops() as ShopVO[]
|
||||
console.log('店铺数量:', shops.length)
|
||||
console.log('店铺数据:', shops)
|
||||
|
||||
// 处理店铺图片 - 只使用coverImageFileId(banner图片)
|
||||
for (const shop of shops) {
|
||||
// 处理coverImageFileId(专门用于banner的图片)
|
||||
if (shop.coverImageFileId) {
|
||||
const fileIds = shop.coverImageFileId.split(',').filter(id => id.trim())
|
||||
for (const idStr of fileIds) {
|
||||
const fileId = parseInt(idStr)
|
||||
if (!isNaN(fileId)) {
|
||||
const promise = fileApi.getSignedUrl(fileId).catch(err => {
|
||||
console.error('获取店铺banner图签名失败:', err)
|
||||
return null
|
||||
})
|
||||
fileIdPromises.push(promise)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 并行请求所有签名URL
|
||||
const results = await Promise.all(fileIdPromises)
|
||||
console.log('原始请求结果:', results)
|
||||
|
||||
// 过滤掉null值并去除反引号
|
||||
const filteredResults = results.filter((url): url is string => url !== null).map(url => url.replace(/[`]/g, '').trim())
|
||||
console.log('过滤后结果:', filteredResults)
|
||||
|
||||
// 去重
|
||||
const uniqueImages = [...new Set(filteredResults)]
|
||||
console.log('去重后结果:', uniqueImages)
|
||||
console.log('去重后数量:', uniqueImages.length)
|
||||
|
||||
// 限制数量并更新bannerImages
|
||||
bannerImages.value = uniqueImages.slice(0, 10) // 最多显示10张
|
||||
console.log('Banner图片数量:', bannerImages.value.length)
|
||||
console.log('Banner图片列表:', bannerImages.value)
|
||||
} catch (error) {
|
||||
console.error('获取Banner图片失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载精选商品
|
||||
const loadFeaturedProducts = async () => {
|
||||
try {
|
||||
@@ -245,6 +307,7 @@ const handleScroll = () => {
|
||||
// 添加滚动监听
|
||||
onMounted(() => {
|
||||
loadUserInfo()
|
||||
loadBannerImages()
|
||||
loadFeaturedProducts()
|
||||
loadPopularProducts()
|
||||
window.addEventListener('scroll', handleScroll)
|
||||
@@ -261,13 +324,6 @@ const getRandomColor = () => {
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
// 页面加载时获取数据
|
||||
onMounted(() => {
|
||||
loadUserInfo()
|
||||
loadFeaturedProducts()
|
||||
loadPopularProducts()
|
||||
})
|
||||
|
||||
// 处理用户头像点击
|
||||
const handleUserClick = () => {
|
||||
console.log('用户头像被点击')
|
||||
@@ -376,6 +432,53 @@ const handleProductClick = (item: any) => {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Banner轮播区域 */
|
||||
.banner-carousel {
|
||||
margin: 15px 20px;
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.banner-carousel :deep(.ant-carousel) {
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.banner-slide {
|
||||
width: 100%;
|
||||
height: 180px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.banner-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
/* 轮播指示器样式 */
|
||||
.banner-carousel :deep(.slick-dots) {
|
||||
bottom: 12px;
|
||||
}
|
||||
|
||||
.banner-carousel :deep(.slick-dots li) {
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.banner-carousel :deep(.slick-dots li button) {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
.banner-carousel :deep(.slick-dots li.slick-active button) {
|
||||
width: 20px;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.banner {
|
||||
margin: 15px 20px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
|
||||
Reference in New Issue
Block a user