Files
JayuCloud/Frontend/src/views/ShopDetailView.vue
T

277 lines
5.6 KiB
Vue
Raw Normal View History

2026-02-26 23:28:24 +08:00
<template>
<div class="shop-detail">
<div class="header-bg"></div>
<header class="header">
<a-button class="back-btn" type="text" @click="handleBackClick">
<LeftOutlined :style="{ fontSize: '20px' }" />
</a-button>
<h1>店铺详情</h1>
<div class="header-placeholder"></div>
</header>
<div class="shop-content">
<a-card :bordered="false" class="shop-card">
<div class="shop-info">
<div class="shop-header">
<div class="shop-icon-wrapper">
<ShopOutlined class="shop-icon" />
</div>
<div class="shop-header-content">
<h2 class="shop-name">{{ shopInfo.shopName }}</h2>
<p class="shop-address">{{ shopInfo.address }}</p>
</div>
</div>
<div class="shop-details">
<div class="detail-item">
<div class="detail-label">营业时间</div>
<div class="detail-value">{{ shopInfo.businessHours }}</div>
</div>
<div class="detail-item">
<div class="detail-label">店铺描述</div>
<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;"
/>
</div>
</div>
</div>
</a-card>
</div>
</div>
</template>
<script setup lang="ts">
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 { shopApi, type ShopVO } from '@/api/shop'
import { fileApi } from '@/api/index'
const router = useRouter()
const route = useRoute()
const shopInfo = ref<ShopVO>({
id: 0,
shopName: '',
description: '',
address: '',
businessHours: '',
imageFileIds: ''
})
const shopImages = ref<string[]>([])
const imageIdCache = ref<Record<string, string>>({})
const handleBackClick = () => {
router.back()
}
const loadShopImages = async () => {
if (shopInfo.value.imageFileIds) {
const ids = shopInfo.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)
}
}
}
shopImages.value = urls
}
}
const fetchShopDetail = async () => {
try {
// 从路由参数或本地存储获取店铺ID
const shopId = route.params.id || localStorage.getItem('userShopId')
if (!shopId) {
message.error('店铺ID不存在')
router.back()
return
}
const res = await shopApi.getShopById(Number(shopId))
shopInfo.value = res as unknown as ShopVO
// 加载店铺图片
await loadShopImages()
} catch (error) {
console.error('获取店铺详情失败:', error)
message.error('获取店铺详情失败')
}
}
onMounted(() => {
fetchShopDetail()
})
</script>
<style scoped>
.shop-detail {
min-height: 100vh;
background: #f5f5f5;
position: relative;
}
.header-bg {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 120px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
z-index: 0;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
background: transparent;
color: white;
}
.back-btn {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.header h1 {
font-size: 18px;
font-weight: bold;
margin: 0;
}
.header-placeholder {
width: 40px;
height: 40px;
}
.shop-content {
padding: 100px 15px 20px;
position: relative;
z-index: 1;
}
.shop-card {
border-radius: 20px;
overflow: hidden;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
.shop-card :deep(.ant-card-body) {
padding: 24px;
}
.shop-info {
display: flex;
flex-direction: column;
gap: 20px;
}
.shop-header {
display: flex;
align-items: center;
gap: 16px;
}
.shop-icon-wrapper {
width: 80px;
height: 80px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.shop-icon {
font-size: 36px;
color: white;
}
.shop-header-content {
flex: 1;
}
.shop-name {
font-size: 22px;
font-weight: 700;
margin: 0 0 8px 0;
color: #1a1a2e;
}
.shop-address {
font-size: 14px;
color: #8b8b9a;
margin: 0;
}
.shop-details {
display: flex;
flex-direction: column;
gap: 16px;
}
.detail-item {
display: flex;
flex-direction: column;
gap: 6px;
}
.detail-label {
font-size: 13px;
color: #8b8b9a;
font-weight: 500;
}
.detail-value {
font-size: 16px;
color: #1a1a2e;
line-height: 1.5;
}
.section-title {
font-size: 16px;
font-weight: 600;
color: #1a1a2e;
margin: 0 0 12px 0;
}
.image-grid {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
</style>