Files
Neo-ZQYY/tmp/DEMO-miniprogram/miniprogram/components/heart-icon/heart-icon.ts

31 lines
629 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Component({
properties: {
/** 评分 0-10超出范围自动 clamp */
score: {
type: Number,
value: 0,
},
},
data: {
heartEmoji: '💙',
},
observers: {
score(val: number) {
const s = val < 0 ? 0 : val > 10 ? 10 : val
let emoji: string
if (s > 8.5) {
emoji = '💖' // 粉红色 - 很好
} else if (s >= 6) {
emoji = '🧡' // 橙色 - 良好
} else if (s >= 3.5) {
emoji = '💛' // 黄色 - 一般
} else {
emoji = '💙' // 蓝色 - 待发展
}
this.setData({ heartEmoji: emoji })
},
},
})