productHotSale.js 551 B

12345678910111213141516171819
  1. /** 热卖标签展示数量上限 */
  2. export const HOT_SALE_MAX = 9999
  3. /** 商品是否展示热卖标签 */
  4. export function hasHotSaleTag(item) {
  5. return item != null && item.hotSaleTags != null
  6. }
  7. /** 热卖计数 map 的 key(按商品 id) */
  8. export function getProductHotKey(item) {
  9. if (!item) return ''
  10. return String(item.productId || item.packageId || '')
  11. }
  12. /** 限制热卖数量在 0 ~ HOT_SALE_MAX */
  13. export function clampHotSaleCount(count) {
  14. const n = Number(count) || 0
  15. return Math.min(HOT_SALE_MAX, Math.max(0, Math.floor(n)))
  16. }