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

398 lines
8.4 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" @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>
2026-02-26 23:28:24 +08:00
</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>
<!-- 店铺环境图轮播 -->
2026-02-26 23:28:24 +08:00
<div class="shop-images" v-if="shopImages.length > 0">
<h3 class="section-title">店铺环境图</h3>
<div class="image-carousel">
2026-03-05 16:28:05 +08:00
<a-carousel autoplay :autoplay-speed="3000" 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>
2026-02-26 23:28:24 +08:00
</div>
</div>
<!-- 图片查看模态框 -->
<a-modal
v-model:open="imageModalVisible"
title="店铺环境图"
:width="800"
@cancel="handleCancel"
>
<img :src="selectedImage" alt="店铺环境图" class="modal-image" />
</a-modal>
2026-02-26 23:28:24 +08:00
</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'
2026-03-05 16:28:05 +08:00
import { message } from 'ant-design-vue'
2026-02-26 23:28:24 +08:00
import { shopApi, type ShopVO } from '@/api/shop'
import { fileApi } from '@/api/file'
2026-02-26 23:28:24 +08:00
const router = useRouter()
const route = useRoute()
const shopInfo = ref<ShopVO>({
id: 0,
shopName: '',
description: '',
address: '',
businessHours: '',
2026-03-02 10:13:20 +08:00
imageFileIds: '',
createTime: '',
updateTime: ''
2026-02-26 23:28:24 +08:00
})
const shopImages = ref<string[]>([])
// 图片模态框
const imageModalVisible = ref(false)
const selectedImage = ref('')
2026-02-26 23:28:24 +08:00
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('复制失败,请手动复制')
}
}
2026-02-26 23:28:24 +08:00
const loadShopImages = async () => {
try {
const imageFileIds = shopInfo.value.imageFileIds
if (imageFileIds) {
const fileIds = imageFileIds.split(',').filter(id => id.trim())
const fileIdPromises = fileIds.map(idStr => {
const fileId = parseInt(idStr)
if (!isNaN(fileId)) {
2026-03-05 16:28:05 +08:00
return fileApi.getSignedUrl(fileId).catch(() => {
return null
})
}
return null
})
const results = await Promise.all(fileIdPromises)
2026-03-05 16:28:05 +08:00
const filteredResults = results
.filter((url): url is any => url !== null)
.map(url => {
const urlStr = typeof url === 'string' ? url : String(url)
return urlStr.replace(/[`]/g, '').trim()
})
shopImages.value = filteredResults
}
} catch (error) {
}
2026-02-26 23:28:24 +08:00
}
const fetchShopDetail = async () => {
try {
// 从路由参数或本地存储获取店铺ID
const shopId = route.params.id || localStorage.getItem('userShopId')
if (!shopId) {
message.error('店铺ID不存在')
router.back()
return
}
2026-03-02 10:13:20 +08:00
const response = await shopApi.getShopById(Number(shopId)) as any
shopInfo.value = response || {}
2026-02-26 23:28:24 +08:00
// 加载店铺图片
await loadShopImages()
} catch (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;
}
.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;
}
2026-02-26 23:28:24 +08:00
.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-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;
2026-02-26 23:28:24 +08:00
display: flex;
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;
2026-02-26 23:28:24 +08:00
}
2026-03-24 09:50:55 +08:00
@media (min-width: 992px) {
.shop-content {
max-width: 1040px;
margin: 0 auto;
padding: 100px 24px 24px;
2026-03-24 09:50:55 +08:00
}
}
</style>