8c7f633541
- var→const/let, function→arrow/class across all 13 JS files - Timer: prototype→class with ES6 getters - plan days: IIFE→Array.from declarative generation - storage/plan: unified formatDate via util.js - Bugfix: getPlanDay now filters by planId (plan switch accuracy) - Bugfix: getTodayRecord searches all months (cross-month boundary) - WXML/WXSS unchanged; public API unchanged
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
const { formatDate } = require('./util')
|
|
|
|
const plans = {
|
|
beginner: {
|
|
id: 'beginner',
|
|
name: '初级 (7天)',
|
|
totalDays: 7,
|
|
description: '适合初学者,从30秒起步',
|
|
days: Array.from({ length: 7 }, (_, i) => ({ day: i + 1, target: 30 + i * 10 }))
|
|
},
|
|
intermediate: {
|
|
id: 'intermediate',
|
|
name: '中级 (14天)',
|
|
totalDays: 14,
|
|
description: '有一定基础,从60秒起步',
|
|
days: Array.from({ length: 14 }, (_, i) => {
|
|
const pair = Math.floor(i / 2)
|
|
return { day: i + 1, target: 60 + pair * 15 }
|
|
})
|
|
},
|
|
advanced: {
|
|
id: 'advanced',
|
|
name: '高级 (30天)',
|
|
totalDays: 30,
|
|
description: '挑战自我,从90秒起步',
|
|
days: Array.from({ length: 30 }, (_, i) => ({
|
|
day: i + 1,
|
|
target: 90 + Math.floor(i / 3) * 15
|
|
}))
|
|
}
|
|
}
|
|
|
|
const getPlan = (planId) => plans[planId] || plans.beginner
|
|
|
|
const getTodayTarget = (planId, currentDay) => {
|
|
const plan = getPlan(planId)
|
|
const day = plan.days.find(d => d.day === currentDay)
|
|
return day ? day.target : plan.days[0].target
|
|
}
|
|
|
|
const getPlanDay = (planId, records) => {
|
|
const plan = getPlan(planId)
|
|
const today = formatDate(new Date())
|
|
const trainedDays = new Set(
|
|
records
|
|
.filter(r => r.date !== today && r.planId === planId)
|
|
.map(r => r.date)
|
|
).size
|
|
return Math.min(trainedDays + 1, plan.totalDays)
|
|
}
|
|
|
|
module.exports = { plans, getPlan, getTodayTarget, getPlanDay }
|