提交开发分支未提交代码并修正配置
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
class="feature-banner__image"
|
||||
:loading="index === 0 ? 'eager' : 'lazy'"
|
||||
decoding="async"
|
||||
@error="handleProductCardImageError(item)"
|
||||
/>
|
||||
<div class="feature-banner__shade"></div>
|
||||
<div class="feature-banner__copy">
|
||||
@@ -131,7 +132,7 @@
|
||||
@click="handleProductClick(item)"
|
||||
>
|
||||
<div class="product-img">
|
||||
<img v-if="item.coverUrl" :src="item.coverUrl" :alt="item.name" class="product-cover" loading="lazy" decoding="async" />
|
||||
<img v-if="item.coverUrl" :src="item.coverUrl" :alt="item.name" class="product-cover" loading="lazy" decoding="async" @error="handleProductCardImageError(item)" />
|
||||
<span v-else>{{ item.name[0] }}</span>
|
||||
</div>
|
||||
<div class="product-info">
|
||||
@@ -164,7 +165,7 @@
|
||||
@click="handleProductClick(item)"
|
||||
>
|
||||
<div class="product-img">
|
||||
<img v-if="item.coverUrl" :src="item.coverUrl" :alt="item.name" class="product-cover" loading="lazy" decoding="async" />
|
||||
<img v-if="item.coverUrl" :src="item.coverUrl" :alt="item.name" class="product-cover" loading="lazy" decoding="async" @error="handleProductCardImageError(item)" />
|
||||
<span v-else>{{ item.name[0] }}</span>
|
||||
</div>
|
||||
<div class="product-info">
|
||||
@@ -208,7 +209,7 @@
|
||||
type="button"
|
||||
@click="openShopById(shop.shopId)"
|
||||
>
|
||||
<img :src="shop.url" :alt="shop.shopName" loading="lazy" decoding="async" />
|
||||
<img :src="shop.url" :alt="shop.shopName" loading="lazy" decoding="async" @error="handleBannerImageError(shop)" />
|
||||
<span>{{ shop.shopName }}</span>
|
||||
</button>
|
||||
</div>
|
||||
@@ -250,7 +251,12 @@ import { shopApi, type ShopVO } from '../api/shop'
|
||||
import { DEFAULT_AVATAR, DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { extractRichText, renderRichContent } from '@/utils/rich-content'
|
||||
import { getCachedSignedImageUrl, getCachedSignedImageUrlSync } from '@/utils/signed-image-cache'
|
||||
import {
|
||||
getPublicImageFileIds,
|
||||
refreshPublicImageUrl,
|
||||
resolvePublicImageUrl,
|
||||
resolvePublicImageUrlsSync
|
||||
} from '@/utils/public-image-assets'
|
||||
|
||||
/**
|
||||
* Purpose: BannerImage supports HomeView.vue by holding or executing the banner image page or API role.
|
||||
@@ -262,6 +268,7 @@ interface BannerImage {
|
||||
shopName: string
|
||||
businessHours?: string
|
||||
url: string
|
||||
imageFileId?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,6 +282,7 @@ interface ProductCardItem {
|
||||
meta: string
|
||||
shopName?: string
|
||||
coverUrl: string
|
||||
imageFileId?: string
|
||||
bgColor: string
|
||||
}
|
||||
|
||||
@@ -421,14 +429,9 @@ const getRandomColor = (): string => {
|
||||
|
||||
/** getProductCoverUrl is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const getProductCoverUrl = async (product: ProductVO): Promise<string> => {
|
||||
const firstImageId = product.imageFileIds?.split(',').map(id => id.trim()).find(Boolean)
|
||||
if (firstImageId) {
|
||||
return getCachedSignedImageUrlSync(firstImageId) || await getCachedSignedImageUrl(firstImageId, DEFAULT_PRODUCT_IMAGE)
|
||||
}
|
||||
|
||||
const directImageUrl = product.imageUrls?.map(url => String(url || '').trim())
|
||||
.find(url => /^(https?:\/\/|data:image\/|blob:|\/assets\/)/.test(url))
|
||||
return directImageUrl || DEFAULT_PRODUCT_IMAGE
|
||||
const cachedUrls = resolvePublicImageUrlsSync(product, '')
|
||||
if (cachedUrls.length) return cachedUrls[0] || DEFAULT_PRODUCT_IMAGE
|
||||
return resolvePublicImageUrl(product, DEFAULT_PRODUCT_IMAGE)
|
||||
}
|
||||
/** formatProductCards is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const formatProductCards = async (products: ProductVO[]): Promise<ProductCardItem[]> =>
|
||||
@@ -439,6 +442,7 @@ const formatProductCards = async (products: ProductVO[]): Promise<ProductCardIte
|
||||
meta: item.approximateDuration || item.shopName || '支持预约',
|
||||
shopName: item.shopName,
|
||||
coverUrl: await getProductCoverUrl(item),
|
||||
imageFileId: getPublicImageFileIds(item)[0],
|
||||
bgColor: getRandomColor()
|
||||
})))
|
||||
|
||||
@@ -484,30 +488,43 @@ const loadPublicShops = async () => {
|
||||
const loadBannerImages = async () => {
|
||||
const banners: BannerImage[] = []
|
||||
for (const shop of publicShops.value) {
|
||||
const coverIds = (shop.coverImageFileId || shop.imageFileIds || '')
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(Boolean)
|
||||
for (const id of coverIds) {
|
||||
try {
|
||||
const url = getCachedSignedImageUrlSync(id) || await getCachedSignedImageUrl(id)
|
||||
if (url) {
|
||||
banners.push({
|
||||
id: `${shop.id}-${id}`,
|
||||
shopId: shop.id,
|
||||
shopName: shop.shopName,
|
||||
businessHours: shop.businessHours,
|
||||
url
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取门店轮播图失败:', error)
|
||||
}
|
||||
const imageRecord = {
|
||||
coverImageFileId: shop.coverImageFileId,
|
||||
imageFileIds: shop.imageFileIds,
|
||||
imageUrls: shop.imageUrls
|
||||
}
|
||||
const fileId = getPublicImageFileIds(imageRecord)[0]
|
||||
const url = await resolvePublicImageUrl(imageRecord, '')
|
||||
if (url) {
|
||||
banners.push({
|
||||
id: `${shop.id}-${fileId || url}`,
|
||||
shopId: shop.id,
|
||||
shopName: shop.shopName,
|
||||
businessHours: shop.businessHours,
|
||||
url,
|
||||
imageFileId: fileId
|
||||
})
|
||||
}
|
||||
}
|
||||
bannerImages.value = banners.slice(0, 8)
|
||||
}
|
||||
|
||||
const replaceProductCardImage = (items: ProductCardItem[], productId: IdType, imageUrl: string): ProductCardItem[] =>
|
||||
items.map(item => String(item.id) === String(productId) ? { ...item, coverUrl: imageUrl } : item)
|
||||
|
||||
const handleProductCardImageError = async (item: ProductCardItem) => {
|
||||
const imageUrl = item.imageFileId ? await refreshPublicImageUrl(item.imageFileId, DEFAULT_PRODUCT_IMAGE) : DEFAULT_PRODUCT_IMAGE
|
||||
newArrivalItems.value = replaceProductCardImage(newArrivalItems.value, item.id, imageUrl)
|
||||
featuredItems.value = replaceProductCardImage(featuredItems.value, item.id, imageUrl)
|
||||
popularSource.value = replaceProductCardImage(popularSource.value, item.id, imageUrl)
|
||||
popularItems.value = replaceProductCardImage(popularItems.value, item.id, imageUrl)
|
||||
}
|
||||
|
||||
const handleBannerImageError = async (shop: BannerImage) => {
|
||||
const imageUrl = shop.imageFileId ? await refreshPublicImageUrl(shop.imageFileId, DEFAULT_PRODUCT_IMAGE) : DEFAULT_PRODUCT_IMAGE
|
||||
bannerImages.value = bannerImages.value.map(item => item.id === shop.id ? { ...item, url: imageUrl } : item)
|
||||
}
|
||||
|
||||
/** loadNewArrivalProducts fills the top carousel with products tagged as new arrivals. */
|
||||
const loadNewArrivalProducts = async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user