修复一些问题,优化前后端交互接口格式,优化首页轮播图图的维护
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%);
|
||||
|
||||
@@ -16,8 +16,14 @@
|
||||
<ShopOutlined class="shop-icon" />
|
||||
</div>
|
||||
<div class="shop-header-content">
|
||||
<h2 class="shop-name">{{ shopInfo.shopName }}</h2>
|
||||
<p class="shop-address">{{ shopInfo.address }}</p>
|
||||
<h2 class="shop-name" @click="copyToClipboard(shopInfo.shopName, '店名')" style="cursor: pointer;">
|
||||
{{ shopInfo.shopName }}
|
||||
<span class="copy-icon">📋</span>
|
||||
</h2>
|
||||
<p class="shop-address" @click="copyToClipboard(shopInfo.address, '地址')" style="cursor: pointer;">
|
||||
{{ shopInfo.address }}
|
||||
<span class="copy-icon">📋</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shop-details">
|
||||
@@ -30,19 +36,27 @@
|
||||
<div class="detail-value">{{ shopInfo.description }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 店铺环境图轮播 -->
|
||||
<div class="shop-images" v-if="shopImages.length > 0">
|
||||
<h3 class="section-title">店铺图片</h3>
|
||||
<div class="image-grid">
|
||||
<a-image
|
||||
v-for="(url, index) in shopImages"
|
||||
:key="index"
|
||||
:width="100"
|
||||
:height="100"
|
||||
:src="url"
|
||||
style="object-fit: cover; border-radius: 4px; margin: 4px;"
|
||||
/>
|
||||
<h3 class="section-title">店铺环境图</h3>
|
||||
<div class="image-carousel">
|
||||
<a-carousel autoplay :autoplay-speed="3000" effect="slide" dots>
|
||||
<div v-for="(url, index) in shopImages" :key="index" class="carousel-item" @click="showImageModal(url)">
|
||||
<img :src="url" :alt="`店铺环境图 ${index + 1}`" class="carousel-image" />
|
||||
</div>
|
||||
</a-carousel>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 图片查看模态框 -->
|
||||
<a-modal
|
||||
v-model:open="imageModalVisible"
|
||||
title="店铺环境图"
|
||||
:width="800"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<img :src="selectedImage" alt="店铺环境图" class="modal-image" />
|
||||
</a-modal>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
@@ -53,8 +67,9 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { LeftOutlined, ShopOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { shopApi, type ShopVO } from '@/api/shop'
|
||||
import { fileApi } from '@/api/file'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
@@ -72,13 +87,72 @@ const shopInfo = ref<ShopVO>({
|
||||
|
||||
const shopImages = ref<string[]>([])
|
||||
|
||||
// 图片模态框
|
||||
const imageModalVisible = ref(false)
|
||||
const selectedImage = ref('')
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 显示图片模态框
|
||||
const showImageModal = (imageUrl: string) => {
|
||||
selectedImage.value = imageUrl
|
||||
imageModalVisible.value = true
|
||||
}
|
||||
|
||||
// 关闭图片模态框
|
||||
const handleCancel = () => {
|
||||
imageModalVisible.value = false
|
||||
selectedImage.value = ''
|
||||
}
|
||||
|
||||
// 复制到剪贴板
|
||||
const copyToClipboard = async (text: string, type: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
message.success(`${type}已复制到剪贴板`)
|
||||
} catch (err) {
|
||||
console.error('复制失败:', err)
|
||||
message.error('复制失败,请手动复制')
|
||||
}
|
||||
}
|
||||
|
||||
const loadShopImages = async () => {
|
||||
// 由于ShopVO类型中没有imageFileIds属性,这里简化处理
|
||||
shopImages.value = []
|
||||
try {
|
||||
console.log('开始加载店铺环境图')
|
||||
const imageFileIds = shopInfo.value.imageFileIds
|
||||
console.log('imageFileIds:', imageFileIds)
|
||||
|
||||
if (imageFileIds) {
|
||||
const fileIds = imageFileIds.split(',').filter(id => id.trim())
|
||||
console.log('分割后的fileIds:', fileIds)
|
||||
|
||||
const fileIdPromises = fileIds.map(idStr => {
|
||||
const fileId = parseInt(idStr)
|
||||
console.log('处理fileId:', fileId)
|
||||
if (!isNaN(fileId)) {
|
||||
return fileApi.getSignedUrl(fileId).catch(err => {
|
||||
console.error('获取店铺环境图签名失败:', err)
|
||||
return null
|
||||
})
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
const results = await Promise.all(fileIdPromises)
|
||||
console.log('签名URL请求结果:', results)
|
||||
|
||||
const filteredResults = results.filter((url): url is string => url !== null).map(url => url.replace(/[`]/g, '').trim())
|
||||
console.log('过滤后结果:', filteredResults)
|
||||
console.log('过滤后数量:', filteredResults.length)
|
||||
|
||||
shopImages.value = filteredResults
|
||||
console.log('shopImages最终值:', shopImages.value)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载店铺环境图失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchShopDetail = async () => {
|
||||
@@ -91,8 +165,12 @@ const fetchShopDetail = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log('请求店铺详情,shopId:', shopId)
|
||||
const response = await shopApi.getShopById(Number(shopId)) as any
|
||||
console.log('店铺详情响应:', response)
|
||||
|
||||
shopInfo.value = response || {}
|
||||
console.log('shopInfo.value:', shopInfo.value)
|
||||
|
||||
// 加载店铺图片
|
||||
await loadShopImages()
|
||||
@@ -219,6 +297,19 @@ onMounted(() => {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.copy-icon {
|
||||
font-size: 12px;
|
||||
margin-left: 6px;
|
||||
opacity: 0.6;
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.shop-name:hover .copy-icon,
|
||||
.shop-address:hover .copy-icon {
|
||||
opacity: 1;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.shop-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -250,9 +341,63 @@ onMounted(() => {
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
.image-carousel {
|
||||
margin: 12px 0;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.carousel-item {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.carousel-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.carousel-item:hover .carousel-image {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
/* 轮播指示器样式 */
|
||||
.image-carousel :deep(.slick-dots) {
|
||||
bottom: 10px;
|
||||
}
|
||||
|
||||
.image-carousel :deep(.slick-dots li) {
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.image-carousel :deep(.slick-dots li button) {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.image-carousel :deep(.slick-dots li.slick-active button) {
|
||||
width: 20px;
|
||||
border-radius: 4px;
|
||||
background: #667eea;
|
||||
}
|
||||
|
||||
.modal-image {
|
||||
width: 100%;
|
||||
max-height: 600px;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -457,9 +457,15 @@ const fetchCoupons = async () => {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
const res = await adminCouponApi.listAllCoupons(shopId)
|
||||
// 处理后端返回的分页数据结构
|
||||
couponList.value = res?.list || []
|
||||
pagination.total = res?.total || 0
|
||||
// 后端返回的是数组,直接使用
|
||||
if (Array.isArray(res)) {
|
||||
couponList.value = res
|
||||
pagination.total = res.length
|
||||
} else {
|
||||
// 兼容分页数据结构
|
||||
couponList.value = res?.list || []
|
||||
pagination.total = res?.total || 0
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
|
||||
@@ -69,7 +69,8 @@
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { DashboardOutlined, UserOutlined, ShopOutlined, SafetyCertificateOutlined, HomeOutlined } from '@ant-design/icons-vue'
|
||||
import { userApi, type UserVO, permissionApi, type PermissionVO } from '@/api/admin'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
|
||||
@@ -178,7 +178,8 @@ import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { permissionApi, type PermissionVO, userApi, type UserVO } from '@/api/admin'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
@@ -50,6 +50,20 @@
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'banner'">
|
||||
<div class="shop-banner">
|
||||
<a-image
|
||||
v-for="(url, index) in getShopBannerImages(record)"
|
||||
:key="index"
|
||||
:width="80"
|
||||
:height="40"
|
||||
:src="url"
|
||||
style="object-fit: cover; border-radius: 4px; margin-right: 4px;"
|
||||
:preview="false"
|
||||
/>
|
||||
<span v-if="getShopBannerImages(record).length === 0" class="no-banner">暂无Banner</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('shop:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
@@ -76,7 +90,7 @@
|
||||
<a-modal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑店铺' : '新增店铺'"
|
||||
width="600px"
|
||||
width="700px"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
@@ -104,7 +118,28 @@
|
||||
<a-form-item label="营业时间" name="businessHours">
|
||||
<a-input v-model:value="formState.businessHours" placeholder="例如:09:00-21:00" />
|
||||
</a-form-item>
|
||||
<a-form-item label="Banner图片">
|
||||
<div class="upload-tip">首页轮播图,建议尺寸 750x300 像素</div>
|
||||
<a-upload
|
||||
v-model:file-list="bannerFileList"
|
||||
list-type="picture-card"
|
||||
:custom-request="handleUploadBanner"
|
||||
:before-upload="beforeUpload"
|
||||
@preview="handleBannerPreview"
|
||||
@remove="handleBannerRemove"
|
||||
:max-count="5"
|
||||
>
|
||||
<div v-if="bannerFileList.length < 5">
|
||||
<plus-outlined />
|
||||
<div style="margin-top: 8px">上传Banner</div>
|
||||
</div>
|
||||
</a-upload>
|
||||
<a-modal v-model:open="bannerPreviewVisible" :footer="null" @cancel="bannerPreviewVisible = false">
|
||||
<img alt="预览" style="width: 100%" :src="bannerPreviewImage" />
|
||||
</a-modal>
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺图片">
|
||||
<div class="upload-tip">店铺详情展示图</div>
|
||||
<a-upload
|
||||
v-model:file-list="imageFileList"
|
||||
list-type="picture-card"
|
||||
@@ -130,7 +165,7 @@
|
||||
<a-modal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看店铺详情"
|
||||
width="600px"
|
||||
width="700px"
|
||||
@cancel="handleViewModalCancel"
|
||||
>
|
||||
<a-form
|
||||
@@ -154,6 +189,20 @@
|
||||
<a-form-item label="营业时间">
|
||||
<a-input v-model:value="viewFormState.businessHours" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="Banner图片">
|
||||
<div class="shop-images">
|
||||
<a-image
|
||||
v-for="(url, index) in viewBannerUrls"
|
||||
:key="index"
|
||||
:width="120"
|
||||
:height="60"
|
||||
:src="url"
|
||||
style="object-fit: cover; border-radius: 4px; margin-right: 8px; margin-bottom: 8px;"
|
||||
:preview="false"
|
||||
/>
|
||||
<span v-if="viewBannerUrls.length === 0" class="no-banner">暂无Banner</span>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺图片">
|
||||
<div class="shop-images">
|
||||
<a-image
|
||||
@@ -165,6 +214,14 @@
|
||||
style="object-fit: cover; border-radius: 4px; margin-right: 8px; margin-bottom: 8px;"
|
||||
:preview="false"
|
||||
/>
|
||||
<a-image
|
||||
v-if="viewImageUrls.length === 0"
|
||||
:width="80"
|
||||
:height="80"
|
||||
:src="DEFAULT_SHOP_IMAGE"
|
||||
style="object-fit: cover; border-radius: 4px;"
|
||||
:preview="false"
|
||||
/>
|
||||
</div>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
@@ -194,12 +251,20 @@ const formRef = ref<FormInstance>()
|
||||
const currentShop = ref<Shop | null>(null)
|
||||
const isAdmin = ref(false)
|
||||
|
||||
// 图片相关
|
||||
// Banner图片相关
|
||||
const bannerFileList = ref<any[]>([])
|
||||
const uploadedBannerIds = ref<string[]>([])
|
||||
const bannerPreviewVisible = ref(false)
|
||||
const bannerPreviewImage = ref('')
|
||||
|
||||
// 店铺图片相关
|
||||
const imageFileList = ref<any[]>([])
|
||||
const uploadedFileIds = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const shopImageUrls = ref<Record<number, string[]>>({})
|
||||
const shopBannerUrls = ref<Record<number, string[]>>({})
|
||||
const viewImageUrls = ref<string[]>([])
|
||||
const viewBannerUrls = ref<string[]>([])
|
||||
const previewVisible = ref(false)
|
||||
const previewImage = ref('')
|
||||
|
||||
@@ -209,6 +274,7 @@ const viewFormState = reactive({
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
|
||||
@@ -226,6 +292,7 @@ const formState = reactive({
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
|
||||
@@ -238,6 +305,7 @@ const formRules: any = {
|
||||
|
||||
const columns = [
|
||||
{ title: '图片', key: 'image', width: 150 },
|
||||
{ title: 'Banner', key: 'banner', width: 200 },
|
||||
{ title: '店铺名称', dataIndex: 'shopName', key: 'shopName' },
|
||||
{ title: '店铺描述', dataIndex: 'description', key: 'description' },
|
||||
{ title: '店铺地址', dataIndex: 'address', key: 'address' },
|
||||
@@ -263,6 +331,7 @@ const getCurrentUserInfo = () => {
|
||||
|
||||
const loadImageUrls = async (shops: Shop[]) => {
|
||||
for (const shop of shops) {
|
||||
// 加载店铺图片
|
||||
if (shop.imageFileIds) {
|
||||
const ids = shop.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
@@ -285,14 +354,45 @@ const loadImageUrls = async (shops: Shop[]) => {
|
||||
|
||||
shopImageUrls.value[shop.id] = urls
|
||||
} else {
|
||||
shopImageUrls.value[shop.id] = [DEFAULT_SHOP_IMAGE]
|
||||
shopImageUrls.value[shop.id] = []
|
||||
}
|
||||
|
||||
// 加载Banner图片
|
||||
if (shop.coverImageFileId) {
|
||||
const ids = shop.coverImageFileId.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
urls.push(DEFAULT_SHOP_IMAGE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shopBannerUrls.value[shop.id] = urls
|
||||
} else {
|
||||
shopBannerUrls.value[shop.id] = []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getShopImages = (shop: Shop | Record<string, any>): string[] => {
|
||||
const shopId = 'id' in shop ? shop.id : (shop as any).id
|
||||
return shopImageUrls.value[shopId] || [DEFAULT_SHOP_IMAGE]
|
||||
return shopImageUrls.value[shopId] || []
|
||||
}
|
||||
|
||||
const getShopBannerImages = (shop: Shop | Record<string, any>): string[] => {
|
||||
const shopId = 'id' in shop ? shop.id : (shop as any).id
|
||||
return shopBannerUrls.value[shopId] || []
|
||||
}
|
||||
|
||||
const fetchShopList = async () => {
|
||||
@@ -346,6 +446,47 @@ const beforeUpload = (file: File) => {
|
||||
return isImage && isLt2M
|
||||
}
|
||||
|
||||
// Banner图片上传
|
||||
const handleUploadBanner = async (options: any) => {
|
||||
const { file, onSuccess, onError } = options
|
||||
try {
|
||||
const response = await adminFileApi.uploadFile(file)
|
||||
const res = typeof response === 'object' && 'id' in response ? response : (response as any).data
|
||||
uploadedBannerIds.value.push(String(res.id))
|
||||
formState.coverImageFileId = uploadedBannerIds.value.join(',')
|
||||
onSuccess({ url: String(res.id) })
|
||||
message.success('Banner上传成功')
|
||||
} catch (error) {
|
||||
console.error('Banner上传失败:', error)
|
||||
onError(error)
|
||||
message.error('Banner上传失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleBannerPreview = async (file: any) => {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[file.uid]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(file.uid)) as any
|
||||
imageIdCache.value[file.uid] = response
|
||||
}
|
||||
bannerPreviewImage.value = imageIdCache.value[file.uid] || ''
|
||||
bannerPreviewVisible.value = true
|
||||
} catch (error) {
|
||||
console.error('获取预览链接失败:', error)
|
||||
message.error('获取预览链接失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleBannerRemove = (file: any) => {
|
||||
const index = uploadedBannerIds.value.indexOf(file.uid)
|
||||
if (index > -1) {
|
||||
uploadedBannerIds.value.splice(index, 1)
|
||||
formState.coverImageFileId = uploadedBannerIds.value.join(',')
|
||||
}
|
||||
}
|
||||
|
||||
// 店铺图片上传
|
||||
const handleUploadImage = async (options: any) => {
|
||||
const { file, onSuccess, onError } = options
|
||||
try {
|
||||
@@ -392,8 +533,11 @@ const showAddModal = () => {
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
bannerFileList.value = []
|
||||
uploadedBannerIds.value = []
|
||||
imageFileList.value = []
|
||||
uploadedFileIds.value = []
|
||||
modalVisible.value = true
|
||||
@@ -407,9 +551,48 @@ const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
description: 'description' in record ? record.description : (record as any).description,
|
||||
address: 'address' in record ? record.address : (record as any).address,
|
||||
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
|
||||
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
|
||||
// 加载Banner图片
|
||||
const coverImageFileId = 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId
|
||||
if (coverImageFileId) {
|
||||
const ids = coverImageFileId.split(',')
|
||||
uploadedBannerIds.value = ids
|
||||
|
||||
// 加载所有图片签名链接
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
name: `Banner${index + 1}`,
|
||||
status: 'done',
|
||||
url: imageIdCache.value[id]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
fileList.push({
|
||||
uid: id,
|
||||
name: `Banner${index + 1}`,
|
||||
status: 'done',
|
||||
url: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
bannerFileList.value = fileList
|
||||
} else {
|
||||
bannerFileList.value = []
|
||||
uploadedBannerIds.value = []
|
||||
}
|
||||
|
||||
// 加载店铺图片
|
||||
const imageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
if (imageFileIds) {
|
||||
const ids = imageFileIds.split(',')
|
||||
@@ -455,11 +638,36 @@ const showViewModal = async (record: Shop | Record<string, any>) => {
|
||||
description: 'description' in record ? record.description : (record as any).description,
|
||||
address: 'address' in record ? record.address : (record as any).address,
|
||||
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
|
||||
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
|
||||
// 加载Banner图片URL
|
||||
const coverImageFileId = 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId
|
||||
if (coverImageFileId) {
|
||||
const ids = coverImageFileId.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
urls.push(DEFAULT_SHOP_IMAGE)
|
||||
}
|
||||
}
|
||||
viewBannerUrls.value = urls
|
||||
} else {
|
||||
viewBannerUrls.value = []
|
||||
}
|
||||
|
||||
// 加载店铺图片URL
|
||||
const imageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
// 加载图片URL
|
||||
if (imageFileIds) {
|
||||
const ids = imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
@@ -479,7 +687,7 @@ const showViewModal = async (record: Shop | Record<string, any>) => {
|
||||
}
|
||||
viewImageUrls.value = urls
|
||||
} else {
|
||||
viewImageUrls.value = [DEFAULT_SHOP_IMAGE]
|
||||
viewImageUrls.value = []
|
||||
}
|
||||
|
||||
viewModalVisible.value = true
|
||||
@@ -488,6 +696,7 @@ const showViewModal = async (record: Shop | Record<string, any>) => {
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
viewImageUrls.value = []
|
||||
viewBannerUrls.value = []
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
@@ -515,6 +724,8 @@ const handleModalOk = async () => {
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
bannerFileList.value = []
|
||||
uploadedBannerIds.value = []
|
||||
imageFileList.value = []
|
||||
uploadedFileIds.value = []
|
||||
}
|
||||
@@ -548,12 +759,21 @@ onMounted(async () => {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.shop-images :deep(.ant-image) {
|
||||
border-radius: 4px;
|
||||
.shop-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
:deep(.ant-upload-list-picture-card .ant-upload-list-item) {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
.no-banner {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.upload-tip {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user