| | |
| | | </view> |
| | | </view> |
| | | |
| | | <scroll-view class="content" scroll-y @scroll="handleScroll"> |
| | | <scroll-view :show-scrollbar="false" class="content" scroll-y @scroll="handleScroll"> |
| | | <view class="hero"> |
| | | <image class="hero-image" :src="productImage" mode="aspectFill" @error="replaceProductImage"></image> |
| | | <view class="hero-shade"></view> |
| | |
| | | |
| | | <view v-if="detailText.length > 0" class="detail-card"> |
| | | <text class="card-title">商品详情</text> |
| | | <text class="detail-description">{{detailText}}</text> |
| | | <rich-text class="detail-description" :nodes="detailText"></rich-text> |
| | | </view> |
| | | |
| | | <view class="notice-card"> |
| | |
| | | <script setup lang="uts"> |
| | | import { isApiConfigured } from '../../config/api.uts' |
| | | import { getProductDetail } from '../../services/portal.uts' |
| | | import { sanitizeRichText } from '../../services/business.uts' |
| | | import { resolveApiUrl } from '../../services/http.uts' |
| | | import { getSession } from '../../services/session.uts' |
| | | import { safeBack } from '../../utils/navigation.uts' |
| | |
| | | const productAvailable = ref(true) |
| | | const productSoldOut = ref(false) |
| | | |
| | | // 后台分别返回图片数组与文字结构,不使用富文本 HTML。 |
| | | // Sanitize and render backend-configured product details as rich text. |
| | | const detailText = ref('') |
| | | |
| | | // 购买须知固定只有四项,后台只返回四项各自的内容文本。 |
| | |
| | | const purchaseNotices = ref<any[]>(defaultPurchaseNotices) |
| | | |
| | | const loadProduct = (id: string) => { |
| | | if (id == 'food-set-002') { productName.value = '【川香四溢】川菜4人餐'; productImage.value = '/static/food-assets/food-2.jpg'; productPrice.value = '118'; productOriginalPrice.value = '198'; productDiscount.value = '6折'; return } |
| | | if (id == 'food-set-003') { productName.value = '【欢聚时光】招牌菜6人餐'; productImage.value = '/static/food-assets/food-1.jpg'; productPrice.value = '168'; productOriginalPrice.value = '248'; productDiscount.value = '6.8折'; return } |
| | | if (id == 'food-set-004') { productName.value = '【暖心小聚】特色菜双人餐'; productImage.value = '/static/food-assets/food-2.jpg'; productPrice.value = '88'; productOriginalPrice.value = '126'; productDiscount.value = '7折'; return } |
| | | if (id == 'food-set-005') { productName.value = '【家庭聚餐】经典川菜8人餐'; productImage.value = '/static/food-assets/food-1.jpg'; productPrice.value = '238'; productOriginalPrice.value = '366'; productDiscount.value = '6.5折'; return } |
| | | if (id == 'food-set-006') { productName.value = '【人气必点】招牌菜4人餐'; productImage.value = '/static/food-assets/food-2.jpg'; productPrice.value = '128'; productOriginalPrice.value = '188'; productDiscount.value = '6.8折'; return } |
| | | if (id == 'food-set-007') { productName.value = '【周末欢聚】特色菜10人餐'; productImage.value = '/static/food-assets/food-1.jpg'; productPrice.value = '298'; productOriginalPrice.value = '498'; productDiscount.value = '6折'; return } |
| | | if (id == 'food-set-008') { productName.value = '【一人食】暖心工作餐'; productImage.value = '/static/food-assets/food-2.jpg'; productPrice.value = '39'; productOriginalPrice.value = '49'; productDiscount.value = '8折'; return } |
| | | if (id == 'food-set-002') { productName.value = '【川香四溢】川菜4人餐'; productImage.value = '/static/common/image-placeholder.png'; productPrice.value = '118'; productOriginalPrice.value = '198'; productDiscount.value = '6折'; return } |
| | | if (id == 'food-set-003') { productName.value = '【欢聚时光】招牌菜6人餐'; productImage.value = '/static/common/image-placeholder.png'; productPrice.value = '168'; productOriginalPrice.value = '248'; productDiscount.value = '6.8折'; return } |
| | | if (id == 'food-set-004') { productName.value = '【暖心小聚】特色菜双人餐'; productImage.value = '/static/common/image-placeholder.png'; productPrice.value = '88'; productOriginalPrice.value = '126'; productDiscount.value = '7折'; return } |
| | | if (id == 'food-set-005') { productName.value = '【家庭聚餐】经典川菜8人餐'; productImage.value = '/static/common/image-placeholder.png'; productPrice.value = '238'; productOriginalPrice.value = '366'; productDiscount.value = '6.5折'; return } |
| | | if (id == 'food-set-006') { productName.value = '【人气必点】招牌菜4人餐'; productImage.value = '/static/common/image-placeholder.png'; productPrice.value = '128'; productOriginalPrice.value = '188'; productDiscount.value = '6.8折'; return } |
| | | if (id == 'food-set-007') { productName.value = '【周末欢聚】特色菜10人餐'; productImage.value = '/static/common/image-placeholder.png'; productPrice.value = '298'; productOriginalPrice.value = '498'; productDiscount.value = '6折'; return } |
| | | if (id == 'food-set-008') { productName.value = '【一人食】暖心工作餐'; productImage.value = '/static/common/image-placeholder.png'; productPrice.value = '39'; productOriginalPrice.value = '49'; productDiscount.value = '8折'; return } |
| | | } |
| | | |
| | | onLoad((options: any) => { |
| | |
| | | productAvailable.value = data == null || data.available !== false |
| | | productSoldOut.value = data != null && (data.soldOut === true || Number(data.stock) == 0) |
| | | const rawDetailText = data != null && data.detailText != null ? data.detailText as string : '' |
| | | detailText.value = stripDetailMarkup(rawDetailText) |
| | | detailText.value = sanitizeRichText(rawDetailText) |
| | | purchaseNotices.value = buildPurchaseNotices(data != null ? data.purchaseNotice : null) |
| | | }, () => {}) |
| | | } |
| | |
| | | return next |
| | | } |
| | | |
| | | const stripDetailMarkup = (value: string): string => { |
| | | if (value == '') return '' |
| | | let text = value.replace(/<img[^>]*>/gi, '') |
| | | text = text.replace(/<br\s*\/?>/gi, '\n').replace(/<\/p>/gi, '\n').replace(/<[^>]+>/g, '') |
| | | return text.replace(/ /gi, ' ').replace(/&/gi, '&').replace(/</gi, '<').replace(/>/gi, '>').trim() |
| | | } |
| | | const goBack = () => safeBack('/pages/benefits/benefits') |
| | | const handleScroll = (event: any) => { |
| | | const shouldShow = event.detail.scrollTop > 64 |