微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
21
apps/miniprogram - 副本/miniprogram/utils/heart.ts
Normal file
21
apps/miniprogram - 副本/miniprogram/utils/heart.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* 爱心评分映射工具函数
|
||||
* 纯函数,无 wx.* 依赖
|
||||
*/
|
||||
|
||||
/**
|
||||
* 将 0-10 分数映射为爱心 Emoji
|
||||
* >8.5 → 💖, >7 → 🧡, >5 → 💛, ≤5 → 💙
|
||||
* 超出 [0,10] 范围的值会被 clamp
|
||||
* @param score 评分 0-10
|
||||
* @returns 爱心 Emoji
|
||||
*/
|
||||
export function getHeartEmoji(score: number): string {
|
||||
// clamp 到 [0, 10]
|
||||
const clamped = Math.min(10, Math.max(0, score))
|
||||
|
||||
if (clamped > 8.5) return '💖'
|
||||
if (clamped > 7) return '🧡'
|
||||
if (clamped > 5) return '💛'
|
||||
return '💙'
|
||||
}
|
||||
Reference in New Issue
Block a user