店铺管理初版

This commit is contained in:
xiaowang
2026-02-26 14:20:35 +08:00
parent 98c9463efa
commit 4275f1840c
9 changed files with 230 additions and 37 deletions
+3 -3
View File
@@ -174,8 +174,8 @@ export interface Shop {
description: string description: string
address: string address: string
businessHours: string businessHours: string
coverImageFileId: string imageFileIds: string
coverImageUrl?: string imageUrls?: string[]
createTime: string createTime: string
updateTime: string updateTime: string
} }
@@ -192,7 +192,7 @@ export interface CreateShopRequest {
description: string description: string
address: string address: string
businessHours: string businessHours: string
coverImageFileId: string imageFileIds: string
} }
export const adminShopApi = { export const adminShopApi = {
+3 -4
View File
@@ -2,13 +2,12 @@ import api from './index'
export interface ShopVO { export interface ShopVO {
id: number id: number
name: string shopName: string
description: string description: string
image: string
phone: string
address: string address: string
businessHours: string businessHours: string
status: number imageFileIds: string
imageUrls?: string[]
createTime: string createTime: string
updateTime: string updateTime: string
} }
+6
View File
@@ -39,6 +39,12 @@ const router = createRouter({
component: () => import('../views/ProfileView.vue'), component: () => import('../views/ProfileView.vue'),
meta: { requiresAuth: true, isAdmin: false } meta: { requiresAuth: true, isAdmin: false }
}, },
{
path: '/shop/:id',
name: 'shop-detail',
component: () => import('../views/ShopDetailView.vue'),
meta: { requiresAuth: true, isAdmin: false }
},
{ {
path: '/wishlist', path: '/wishlist',
name: 'wishlist', name: 'wishlist',
+10 -1
View File
@@ -20,7 +20,7 @@
</div> </div>
</div> </div>
<div class="shop-section" v-if="userInfo.shopName"> <div class="shop-section" v-if="userInfo.shopName">
<div class="shop-card"> <div class="shop-card" @click="handleShopClick">
<div class="shop-icon-wrapper"> <div class="shop-icon-wrapper">
<ShopOutlined class="shop-icon" /> <ShopOutlined class="shop-icon" />
</div> </div>
@@ -401,6 +401,15 @@ const handleSettingsClick = () => {
router.push('/settings') router.push('/settings')
} }
const handleShopClick = () => {
console.log('店铺信息被点击')
if (userInfo.value.shopId) {
router.push(`/shop/${userInfo.value.shopId}`)
} else {
message.error('店铺信息不完整')
}
}
onMounted(() => { onMounted(() => {
fetchUserInfo() fetchUserInfo()
fetchUserPermissions() fetchUserPermissions()
+192 -13
View File
@@ -30,12 +30,25 @@
> >
<template #bodyCell="{ column, record }"> <template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'"> <template v-if="column.key === 'image'">
<div class="shop-images">
<a-image <a-image
:width="60" v-for="(url, index) in getShopImages(record)"
:height="60" :key="index"
:src="record.coverImageUrl || DEFAULT_SHOP_IMAGE" :width="50"
style="object-fit: cover; border-radius: 4px;" :height="50"
:src="url"
style="object-fit: cover; border-radius: 4px; margin-right: 4px;"
:preview="false"
/> />
<a-image
v-if="getShopImages(record).length === 0"
:width="50"
:height="50"
:src="DEFAULT_SHOP_IMAGE"
style="object-fit: cover; border-radius: 4px;"
:preview="false"
/>
</div>
</template> </template>
<template v-else-if="column.key === 'actions'"> <template v-else-if="column.key === 'actions'">
<a-space> <a-space>
@@ -87,8 +100,24 @@
<a-form-item label="营业时间" name="businessHours"> <a-form-item label="营业时间" name="businessHours">
<a-input v-model:value="formState.businessHours" placeholder="例如:09:00-21:00" /> <a-input v-model:value="formState.businessHours" placeholder="例如:09:00-21:00" />
</a-form-item> </a-form-item>
<a-form-item label="封面图文件ID" name="coverImageFileId"> <a-form-item label="店铺图片">
<a-input v-model:value="formState.coverImageFileId" placeholder="请输入封面图文件ID" /> <a-upload
v-model:file-list="imageFileList"
list-type="picture-card"
:custom-request="handleUploadImage"
:before-upload="beforeUpload"
@preview="handlePreview"
@remove="handleRemove"
:max-count="5"
>
<div v-if="imageFileList.length < 5">
<plus-outlined />
<div style="margin-top: 8px">上传图片</div>
</div>
</a-upload>
<a-modal v-model:open="previewVisible" :footer="null" @cancel="previewVisible = false">
<img alt="预览" style="width: 100%" :src="previewImage" />
</a-modal>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-modal> </a-modal>
@@ -99,9 +128,9 @@
import { ref, reactive, onMounted } from 'vue' import { ref, reactive, onMounted } from 'vue'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue' import type { FormInstance } from 'ant-design-vue'
import { PlusOutlined } from '@ant-design/icons-vue' import { PlusOutlined, UploadOutlined } from '@ant-design/icons-vue'
import { DEFAULT_SHOP_IMAGE } from '@/constants' import { DEFAULT_SHOP_IMAGE } from '@/constants'
import { adminShopApi, type Shop } from '@/api/admin' import { adminShopApi, adminFileApi, type Shop } from '@/api/admin'
const loading = ref(false) const loading = ref(false)
const searchText = ref('') const searchText = ref('')
@@ -112,6 +141,14 @@ const isEdit = ref(false)
const formRef = ref<FormInstance>() const formRef = ref<FormInstance>()
const currentShop = ref<Shop | null>(null) const currentShop = ref<Shop | null>(null)
// 图片相关
const imageFileList = ref<any[]>([])
const uploadedFileIds = ref<string[]>([])
const imageIdCache = ref<Record<string, string>>({})
const shopImageUrls = ref<Record<number, string[]>>({})
const previewVisible = ref(false)
const previewImage = ref('')
const pagination = reactive({ const pagination = reactive({
current: 1, current: 1,
pageSize: 10, pageSize: 10,
@@ -126,7 +163,7 @@ const formState = reactive({
description: '', description: '',
address: '', address: '',
businessHours: '', businessHours: '',
coverImageFileId: '' imageFileIds: ''
}) })
const formRules = { const formRules = {
@@ -137,7 +174,7 @@ const formRules = {
} }
const columns = [ const columns = [
{ title: '图片', key: 'image', width: 100 }, { title: '图片', key: 'image', width: 150 },
{ title: '店铺名称', dataIndex: 'shopName', key: 'shopName' }, { title: '店铺名称', dataIndex: 'shopName', key: 'shopName' },
{ title: '店铺描述', dataIndex: 'description', key: 'description' }, { title: '店铺描述', dataIndex: 'description', key: 'description' },
{ title: '店铺地址', dataIndex: 'address', key: 'address' }, { title: '店铺地址', dataIndex: 'address', key: 'address' },
@@ -158,6 +195,39 @@ const getCurrentUserInfo = () => {
return null return null
} }
const loadImageUrls = async (shops: Shop[]) => {
for (const shop of shops) {
if (shop.imageFileIds) {
const ids = shop.imageFileIds.split(',')
const urls: string[] = []
for (const id of ids) {
if (id) {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
imageIdCache.value[id] = signedUrl
}
urls.push(imageIdCache.value[id])
} catch (error) {
console.error('获取签名链接失败:', error)
urls.push(DEFAULT_SHOP_IMAGE)
}
}
}
shopImageUrls.value[shop.id] = urls
} else {
shopImageUrls.value[shop.id] = [DEFAULT_SHOP_IMAGE]
}
}
}
const getShopImages = (shop: Shop): string[] => {
return shopImageUrls.value[shop.id] || [DEFAULT_SHOP_IMAGE]
}
const fetchShopList = async () => { const fetchShopList = async () => {
loading.value = true loading.value = true
try { try {
@@ -175,6 +245,9 @@ const fetchShopList = async () => {
const res = await adminShopApi.listShops(params) const res = await adminShopApi.listShops(params)
shopList.value = res.list || [] shopList.value = res.list || []
pagination.total = res.total || 0 pagination.total = res.total || 0
// 预加载所有图片签名链接
await loadImageUrls(res.list || [])
} catch (error) { } catch (error) {
message.error('获取店铺列表失败') message.error('获取店铺列表失败')
} finally { } finally {
@@ -193,6 +266,56 @@ const handleTableChange = (pag: any) => {
fetchShopList() fetchShopList()
} }
const beforeUpload = (file: File) => {
const isImage = file.type.startsWith('image/')
if (!isImage) {
message.error('只能上传图片文件!')
}
const isLt2M = file.size / 1024 / 1024 < 2
if (!isLt2M) {
message.error('图片大小不能超过 2MB!')
}
return isImage && isLt2M
}
const handleUploadImage = async (options: any) => {
const { file, onSuccess, onError } = options
try {
const res = await adminFileApi.uploadFile(file)
uploadedFileIds.value.push(String(res.id))
formState.imageFileIds = uploadedFileIds.value.join(',')
onSuccess({ url: String(res.id) })
message.success('图片上传成功')
} catch (error) {
console.error('图片上传失败:', error)
onError(error)
message.error('图片上传失败')
}
}
const handlePreview = async (file: any) => {
try {
// 检查缓存
if (!imageIdCache.value[file.uid]) {
const signedUrl = await adminFileApi.getSignedUrl(Number(file.uid))
imageIdCache.value[file.uid] = signedUrl
}
previewImage.value = imageIdCache.value[file.uid]
previewVisible.value = true
} catch (error) {
console.error('获取预览链接失败:', error)
message.error('获取预览链接失败')
}
}
const handleRemove = (file: any) => {
const index = uploadedFileIds.value.indexOf(file.uid)
if (index > -1) {
uploadedFileIds.value.splice(index, 1)
formState.imageFileIds = uploadedFileIds.value.join(',')
}
}
const showAddModal = () => { const showAddModal = () => {
isEdit.value = false isEdit.value = false
Object.assign(formState, { Object.assign(formState, {
@@ -200,12 +323,14 @@ const showAddModal = () => {
description: '', description: '',
address: '', address: '',
businessHours: '', businessHours: '',
coverImageFileId: '' imageFileIds: ''
}) })
imageFileList.value = []
uploadedFileIds.value = []
modalVisible.value = true modalVisible.value = true
} }
const showEditModal = (record: Shop) => { const showEditModal = async (record: Shop) => {
isEdit.value = true isEdit.value = true
currentShop.value = record currentShop.value = record
Object.assign(formState, { Object.assign(formState, {
@@ -213,8 +338,44 @@ const showEditModal = (record: Shop) => {
description: record.description, description: record.description,
address: record.address, address: record.address,
businessHours: record.businessHours, businessHours: record.businessHours,
coverImageFileId: record.coverImageFileId imageFileIds: record.imageFileIds
}) })
if (record.imageFileIds) {
const ids = record.imageFileIds.split(',')
uploadedFileIds.value = ids
// 加载所有图片签名链接
const fileList = []
for (const [index, id] of ids.entries()) {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
imageIdCache.value[id] = signedUrl
}
fileList.push({
uid: id,
name: `图片${index + 1}`,
status: 'done',
url: imageIdCache.value[id]
})
} catch (error) {
console.error('获取签名链接失败:', error)
fileList.push({
uid: id,
name: `图片${index + 1}`,
status: 'done',
url: ''
})
}
}
imageFileList.value = fileList
} else {
imageFileList.value = []
uploadedFileIds.value = []
}
modalVisible.value = true modalVisible.value = true
} }
@@ -243,6 +404,8 @@ const handleModalOk = async () => {
const handleModalCancel = () => { const handleModalCancel = () => {
modalVisible.value = false modalVisible.value = false
formRef.value?.resetFields() formRef.value?.resetFields()
imageFileList.value = []
uploadedFileIds.value = []
} }
const handleDelete = async (record: Shop) => { const handleDelete = async (record: Shop) => {
@@ -264,4 +427,20 @@ onMounted(() => {
.shops { .shops {
padding: 0; padding: 0;
} }
.shop-images {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 4px;
}
.shop-images :deep(.ant-image) {
border-radius: 4px;
}
:deep(.ant-upload-list-picture-card .ant-upload-list-item) {
width: 100px;
height: 100px;
}
</style> </style>
@@ -33,7 +33,7 @@ public class ShopDTO {
private String businessHours; private String businessHours;
/** /**
* 店铺封面图文件ID * 店铺图片文件ID集合,多个ID以逗号分隔
*/ */
private String coverImageFileId; private String imageFileIds;
} }
@@ -43,10 +43,10 @@ public class ShopDO extends BaseEntity {
private String businessHours; private String businessHours;
/** /**
* 店铺封面图文件ID * 店铺图片文件ID集合,多个ID以逗号分隔
*/ */
@TableField("cover_image_file_id") @TableField("image_file_ids")
private String coverImageFileId; private String imageFileIds;
/** /**
* 逻辑删除:0-未删,1-已删 * 逻辑删除:0-未删,1-已删
@@ -37,7 +37,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
shopDO.setDescription(shopDTO.getDescription()); shopDO.setDescription(shopDTO.getDescription());
shopDO.setAddress(shopDTO.getAddress()); shopDO.setAddress(shopDTO.getAddress());
shopDO.setBusinessHours(shopDTO.getBusinessHours()); shopDO.setBusinessHours(shopDTO.getBusinessHours());
shopDO.setCoverImageFileId(shopDTO.getCoverImageFileId()); shopDO.setImageFileIds(shopDTO.getImageFileIds());
shopDO.setIsDelete(0); shopDO.setIsDelete(0);
shopMapper.insert(shopDO); shopMapper.insert(shopDO);
return shopDO.getId(); return shopDO.getId();
@@ -53,7 +53,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
shopDO.setDescription(shopDTO.getDescription()); shopDO.setDescription(shopDTO.getDescription());
shopDO.setAddress(shopDTO.getAddress()); shopDO.setAddress(shopDTO.getAddress());
shopDO.setBusinessHours(shopDTO.getBusinessHours()); shopDO.setBusinessHours(shopDTO.getBusinessHours());
shopDO.setCoverImageFileId(shopDTO.getCoverImageFileId()); shopDO.setImageFileIds(shopDTO.getImageFileIds());
return shopMapper.updateById(shopDO) > 0; return shopMapper.updateById(shopDO) > 0;
} }
@@ -63,8 +63,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
if (shopDO == null) { if (shopDO == null) {
return false; return false;
} }
shopDO.setIsDelete(1); return this.removeById(id);
return shopMapper.updateById(shopDO) > 0;
} }
@Override @Override
@@ -138,7 +137,8 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
shopVO.setDescription(shopDO.getDescription()); shopVO.setDescription(shopDO.getDescription());
shopVO.setAddress(shopDO.getAddress()); shopVO.setAddress(shopDO.getAddress());
shopVO.setBusinessHours(shopDO.getBusinessHours()); shopVO.setBusinessHours(shopDO.getBusinessHours());
shopVO.setCoverImageFileId(shopDO.getCoverImageFileId()); shopVO.setImageFileIds(shopDO.getImageFileIds());
shopVO.setImageUrls(new java.util.ArrayList<>());
shopVO.setCreateTime(shopDO.getCreateTime()); shopVO.setCreateTime(shopDO.getCreateTime());
shopVO.setUpdateTime(shopDO.getUpdateTime()); shopVO.setUpdateTime(shopDO.getUpdateTime());
return shopVO; return shopVO;
@@ -40,14 +40,14 @@ public class ShopVO {
private String businessHours; private String businessHours;
/** /**
* 店铺封面图文件ID * 店铺图片文件ID集合,多个ID以逗号分隔
*/ */
private String coverImageFileId; private String imageFileIds;
/** /**
* 店铺封面图URL * 店铺图片URL列表
*/ */
private String coverImageUrl; private java.util.List<String> imageUrls;
/** /**
* 创建时间 * 创建时间