功能:新增微信小程序界面
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
const { formatPrice, getProductTitle } = require('./format')
|
||||
const { resolveImageList } = require('./file')
|
||||
const { DEFAULT_PRODUCT_IMAGE } = require('./config')
|
||||
|
||||
function getProductTags(product) {
|
||||
if (Array.isArray(product && product.tagInfos)) {
|
||||
return product.tagInfos
|
||||
.map(tag => tag && tag.tagName)
|
||||
.filter(Boolean)
|
||||
.slice(0, 3)
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
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 || product.shopName)) || '支持预约',
|
||||
coverUrl: images[0],
|
||||
imageUrls: images,
|
||||
tagsPreview: getProductTags(product),
|
||||
statsText: `${Number(product && product.likeCount || 0)}赞 · ${Number(product && product.collectCount || 0)}藏`
|
||||
}
|
||||
}
|
||||
|
||||
async function buildProductCards(products) {
|
||||
const list = Array.isArray(products) ? products : []
|
||||
return Promise.all(list.map(item => buildProductCard(item)))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildProductCard,
|
||||
buildProductCards
|
||||
}
|
||||
Reference in New Issue
Block a user