Files
Neo-ZQYY/apps/miniprogram - 副本/miniprogram/components/heart-icon/heart-icon.ts

31 lines
539 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 > 7) {
emoji = '🧡'
} else if (s > 5) {
emoji = '💛'
} else {
emoji = '💙'
}
this.setData({ heartEmoji: emoji })
},
},
})