Files

52 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2026-04-01 15:18:35 +08:00
const { formatPrice, getProductTitle } = require('./format')
const { resolveImageList } = require('./file')
const { DEFAULT_PRODUCT_IMAGE } = require('./config')
2026-05-23 18:45:41 +08:00
/**
* Purpose: getProductTags supports product.js by holding or executing the get product tags page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
function getProductTags(product) {
if (Array.isArray(product && product.tagInfos)) {
return product.tagInfos
.map(tag => tag && tag.tagName)
.filter(Boolean)
.slice(0, 3)
}
return []
}
2026-05-23 18:45:41 +08:00
/**
* Purpose: buildProductCard supports product.js by holding or executing the build product card page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
async function buildProductCard(product) {
const images = await resolveImageList(product && product.imageFileIds, DEFAULT_PRODUCT_IMAGE)
return {
...product,
displayTitle: getProductTitle(product),
priceText: `¥${formatPrice(product && product.price)}`,
metaText: (product && product.approximateDuration) || '支持预约',
shopNameText: product && product.shopName ? `所属店铺:${product.shopName}` : '',
2026-04-01 15:18:35 +08:00
coverUrl: images[0],
imageUrls: images,
tagsPreview: getProductTags(product),
statsText: `${Number((product && product.likeCount) || 0)}赞 · ${Number((product && product.collectCount) || 0)}藏`
2026-04-01 15:18:35 +08:00
}
}
2026-05-23 18:45:41 +08:00
/**
* Purpose: buildProductCards supports product.js by holding or executing the build product cards page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-04-01 15:18:35 +08:00
async function buildProductCards(products) {
const list = Array.isArray(products) ? products : []
return Promise.all(list.map(item => buildProductCard(item)))
}
module.exports = {
buildProductCard,
buildProductCards
}