功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -116,6 +116,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import { computed, inject, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
@@ -152,22 +156,33 @@ const shopInfo = ref<ShopVO | null>(null)
|
||||
const productImages = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const comments = ref<CommentVO[]>([])
|
||||
/** commentText is a reactive state variable used by the template and event handlers. */
|
||||
const commentText = ref('')
|
||||
const replyTarget = ref<CommentVO | null>(null)
|
||||
/** submittingComment is a reactive state variable used by the template and event handlers. */
|
||||
const submittingComment = ref(false)
|
||||
/** isFavorite is a reactive state variable used by the template and event handlers. */
|
||||
const isFavorite = ref(false)
|
||||
/** isLiked is a reactive state variable used by the template and event handlers. */
|
||||
const isLiked = ref(false)
|
||||
/** loadError is a reactive state variable used by the template and event handlers. */
|
||||
const loadError = ref('')
|
||||
|
||||
/** isLoggedIn is a reactive state variable used by the template and event handlers. */
|
||||
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
||||
/** productTitle is a reactive state variable used by the template and event handlers. */
|
||||
const productTitle = computed(() => product.value.title || product.value.name || '作品详情')
|
||||
/** artistCount is a reactive state variable used by the template and event handlers. */
|
||||
const artistCount = computed(() => {
|
||||
if (typeof product.value.availableBookableArtistCount === 'number') return product.value.availableBookableArtistCount
|
||||
return String(product.value.bookableArtists || '').split(',').map(id => id.trim()).filter(Boolean).length
|
||||
})
|
||||
/** artistCountText is a reactive state variable used by the template and event handlers. */
|
||||
const artistCountText = computed(() => artistCount.value > 0 ? `${artistCount.value} 位` : (product.value.bookableArtistRestricted ? '暂无可约' : '门店安排'))
|
||||
/** earliestBookableText is a reactive state variable used by the template and event handlers. */
|
||||
const earliestBookableText = computed(() => shopInfo.value?.businessHours || '以门店安排为准')
|
||||
|
||||
/** requireLogin is a local helper used by this page script. */
|
||||
const requireLogin = (actionText: string) => {
|
||||
if (isLoggedIn.value) return true
|
||||
message.info(`${actionText}前请先登录`)
|
||||
@@ -175,6 +190,7 @@ const requireLogin = (actionText: string) => {
|
||||
return false
|
||||
}
|
||||
|
||||
/** loadProductImages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadProductImages = async () => {
|
||||
const fileIds = product.value.imageFileIds?.split(',').map(id => id.trim()).filter(Boolean) || []
|
||||
if (!fileIds.length) {
|
||||
@@ -191,15 +207,18 @@ const loadProductImages = async () => {
|
||||
productImages.value = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
/** loadShopInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadShopInfo = async (shopId?: IdType | null) => {
|
||||
shopInfo.value = shopId ? await shopApi.getShopById(shopId).catch(() => null) : null
|
||||
}
|
||||
|
||||
/** loadComments is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadComments = async () => {
|
||||
if (!product.value.id) return
|
||||
comments.value = await commentApi.listByProduct(product.value.id).catch(() => [])
|
||||
}
|
||||
|
||||
/** checkInteractionStatus is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const checkInteractionStatus = async () => {
|
||||
if (!isLoggedIn.value || !product.value.id) {
|
||||
isFavorite.value = false
|
||||
@@ -214,6 +233,7 @@ const checkInteractionStatus = async () => {
|
||||
isLiked.value = Boolean(liked)
|
||||
}
|
||||
|
||||
/** fetchProductDetail is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchProductDetail = async () => {
|
||||
loadError.value = ''
|
||||
try {
|
||||
@@ -228,10 +248,12 @@ const fetchProductDetail = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** openShopDetail is a local helper used by this page script. */
|
||||
const openShopDetail = () => {
|
||||
if (shopInfo.value?.id) router.push(`/shop/${shopInfo.value.id}`)
|
||||
}
|
||||
|
||||
/** handleFavoriteClick is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleFavoriteClick = async () => {
|
||||
if (!product.value.id || !requireLogin('收藏作品')) return
|
||||
await runWithGlobalLoading(async () => {
|
||||
@@ -248,6 +270,7 @@ const handleFavoriteClick = async () => {
|
||||
}).catch((error: any) => message.error(error?.message || '收藏操作失败'))
|
||||
}
|
||||
|
||||
/** handleLikeClick is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleLikeClick = async () => {
|
||||
if (!product.value.id || !requireLogin('点赞作品')) return
|
||||
await runWithGlobalLoading(async () => {
|
||||
@@ -264,6 +287,7 @@ const handleLikeClick = async () => {
|
||||
}).catch((error: any) => message.error(error?.message || '点赞操作失败'))
|
||||
}
|
||||
|
||||
/** handleAddToCart is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleAddToCart = async () => {
|
||||
if (!product.value.id || !requireLogin('加入购物车')) return
|
||||
await runWithGlobalLoading(() => cartApi.addToCart({ productId: product.value.id, quantity: 1 }))
|
||||
@@ -271,12 +295,14 @@ const handleAddToCart = async () => {
|
||||
message.success('已加入购物车')
|
||||
}
|
||||
|
||||
/** handleBuyNow is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleBuyNow = async () => {
|
||||
if (!product.value.id || !requireLogin('预约下单')) return
|
||||
await handleAddToCart()
|
||||
router.push('/cart')
|
||||
}
|
||||
|
||||
/** submitComment is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const submitComment = async () => {
|
||||
if (!product.value.id || !requireLogin('发表评论')) return
|
||||
const content = commentText.value.trim()
|
||||
@@ -300,6 +326,7 @@ const submitComment = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** formatTime is a local helper used by this page script. */
|
||||
const formatTime = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : ''
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user