feat(leaderboard): 新增耐力榜(全局单次最久 top10) + 领奖台日期两行 + 顶部哲理文案

- 云函数支持 endurance 周期:遍历全部 records 取 max(duration) 及 bestDate
- 客户端新增耐力榜 tab(maxRank=10),未上榜时在底部 my-bar 显示最佳成绩+产生时间
- 领奖台底座(耐力榜)单次日期拆成「日期+时间」两行,统一三阶底座高度修复第3名贴顶
- 领奖台顶部新增哲理文案,配置进 config.js(leaderboardPodiumSlogan),斜体金句卡片样式
This commit is contained in:
2026-07-31 09:30:30 +08:00
parent fca3e32d04
commit 1589d6c387
5 changed files with 174 additions and 30 deletions
+83 -16
View File
@@ -9,11 +9,13 @@ Page({
theme: { primary: '#FF6B35', primaryLight: '#FF8C5A', primaryBg: '#FFF3ED', primaryRgb: '255,107,53' },
themeStyle: themeMod.BASE_VARS,
periods: [
{ key: 'day', label: '日榜' },
{ key: 'month', label: '月榜' },
{ key: 'year', label: '年榜' }
{ key: 'day', label: '日榜', maxRank: config.leaderboardMaxRank },
{ key: 'month', label: '月榜', maxRank: config.leaderboardMaxRank },
{ key: 'year', label: '年榜', maxRank: config.leaderboardMaxRank },
{ key: 'endurance', label: '耐力', maxRank: 10 }
],
activePeriod: 'day',
podiumSlogan: config.leaderboardPodiumSlogan,
rankedList: [],
myEntry: null,
loading: false,
@@ -68,6 +70,8 @@ Page({
this._fetchSeq = (this._fetchSeq || 0) + 1
const seq = this._fetchSeq
const period = this.data.activePeriod
const periodObj = this.data.periods.find(p => p.key === period)
const maxRank = (periodObj && periodObj.maxRank) || config.leaderboardMaxRank
// 乐观缓存:命中该 period 的近期缓存就先秒显旧数据,后台再静默拉新。
// 命中时不进 loading 骨架屏(避免旧数据被空白覆盖),用 refreshing 标记
@@ -91,7 +95,7 @@ Page({
name: 'leaderboard',
data: {
period,
maxRank: config.leaderboardMaxRank,
maxRank,
force: !!force
}
}).then(res => {
@@ -116,15 +120,35 @@ Page({
},
_applyResult(result) {
const list = (result.ranked || []).map(item => ({
...item,
durationText: util.formatDuration(item.duration)
}))
const myEntry = result.myEntry ? {
...result.myEntry,
durationText: util.formatDuration(result.myEntry.duration),
isMe: true
} : null
const isEndurance = this.data.activePeriod === 'endurance'
const list = (result.ranked || []).map(item => {
const base = { ...item, durationText: util.formatDuration(item.duration) }
if (isEndurance) {
const { date, time } = this._splitBestDate(item.bestDate)
base.subText = this._formatBestDate(item.bestDate)
base.subDate = date
base.subTime = time
} else {
base.subText = `${item.sessions}`
}
return base
})
const myEntry = result.myEntry ? (() => {
const base = {
...result.myEntry,
durationText: util.formatDuration(result.myEntry.duration),
isMe: true
}
if (isEndurance) {
const { date, time } = this._splitBestDate(result.myEntry.bestDate)
base.subText = this._formatBestDate(result.myEntry.bestDate)
base.subDate = date
base.subTime = time
} else {
base.subText = `${result.myEntry.sessions}`
}
return base
})() : null
const empty = list.length === 0 && !myEntry
this.setData({
rankedList: list,
@@ -141,11 +165,34 @@ Page({
_applyLocal() {
const period = this.data.activePeriod
const allRecords = Object.values(storage.getRecords()).flat()
const profile = storage.getProfile()
const localName = profile.nickname || '我'
// 耐力榜本地兜底:取本地全部记录里单次最久 + 其日期
if (period === 'endurance') {
let bestDuration = 0
let bestDate = ''
allRecords.forEach(r => {
const dur = Number(r.duration) || 0
if (dur > bestDuration) { bestDuration = dur; bestDate = r.date }
})
if (bestDuration > 0) {
const { date, time } = this._splitBestDate(bestDate)
const entry = {
rank: 1, openid: 'local', name: localName, nickname: profile.nickname || '',
duration: bestDuration, durationText: util.formatDuration(bestDuration),
bestDate, subText: this._formatBestDate(bestDate), subDate: date, subTime: time
}
this.setData({ rankedList: [entry], myEntry: { ...entry, isMe: true }, loading: false, refreshing: false, empty: false })
} else {
this.setData({ loading: false, refreshing: false, empty: true })
}
return
}
const today = storage.getToday()
const thisMonth = today.substring(0, 7)
const thisYear = String(new Date().getFullYear())
const profile = storage.getProfile()
const localName = profile.nickname || '我'
let duration = 0
let sessions = 0
@@ -166,6 +213,26 @@ Page({
}
},
/**
* 把记录里的 "YYYY-MM-DD HH:MM:SS" 截成 "YYYY-MM-DD HH:MM"(去掉秒),
* 纯日期串原样返回。耐力榜用其展示单次的"产生时间"。
*/
_formatBestDate(s) {
if (!s || typeof s !== 'string') return ''
if (s.length >= 16) return s.substring(0, 16)
return s
},
/**
* 把 "YYYY-MM-DD HH:MM"(来自 _formatBestDate)拆成
* { date: 'YYYY-MM-DD', time: 'HH:MM' },供领奖台底座两行展示耐力榜的"单次日期"。
*/
_splitBestDate(s) {
const f = this._formatBestDate(s)
if (f && f.length >= 11) return { date: f.substring(0, 10), time: f.substring(11) }
return { date: f || '', time: '' }
},
/**
* 分享给朋友 — 排行榜页。把用户当前名次写进标题,有"攀比"属性,
* 分享欲望会强一些。
@@ -175,7 +242,7 @@ Page({
const s = config.share.leaderboard
// myEntry.rank 依赖云函数返回,缺失时回退静态 title,避免出现"排第 undefined"
if (me && me.rank) {
const periodLabel = { day: '日', month: '月', year: '年' }[this.data.activePeriod] || ''
const periodLabel = { day: '日', month: '月', year: '年', endurance: '耐力' }[this.data.activePeriod] || ''
return {
title: s.titleTemplate.replace('{period}', periodLabel).replace('{rank}', me.rank),
path: s.path