2026-02-13 17:34:32 +08:00
|
|
|
<template>
|
2026-05-16 14:28:42 +08:00
|
|
|
<div class="detail-page">
|
|
|
|
|
<header class="detail-header">
|
|
|
|
|
<a-button type="text" @click="router.back()"><LeftOutlined /></a-button>
|
|
|
|
|
<h1>{{ productTitle }}</h1>
|
2026-03-26 10:28:28 +08:00
|
|
|
<a-button type="text" @click="handleFavoriteClick">
|
2026-05-16 14:28:42 +08:00
|
|
|
<component :is="isFavorite ? StarFilled : StarOutlined" :class="{ active: isFavorite }" />
|
2026-03-26 10:28:28 +08:00
|
|
|
</a-button>
|
2026-02-13 17:34:32 +08:00
|
|
|
</header>
|
|
|
|
|
|
2026-05-16 14:28:42 +08:00
|
|
|
<main class="detail-content">
|
|
|
|
|
<a-result v-if="loadError" status="warning" title="暂时无法查看作品详情" :sub-title="loadError">
|
2026-03-26 10:28:28 +08:00
|
|
|
<template #extra>
|
2026-05-16 14:28:42 +08:00
|
|
|
<a-button type="primary" @click="router.back()">返回上一页</a-button>
|
2026-03-26 10:28:28 +08:00
|
|
|
</template>
|
|
|
|
|
</a-result>
|
2026-02-13 17:34:32 +08:00
|
|
|
|
2026-03-26 10:28:28 +08:00
|
|
|
<template v-else>
|
2026-05-16 14:28:42 +08:00
|
|
|
<section class="media-section">
|
2026-05-21 18:43:59 +08:00
|
|
|
<a-image
|
|
|
|
|
class="detail-image-preview"
|
|
|
|
|
:src="productImages[0] || DEFAULT_PRODUCT_IMAGE"
|
|
|
|
|
:alt="productTitle"
|
|
|
|
|
:preview="{ src: productImages[0] || DEFAULT_PRODUCT_IMAGE }"
|
|
|
|
|
/>
|
2026-03-26 10:28:28 +08:00
|
|
|
</section>
|
2026-02-13 17:34:32 +08:00
|
|
|
|
2026-05-16 14:28:42 +08:00
|
|
|
<section class="info-section">
|
|
|
|
|
<div class="title-row">
|
2026-03-26 10:28:28 +08:00
|
|
|
<div>
|
2026-05-16 14:28:42 +08:00
|
|
|
<h2>{{ productTitle }}</h2>
|
|
|
|
|
<p class="price">¥{{ Number(product.price || 0).toFixed(2) }}</p>
|
2026-03-26 10:28:28 +08:00
|
|
|
</div>
|
2026-05-16 14:28:42 +08:00
|
|
|
<a-tag color="blue">{{ product.approximateDuration || '以门店确认为准' }}</a-tag>
|
2026-03-26 10:28:28 +08:00
|
|
|
</div>
|
|
|
|
|
|
2026-05-16 14:28:42 +08:00
|
|
|
<div class="metrics">
|
|
|
|
|
<button type="button" @click="openShopDetail" :disabled="!shopInfo?.id">
|
2026-03-26 10:28:28 +08:00
|
|
|
<ShopOutlined />
|
2026-05-16 14:28:42 +08:00
|
|
|
<span>门店</span>
|
|
|
|
|
<strong>{{ shopInfo?.shopName || '暂未绑定门店' }}</strong>
|
2026-03-26 10:28:28 +08:00
|
|
|
</button>
|
2026-05-16 14:28:42 +08:00
|
|
|
<div>
|
2026-03-26 10:28:28 +08:00
|
|
|
<TeamOutlined />
|
2026-05-16 14:28:42 +08:00
|
|
|
<span>可约美甲师</span>
|
|
|
|
|
<strong>{{ artistCountText }}</strong>
|
2026-03-26 10:28:28 +08:00
|
|
|
</div>
|
2026-05-16 14:28:42 +08:00
|
|
|
<div>
|
2026-03-26 10:28:28 +08:00
|
|
|
<CalendarOutlined />
|
2026-05-16 14:28:42 +08:00
|
|
|
<span>可约时间</span>
|
|
|
|
|
<strong>{{ earliestBookableText }}</strong>
|
2026-03-26 10:28:28 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-05-16 14:28:42 +08:00
|
|
|
<div v-if="shopInfo" class="shop-panel" @click="openShopDetail">
|
|
|
|
|
<strong>{{ shopInfo.shopName }}</strong>
|
|
|
|
|
<span>{{ shopInfo.address || '门店地址待完善' }}</span>
|
|
|
|
|
<span>{{ shopInfo.businessHours || '营业时间待完善' }}</span>
|
2026-03-26 10:28:28 +08:00
|
|
|
</div>
|
|
|
|
|
|
2026-05-16 14:28:42 +08:00
|
|
|
<div class="actions-row">
|
|
|
|
|
<button type="button" :class="{ active: isLiked }" @click="handleLikeClick">
|
|
|
|
|
<component :is="isLiked ? HeartFilled : HeartOutlined" />
|
|
|
|
|
{{ product.likeCount || 0 }} 点赞
|
2026-03-26 10:28:28 +08:00
|
|
|
</button>
|
2026-05-16 14:28:42 +08:00
|
|
|
<button type="button" :class="{ active: isFavorite }" @click="handleFavoriteClick">
|
|
|
|
|
<component :is="isFavorite ? StarFilled : StarOutlined" />
|
|
|
|
|
{{ product.collectCount || 0 }} 收藏
|
2026-03-26 10:28:28 +08:00
|
|
|
</button>
|
2026-05-21 18:43:59 +08:00
|
|
|
<button type="button" @click="copyShareLink">分享链接</button>
|
2026-03-26 10:28:28 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tags">
|
2026-05-16 14:28:42 +08:00
|
|
|
<a-tag v-for="tag in product.tagInfos || []" :key="tag.id">{{ tag.tagName }}</a-tag>
|
|
|
|
|
<a-tag v-if="!product.tagInfos?.length">暂无标签</a-tag>
|
2026-03-26 10:28:28 +08:00
|
|
|
</div>
|
|
|
|
|
|
2026-05-16 14:28:42 +08:00
|
|
|
<div class="description">
|
|
|
|
|
<h3>款式说明</h3>
|
|
|
|
|
<p>{{ product.description || '店家暂未补充作品说明。' }}</p>
|
|
|
|
|
</div>
|
2026-05-23 21:56:18 +08:00
|
|
|
|
|
|
|
|
<div v-if="product.targetAudience || product.precautions" class="guidance-grid">
|
|
|
|
|
<section v-if="product.targetAudience" class="guidance-panel">
|
|
|
|
|
<h3>适合人群</h3>
|
|
|
|
|
<p>{{ product.targetAudience }}</p>
|
|
|
|
|
</section>
|
|
|
|
|
<section v-if="product.precautions" class="guidance-panel">
|
|
|
|
|
<h3>注意事项</h3>
|
|
|
|
|
<p>{{ product.precautions }}</p>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
2026-05-16 14:28:42 +08:00
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section class="comment-section">
|
|
|
|
|
<div class="section-head">
|
|
|
|
|
<h3>作品评论</h3>
|
|
|
|
|
<span>{{ comments.length }} 条</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="comment-editor">
|
|
|
|
|
<a-textarea v-model:value="commentText" :maxlength="300" :rows="3" :placeholder="replyTarget ? `回复 ${replyTarget.userNickname || '用户'}` : '说说你的看法'" />
|
|
|
|
|
<div class="comment-tools">
|
|
|
|
|
<a-button v-if="replyTarget" type="text" @click="replyTarget = null">取消回复</a-button>
|
|
|
|
|
<a-button type="primary" :loading="submittingComment" @click="submitComment">发布</a-button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<a-empty v-if="!comments.length" description="还没有评论,来写第一条吧" />
|
|
|
|
|
<div v-for="comment in comments" :key="comment.id" class="comment-item">
|
|
|
|
|
<div class="comment-main">
|
|
|
|
|
<strong>{{ comment.userNickname || '用户' }}</strong>
|
|
|
|
|
<span>{{ formatTime(comment.createTime) }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<p>{{ comment.commentContent }}</p>
|
|
|
|
|
<button type="button" @click="replyTarget = comment">回复</button>
|
|
|
|
|
<div v-if="comment.replies?.length" class="reply-list">
|
|
|
|
|
<div v-for="reply in comment.replies" :key="reply.id" class="reply-item">
|
|
|
|
|
<strong>{{ reply.userNickname || '用户' }}</strong>
|
|
|
|
|
<span>{{ reply.commentContent }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-26 10:28:28 +08:00
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</template>
|
|
|
|
|
</main>
|
|
|
|
|
|
2026-05-16 14:28:42 +08:00
|
|
|
<footer v-if="!loadError" class="detail-footer">
|
|
|
|
|
<a-button size="large" @click="handleAddToCart"><ShoppingCartOutlined />加入购物车</a-button>
|
|
|
|
|
<a-button type="primary" size="large" @click="handleBuyNow"><ThunderboltOutlined />立即预约</a-button>
|
2026-03-26 10:28:28 +08:00
|
|
|
</footer>
|
2026-02-13 17:34:32 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-05-18 09:46:11 +08:00
|
|
|
/**
|
|
|
|
|
* ProductDetailView page script.
|
|
|
|
|
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
|
|
|
|
*/
|
2026-03-26 10:28:28 +08:00
|
|
|
import { computed, inject, onMounted, ref } from 'vue'
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
|
|
import {
|
2026-05-24 18:09:11 +08:00
|
|
|
CalendarOutlined,
|
2026-03-26 10:28:28 +08:00
|
|
|
HeartFilled,
|
|
|
|
|
HeartOutlined,
|
|
|
|
|
LeftOutlined,
|
|
|
|
|
ShoppingCartOutlined,
|
|
|
|
|
ShopOutlined,
|
|
|
|
|
StarFilled,
|
|
|
|
|
StarOutlined,
|
|
|
|
|
TeamOutlined,
|
|
|
|
|
ThunderboltOutlined
|
|
|
|
|
} from '@ant-design/icons-vue'
|
|
|
|
|
import { message } from 'ant-design-vue'
|
2026-02-27 15:57:14 +08:00
|
|
|
import { cartApi } from '@/api/cart'
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: CommentVO supports ProductDetailView.vue by holding or executing the comment vo page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-16 14:28:42 +08:00
|
|
|
import { commentApi, type CommentVO } from '@/api/comment'
|
2026-03-03 17:50:10 +08:00
|
|
|
import { fileApi } from '@/api/file'
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: ProductVO supports ProductDetailView.vue by holding or executing the product vo page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-03-26 10:28:28 +08:00
|
|
|
import { productApi, type ProductVO } from '@/api/product'
|
|
|
|
|
import { productLikeApi } from '@/api/productLike'
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: ShopVO supports ProductDetailView.vue by holding or executing the shop vo page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-03-26 10:28:28 +08:00
|
|
|
import { shopApi, type ShopVO } from '@/api/shop'
|
|
|
|
|
import { wishlistApi } from '@/api/wishlist'
|
|
|
|
|
import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
2026-03-27 14:55:41 +08:00
|
|
|
import type { IdType } from '@/utils/id'
|
|
|
|
|
import { toOptionalIdString } from '@/utils/id'
|
2026-05-13 12:43:01 +08:00
|
|
|
import { runWithGlobalLoading } from '@/utils/action-loading'
|
2026-02-13 17:34:32 +08:00
|
|
|
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: route supports ProductDetailView.vue by holding or executing the route page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-03-26 10:28:28 +08:00
|
|
|
const route = useRoute()
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: router supports ProductDetailView.vue by holding or executing the router page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-03-26 10:28:28 +08:00
|
|
|
const router = useRouter()
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: updateCartCount supports ProductDetailView.vue by holding or executing the update cart count page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-02-28 17:09:45 +08:00
|
|
|
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
|
|
|
|
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: product supports ProductDetailView.vue by holding or executing the product page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-03-26 10:28:28 +08:00
|
|
|
const product = ref<ProductVO>({} as ProductVO)
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: shopInfo supports ProductDetailView.vue by holding or executing the shop info page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-03-26 10:28:28 +08:00
|
|
|
const shopInfo = ref<ShopVO | null>(null)
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: productImages supports ProductDetailView.vue by holding or executing the product images page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-02-26 11:16:24 +08:00
|
|
|
const productImages = ref<string[]>([])
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: imageIdCache supports ProductDetailView.vue by holding or executing the image id cache page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-03-03 17:50:10 +08:00
|
|
|
const imageIdCache = ref<Record<string, string>>({})
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: comments supports ProductDetailView.vue by holding or executing the comments page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-16 14:28:42 +08:00
|
|
|
const comments = ref<CommentVO[]>([])
|
2026-05-18 09:46:11 +08:00
|
|
|
/** commentText is a reactive state variable used by the template and event handlers. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const commentText = ref('')
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: replyTarget supports ProductDetailView.vue by holding or executing the reply target page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-16 14:28:42 +08:00
|
|
|
const replyTarget = ref<CommentVO | null>(null)
|
2026-05-18 09:46:11 +08:00
|
|
|
/** submittingComment is a reactive state variable used by the template and event handlers. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const submittingComment = ref(false)
|
2026-05-18 09:46:11 +08:00
|
|
|
/** isFavorite is a reactive state variable used by the template and event handlers. */
|
2026-03-26 10:28:28 +08:00
|
|
|
const isFavorite = ref(false)
|
2026-05-18 09:46:11 +08:00
|
|
|
/** isLiked is a reactive state variable used by the template and event handlers. */
|
2026-03-26 10:28:28 +08:00
|
|
|
const isLiked = ref(false)
|
2026-05-18 09:46:11 +08:00
|
|
|
/** loadError is a reactive state variable used by the template and event handlers. */
|
2026-03-26 10:28:28 +08:00
|
|
|
const loadError = ref('')
|
2026-02-13 17:34:32 +08:00
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** isLoggedIn is a reactive state variable used by the template and event handlers. */
|
2026-03-26 10:28:28 +08:00
|
|
|
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
2026-05-18 09:46:11 +08:00
|
|
|
/** productTitle is a reactive state variable used by the template and event handlers. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const productTitle = computed(() => product.value.title || product.value.name || '作品详情')
|
2026-05-18 09:46:11 +08:00
|
|
|
/** artistCount is a reactive state variable used by the template and event handlers. */
|
2026-03-26 10:28:28 +08:00
|
|
|
const artistCount = computed(() => {
|
2026-05-16 14:28:42 +08:00
|
|
|
if (typeof product.value.availableBookableArtistCount === 'number') return product.value.availableBookableArtistCount
|
|
|
|
|
return String(product.value.bookableArtists || '').split(',').map(id => id.trim()).filter(Boolean).length
|
2026-03-26 10:28:28 +08:00
|
|
|
})
|
2026-05-18 09:46:11 +08:00
|
|
|
/** artistCountText is a reactive state variable used by the template and event handlers. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const artistCountText = computed(() => artistCount.value > 0 ? `${artistCount.value} 位` : (product.value.bookableArtistRestricted ? '暂无可约' : '门店安排'))
|
2026-05-18 09:46:11 +08:00
|
|
|
/** earliestBookableText is a reactive state variable used by the template and event handlers. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const earliestBookableText = computed(() => shopInfo.value?.businessHours || '以门店安排为准')
|
2026-03-26 10:28:28 +08:00
|
|
|
|
2026-05-23 18:44:57 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: copyShareLink supports ProductDetailView.vue by holding or executing the copy share link page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
const copyShareLink = async () => {
|
|
|
|
|
const url = `${window.location.origin}/product/${route.params.id}`
|
|
|
|
|
try {
|
|
|
|
|
await navigator.clipboard.writeText(url)
|
|
|
|
|
message.success('分享链接已复制,未登录用户也可以查看详情')
|
|
|
|
|
} catch {
|
|
|
|
|
message.warning(url)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** requireLogin is a local helper used by this page script. */
|
2026-03-26 10:28:28 +08:00
|
|
|
const requireLogin = (actionText: string) => {
|
2026-05-16 14:28:42 +08:00
|
|
|
if (isLoggedIn.value) return true
|
2026-03-26 10:28:28 +08:00
|
|
|
message.info(`${actionText}前请先登录`)
|
|
|
|
|
router.push('/')
|
|
|
|
|
return false
|
2026-03-05 15:15:59 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** loadProductImages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-02-26 11:16:24 +08:00
|
|
|
const loadProductImages = async () => {
|
2026-03-26 10:28:28 +08:00
|
|
|
const fileIds = product.value.imageFileIds?.split(',').map(id => id.trim()).filter(Boolean) || []
|
|
|
|
|
if (!fileIds.length) {
|
2026-03-03 17:50:10 +08:00
|
|
|
productImages.value = [DEFAULT_PRODUCT_IMAGE]
|
2026-03-26 10:28:28 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const urls: string[] = []
|
|
|
|
|
for (const id of fileIds) {
|
|
|
|
|
try {
|
2026-05-16 14:28:42 +08:00
|
|
|
if (!imageIdCache.value[id]) imageIdCache.value[id] = await fileApi.getSignedUrl(id) as unknown as string
|
|
|
|
|
if (imageIdCache.value[id]) urls.push(imageIdCache.value[id])
|
|
|
|
|
} catch {}
|
2026-03-26 10:28:28 +08:00
|
|
|
}
|
|
|
|
|
productImages.value = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE]
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** loadShopInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-03-27 14:55:41 +08:00
|
|
|
const loadShopInfo = async (shopId?: IdType | null) => {
|
2026-05-16 14:28:42 +08:00
|
|
|
shopInfo.value = shopId ? await shopApi.getShopById(shopId).catch(() => null) : null
|
2026-02-26 11:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** loadComments is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const loadComments = async () => {
|
|
|
|
|
if (!product.value.id) return
|
|
|
|
|
comments.value = await commentApi.listByProduct(product.value.id).catch(() => [])
|
2026-03-26 10:28:28 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** checkInteractionStatus is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const checkInteractionStatus = async () => {
|
2026-03-26 10:28:28 +08:00
|
|
|
if (!isLoggedIn.value || !product.value.id) {
|
2026-05-16 14:28:42 +08:00
|
|
|
isFavorite.value = false
|
2026-03-26 10:28:28 +08:00
|
|
|
isLiked.value = false
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-05-16 14:28:42 +08:00
|
|
|
const [favorite, liked] = await Promise.all([
|
|
|
|
|
wishlistApi.checkWishlist(product.value.id).catch(() => false),
|
|
|
|
|
productLikeApi.checkLikeStatus(product.value.id).catch(() => false)
|
|
|
|
|
])
|
|
|
|
|
isFavorite.value = Boolean(favorite)
|
|
|
|
|
isLiked.value = Boolean(liked)
|
2026-03-26 10:28:28 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** fetchProductDetail is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-03-26 10:28:28 +08:00
|
|
|
const fetchProductDetail = async () => {
|
|
|
|
|
loadError.value = ''
|
|
|
|
|
try {
|
2026-03-27 14:55:41 +08:00
|
|
|
const productId = toOptionalIdString(route.params.id)
|
2026-05-16 14:28:42 +08:00
|
|
|
if (!productId) throw new Error('作品不存在')
|
2026-03-26 10:28:28 +08:00
|
|
|
const response = await productApi.getProductById(productId)
|
2026-05-16 14:28:42 +08:00
|
|
|
if (!response?.id) throw new Error('作品不存在或已下架')
|
2026-03-26 10:28:28 +08:00
|
|
|
product.value = response
|
2026-05-16 14:28:42 +08:00
|
|
|
await Promise.all([loadProductImages(), loadShopInfo(response.shopId), checkInteractionStatus(), loadComments()])
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
loadError.value = error?.message || '网络异常,请稍后再试'
|
2026-03-26 10:28:28 +08:00
|
|
|
}
|
2026-02-26 11:16:24 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** openShopDetail is a local helper used by this page script. */
|
2026-03-26 10:28:28 +08:00
|
|
|
const openShopDetail = () => {
|
2026-05-16 14:28:42 +08:00
|
|
|
if (shopInfo.value?.id) router.push(`/shop/${shopInfo.value.id}`)
|
2026-03-26 10:28:28 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** handleFavoriteClick is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-03-03 17:50:10 +08:00
|
|
|
const handleFavoriteClick = async () => {
|
2026-05-16 14:28:42 +08:00
|
|
|
if (!product.value.id || !requireLogin('收藏作品')) return
|
|
|
|
|
await runWithGlobalLoading(async () => {
|
|
|
|
|
if (isFavorite.value) {
|
|
|
|
|
await wishlistApi.removeFromWishlist(product.value.id)
|
|
|
|
|
product.value.collectCount = Math.max(0, Number(product.value.collectCount || 0) - 1)
|
|
|
|
|
message.success('已取消收藏')
|
|
|
|
|
} else {
|
|
|
|
|
await wishlistApi.addToWishlist(product.value.id)
|
|
|
|
|
product.value.collectCount = Number(product.value.collectCount || 0) + 1
|
|
|
|
|
message.success('已加入收藏')
|
|
|
|
|
}
|
2026-03-03 17:50:10 +08:00
|
|
|
isFavorite.value = !isFavorite.value
|
2026-05-16 14:28:42 +08:00
|
|
|
}).catch((error: any) => message.error(error?.message || '收藏操作失败'))
|
2026-02-13 17:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** handleLikeClick is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-03-05 15:15:59 +08:00
|
|
|
const handleLikeClick = async () => {
|
2026-05-16 14:28:42 +08:00
|
|
|
if (!product.value.id || !requireLogin('点赞作品')) return
|
|
|
|
|
await runWithGlobalLoading(async () => {
|
|
|
|
|
if (isLiked.value) {
|
|
|
|
|
await productLikeApi.unlikeProduct(product.value.id)
|
|
|
|
|
product.value.likeCount = Math.max(0, Number(product.value.likeCount || 0) - 1)
|
|
|
|
|
message.success('已取消点赞')
|
|
|
|
|
} else {
|
|
|
|
|
await productLikeApi.likeProduct(product.value.id)
|
|
|
|
|
product.value.likeCount = Number(product.value.likeCount || 0) + 1
|
|
|
|
|
message.success('已点赞')
|
|
|
|
|
}
|
2026-03-05 15:15:59 +08:00
|
|
|
isLiked.value = !isLiked.value
|
2026-05-16 14:28:42 +08:00
|
|
|
}).catch((error: any) => message.error(error?.message || '点赞操作失败'))
|
2026-03-05 15:15:59 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** handleAddToCart is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-02-27 15:57:14 +08:00
|
|
|
const handleAddToCart = async () => {
|
2026-05-16 14:28:42 +08:00
|
|
|
if (!product.value.id || !requireLogin('加入购物车')) return
|
|
|
|
|
await runWithGlobalLoading(() => cartApi.addToCart({ productId: product.value.id, quantity: 1 }))
|
|
|
|
|
await updateCartCount()
|
|
|
|
|
message.success('已加入购物车')
|
2026-02-13 17:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** handleBuyNow is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-02-27 15:57:14 +08:00
|
|
|
const handleBuyNow = async () => {
|
2026-05-16 14:28:42 +08:00
|
|
|
if (!product.value.id || !requireLogin('预约下单')) return
|
2026-05-23 21:56:18 +08:00
|
|
|
await runWithGlobalLoading(() => cartApi.addToCart({ productId: product.value.id, quantity: 1 }))
|
|
|
|
|
await updateCartCount()
|
|
|
|
|
message.success('已加入确认订单')
|
|
|
|
|
router.push({ path: '/cart', query: { mode: 'buyNow', productId: String(product.value.id) } })
|
2026-05-16 14:28:42 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** submitComment is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const submitComment = async () => {
|
|
|
|
|
if (!product.value.id || !requireLogin('发表评论')) return
|
|
|
|
|
const content = commentText.value.trim()
|
|
|
|
|
if (!content) return message.warning('请输入评论内容')
|
|
|
|
|
submittingComment.value = true
|
2026-02-27 15:57:14 +08:00
|
|
|
try {
|
2026-05-16 14:28:42 +08:00
|
|
|
await commentApi.create({
|
|
|
|
|
productId: product.value.id,
|
|
|
|
|
shopId: product.value.shopId,
|
|
|
|
|
parentCommentId: replyTarget.value?.id,
|
|
|
|
|
commentContent: content
|
|
|
|
|
})
|
|
|
|
|
commentText.value = ''
|
|
|
|
|
replyTarget.value = null
|
|
|
|
|
await loadComments()
|
|
|
|
|
message.success('评论已发布')
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
message.error(error?.message || '评论发布失败')
|
|
|
|
|
} finally {
|
|
|
|
|
submittingComment.value = false
|
2026-02-27 15:57:14 +08:00
|
|
|
}
|
2026-02-13 17:34:32 +08:00
|
|
|
}
|
2026-02-24 09:59:22 +08:00
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
/** formatTime is a local helper used by this page script. */
|
2026-05-16 14:28:42 +08:00
|
|
|
const formatTime = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : ''
|
|
|
|
|
|
2026-02-24 09:59:22 +08:00
|
|
|
onMounted(() => {
|
2026-03-26 10:28:28 +08:00
|
|
|
void fetchProductDetail()
|
2026-02-24 09:59:22 +08:00
|
|
|
})
|
2026-02-13 17:34:32 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-05-21 18:43:59 +08:00
|
|
|
.detail-page { min-height: 100vh; background: linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.92)), var(--theme-background-image), var(--theme-page-bg); background-size: cover, cover, auto; background-position: center top; }
|
|
|
|
|
.detail-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(10px); }
|
|
|
|
|
.detail-header h1 { flex: 1; margin: 0; font-size: 17px; text-align: center; color: var(--text-primary); }
|
|
|
|
|
.detail-header .active { color: var(--theme-accent); }
|
2026-05-16 14:28:42 +08:00
|
|
|
.detail-content { max-width: 1040px; margin: 0 auto; padding: 18px 16px 118px; }
|
2026-05-21 18:43:59 +08:00
|
|
|
.media-section { overflow: hidden; border-radius: 8px; background: var(--theme-card-bg); }
|
|
|
|
|
.media-section :deep(.ant-image),
|
|
|
|
|
.media-section :deep(.ant-image-img),
|
|
|
|
|
.media-section img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; cursor: zoom-in; }
|
|
|
|
|
.info-section, .comment-section { margin-top: 14px; padding: 22px; border-radius: 8px; background: var(--theme-card-bg); border: 1px solid var(--theme-border); }
|
2026-05-16 14:28:42 +08:00
|
|
|
.title-row { display: flex; justify-content: space-between; gap: 16px; }
|
2026-05-21 18:43:59 +08:00
|
|
|
.title-row h2 { margin: 0 0 8px; font-size: 24px; color: var(--text-primary); }
|
|
|
|
|
.price { margin: 0; font-size: 26px; font-weight: 700; color: var(--theme-accent); }
|
|
|
|
|
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
|
|
|
|
|
.metrics > div:nth-of-type(2) { display: none; }
|
|
|
|
|
.metrics > div, .metrics > button { display: grid; gap: 4px; padding: 14px; border: 1px solid var(--theme-border); border-radius: 8px; background: var(--theme-primary-soft); text-align: left; }
|
|
|
|
|
.metrics svg { color: var(--theme-primary); }
|
|
|
|
|
.metrics span { font-size: 12px; color: var(--text-secondary); }
|
|
|
|
|
.metrics strong { color: var(--text-primary); }
|
|
|
|
|
.shop-panel { display: none; }
|
|
|
|
|
.shop-panel strong { color: var(--text-primary); }
|
2026-05-16 14:28:42 +08:00
|
|
|
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
|
2026-05-21 18:43:59 +08:00
|
|
|
.actions-row button { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border: 1px solid var(--theme-border); border-radius: 999px; background: var(--theme-card-bg); color: var(--text-secondary); }
|
|
|
|
|
.actions-row button.active { color: var(--theme-accent); border-color: var(--theme-border); background: var(--theme-primary-soft); }
|
2026-05-16 14:28:42 +08:00
|
|
|
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
|
|
|
|
|
.description { margin-top: 22px; }
|
2026-05-23 21:56:18 +08:00
|
|
|
.description h3, .guidance-panel h3, .section-head h3 { margin: 0; font-size: 18px; color: var(--text-primary); }
|
|
|
|
|
.description p, .guidance-panel p { margin: 10px 0 0; color: var(--text-secondary); line-height: 1.8; white-space: pre-wrap; }
|
|
|
|
|
.guidance-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
|
|
|
|
|
.guidance-panel { padding: 14px; border-radius: 8px; border: 1px solid var(--theme-border); background: var(--theme-primary-soft); }
|
2026-05-16 14:28:42 +08:00
|
|
|
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
|
2026-05-21 18:43:59 +08:00
|
|
|
.section-head span { color: var(--text-secondary); }
|
|
|
|
|
.comment-editor { padding: 14px; border: 1px solid var(--theme-border); border-radius: 8px; background: var(--theme-primary-soft); }
|
2026-05-16 14:28:42 +08:00
|
|
|
.comment-tools { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
|
2026-05-21 18:43:59 +08:00
|
|
|
.comment-item { padding: 16px 0; border-bottom: 1px solid var(--theme-border); }
|
2026-05-16 14:28:42 +08:00
|
|
|
.comment-item:last-child { border-bottom: 0; }
|
2026-05-21 18:43:59 +08:00
|
|
|
.comment-main { display: flex; justify-content: space-between; gap: 12px; color: var(--text-secondary); }
|
|
|
|
|
.comment-main strong { color: var(--text-primary); }
|
|
|
|
|
.comment-item p { margin: 8px 0; color: var(--text-primary); line-height: 1.7; }
|
|
|
|
|
.comment-item button { padding: 0; border: 0; background: transparent; color: var(--theme-primary); cursor: pointer; }
|
|
|
|
|
.reply-list { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--theme-primary-soft); }
|
|
|
|
|
.reply-item { display: flex; gap: 8px; padding: 6px 0; color: var(--text-secondary); }
|
|
|
|
|
.reply-item strong { color: var(--text-primary); }
|
|
|
|
|
.detail-footer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 12px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); border-top: 1px solid var(--theme-border); backdrop-filter: blur(10px); }
|
2026-05-16 14:28:42 +08:00
|
|
|
.detail-footer :deep(.ant-btn) { flex: 1; height: 46px; border-radius: 999px; font-weight: 700; }
|
2026-05-23 21:56:18 +08:00
|
|
|
@media (max-width: 720px) { .metrics, .guidance-grid { grid-template-columns: 1fr; } .title-row { flex-direction: column; } }
|
2026-03-05 15:15:59 +08:00
|
|
|
</style>
|