Files
Neo-ZQYY/apps/demo-miniprogram/miniprogram/utils/rating.ts
Neo 779b2f6d52 chore: v1 整理 — 清理历史文件、DDL 合并、文档归档
- 清理 1155 个已删除的历史文件(废弃 prompt_logs、tmp、旧 ops 脚本)
- export/ 数据文件从 git 移除(已在 .gitignore)
- demo-miniprogram 从 tmp/ 移入 apps/,添加 CLAUDE.md 注解
- DDL 合并:完整 schema 定义填充到 db/*/schemas/(从 docs/database/ddl/ 复制)
- 39 个 v1 迁移脚本归档到 db/_archived/migrations_v1_merged/
- 4 个迁移变更类 BD_Manual 文档归档到 docs/database/_archived/
- .gitignore 补充 .vite/ 和 apps/*.zip
- settings.json 添加 effortLevel 默认配置
- scripts/ops/ 新增运维脚本入库

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 00:39:27 +08:00

44 lines
1.0 KiB
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
}
/**
* 将 0-10 分数四舍五入到最近 0.5 星
* 用于后端评分 → 半星展示
* @param score 0-10 分数
* @returns 0-5 星(步长 0.5
*/
export function scoreToHalfStar(score: number): number {
return Math.round((score / 2) * 2) / 2
}
/**
* 判断是否为未评分状态
* score 为 null / undefined / 0 时视为未评分
* @returns true 时展示 '--' 替代星星
*/
export function isUnrated(score: number | null | undefined): boolean {
return score === null || score === undefined || score === 0
}