Files
Pet3/miniprogram/utils/achievements.js
2026-06-25 18:24:29 +08:00

57 lines
1.5 KiB
JavaScript
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.
// utils/achievements.js — 成就定义(前端展示用副本)
// 解锁判定的"权威"逻辑在云函数侧(防刷);此处仅供前端渲染成就墙/进度。
// 成就基于「连续 / 累计 / 场景」,不基于「最多 / 最快」docs/05 R10
const ACHIEVEMENTS = [
{
key: 'first_walk',
name: '首遛',
desc: '第一次记录遛狗',
icon: 'flag',
progress: (stats) => Math.min(1, stats.totalWalks / 1),
},
{
key: 'week_streak',
name: '一周不断',
desc: '连续遛狗满 7 天',
icon: 'medal',
progress: (stats) => Math.min(1, stats.currentStreak / 7),
},
{
key: 'month_streak',
name: '满月坚持',
desc: '连续遛狗满 30 天',
icon: 'trophy',
progress: (stats) => Math.min(1, stats.currentStreak / 30),
},
{
key: 'rainy_warrior',
name: '雨天战士',
desc: '雨天也坚持遛狗',
icon: 'rain',
progress: () => 0, // 场景类,由事件触发
},
{
key: 'hundred_km',
name: '百里同行',
desc: '累计遛狗满 100 公里',
icon: 'walk',
progress: (stats) => Math.min(1, stats.totalDistance / 100),
},
{
key: 'early_bird',
name: '早起鸟',
desc: '在 7 点前遛狗 10 次',
icon: 'sun',
progress: (stats) => Math.min(1, (stats.earlyWalks || 0) / 10), // 场景类:累计早遛次数
},
];
const TOTAL = ACHIEVEMENTS.length;
function getDef(key) {
return ACHIEVEMENTS.find((a) => a.key === key);
}
module.exports = { ACHIEVEMENTS, TOTAL, getDef };