Files
Neo-ZQYY/apps/miniprogram - 副本/miniprogram/components/star-rating/star-rating.ts

39 lines
692 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内部转换为 0-5 星 */
score: {
type: Number,
value: 0,
},
/** 星星尺寸 */
size: {
type: String,
value: '40rpx',
},
/** 是否只读 */
readonly: {
type: Boolean,
value: true,
},
},
observers: {
score(val: number) {
// score(0-10) → star(0-5)
const clamped = Math.max(0, Math.min(10, val))
this.setData({ starValue: clamped / 2 })
},
},
data: {
starValue: 0,
},
lifetimes: {
attached() {
const clamped = Math.max(0, Math.min(10, this.data.score))
this.setData({ starValue: clamped / 2 })
},
},
})