修复一些问题,优化前后端交互接口格式,优化首页轮播图图的维护
This commit is contained in:
@@ -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