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

25 lines
492 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.
/**
* 星级评分转换工具函数
* 纯函数,无 wx.* 依赖
*
* API 使用 0-10 分制UI 使用 0-5 星制(支持半星)
*/
/**
* 将 0-10 分数转换为 0-5 星级
* @param score 0-10 分数
* @returns 0-5 星级值
*/
export function scoreToStar(score: number): number {
return score / 2
}
/**
* 将 0-5 星级转换为 0-10 分数
* @param star 0-5 星级值
* @returns 0-10 分数
*/
export function starToScore(star: number): number {
return star * 2
}