fix(tabBar): 切换暗黑模式后其他 tab 的底栏不跟随变暗
根因:自定义 tabBar 的 pageLifetimes.show() 不触发(微信框架
特殊行为),各 tab 页 onShow 只设了 selected 没同步主题;
onSelectDarkMode 里 getCurrentPages() 只返回当前 tab 页,
其他 tab 的 tabBar 实例未收到更新。
修复:4 个 tab 页 onShow 里 tb.setData({selected:X}) 后加
tb.updateTheme(),显式同步主题。updateTheme 内部有样式未变
则跳过的优化,不会多余渲染。
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# 2026-08-14 工作日志
|
||||
|
||||
## 修复:设置页切换暗黑模式后其他 tab 的 tabBar 不跟随变暗
|
||||
- **现象**:设置页选暗黑模式后,只有设置 tab 的底栏变暗,切到训练/记录/排行 tab 底栏仍是白色,完全退出重进才正常。
|
||||
- **根因**:自定义 tabBar 组件的 `pageLifetimes.show()` 对自定义 tabBar **不触发**(微信框架特殊行为——自定义 tabBar 由框架管理,不走普通组件的页面生命周期)。各 tab 页 `onShow` 里只做了 `tb.setData({selected:X})` 设高亮,没有同步主题;`onSelectDarkMode` 里 `getCurrentPages()` 只返回当前 tab 页(其他 tab 不在页面栈里),所以 `tb.updateTheme()` 只刷新了设置页的 tabBar 实例。
|
||||
- **修复**:4 个 tab 页 `onShow` 里获取 tabBar 后,在 `setData({selected:X})` 之后加一行 `tb.updateTheme()`。`updateTheme()` 内部调 `applyThemeToPage(this)`(有"样式未变则跳过"的优化),不会产生多余渲染。涉及 `pages/index/index.js`、`pages/records/records.js`、`pages/leaderboard/leaderboard.js`、`pages/settings/settings.js`。
|
||||
- **教训**:自定义 tabBar 不能依赖 `pageLifetimes` 做状态同步,必须在各 tab 页 `onShow` 里显式调 `this.getTabBar()` 更新。
|
||||
@@ -12,6 +12,7 @@
|
||||
- **隐私协议在 MP 后台配置,不在 app.json**:`chooseAvatar` 属隐私接口,需在小程序管理后台「设置→服务内容声明→用户隐私保护指引」声明「用户信息(头像/昵称)」。代码里(app.json)看不到隐私配置是正常的;判断隐私合规**先确认后台指引状态**,别只看代码就下"审核风险"结论。已上架运行 = 后台已配好。`__usePrivacyCheck__:true` 仅本地调试用,正式版非必须。
|
||||
- **App.onLaunch 的 async/await 不阻塞首屏**:微信框架是「非阻塞生命周期调度」——onLaunch 被调用但页面 onLoad/onShow 并行推进,不等 onLaunch 内 Promise resolve。所以 app.js 里 `await cloud.pullAll()` 不会卡首屏,只是 await 之后的同步逻辑延迟执行。判断启动性能**别把 onLaunch 的 await 当阻塞**。
|
||||
- **代码审查避免过度判断**:给本项目做问题分析时,勿把"合理设计选择/优化建议"拔高成"问题/风险"。已被纠错的判断:①隐私协议缺失(实为后台配置,代码看不到)②onLaunch await 阻塞启动(机制理解错)③组件默认 isolated 不一致(实为合理分层)。下结论前先核实机制事实,区分"真 bug / 可优化 / 合理设计"。
|
||||
- **自定义 tabBar 的 `pageLifetimes` 不触发**:微信框架的自定义 tabBar 由框架管理,不走普通自定义组件的页面生命周期钩子(`pageLifetimes.show/hide` 不触发)。因此主题/暗黑模式等状态同步**不能依赖 `pageLifetimes.show`**,必须在各 tab 页 `onShow` 里显式调 `this.getTabBar()` 更新(如 `tb.updateTheme()`)。`getCurrentPages()` 也只返回当前 tab 页(其他 tab 不在页面栈),跨 tab 通知无效。
|
||||
|
||||
## 排行榜架构(2026-07-28+,云函数 `cloudfunctions/leaderboard`)
|
||||
- **预计算快照**:定时触发器(每 4min)`_rebuildSnapshots()` 扫 `plank_data` 算 day/month/year/endurance 四榜写 `leaderboard_snapshot`;客户端 99% 走 `_serveFromSnapshot()`(≈50ms),仅训练后 `force=true` 那次实时重算+回写。**改后须重新部署云函数**(定时器随部署注册)。
|
||||
|
||||
@@ -7,7 +7,7 @@ module.exports = {
|
||||
version: 'v3.2',
|
||||
|
||||
/** 最后更新日期,外显在设置页「关于」 */
|
||||
updatedAt: '2026-08-12',
|
||||
updatedAt: '2026-08-14',
|
||||
|
||||
/** 开发者名称 / 微信号,设置页点击可复制 */
|
||||
developer: '三口一瓶',
|
||||
|
||||
@@ -52,7 +52,10 @@ Page({
|
||||
themeMod.applyThemeToPage(this)
|
||||
try {
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 0 })
|
||||
if (tb) {
|
||||
tb.setData({ selected: 0 })
|
||||
tb.updateTheme()
|
||||
}
|
||||
} catch (e) {}
|
||||
// Skip the first onShow to avoid double-refresh; subsequent tab switches still refresh.
|
||||
if (this._firstShow) {
|
||||
|
||||
@@ -36,7 +36,10 @@ Page({
|
||||
this.setData({ theme, icons: iconsMod.build(theme) })
|
||||
try {
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 2 })
|
||||
if (tb) {
|
||||
tb.setData({ selected: 2 })
|
||||
tb.updateTheme()
|
||||
}
|
||||
} catch (e) {}
|
||||
// 训练完设的强刷标志:下次进排行榜跳过云函数缓存,立刻拿到含新记录的数据
|
||||
let force = false
|
||||
|
||||
@@ -50,7 +50,10 @@ Page({
|
||||
themeMod.applyThemeToPage(this)
|
||||
try {
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 1 })
|
||||
if (tb) {
|
||||
tb.setData({ selected: 1 })
|
||||
tb.updateTheme()
|
||||
}
|
||||
} catch (e) {}
|
||||
if (this._firstShow) {
|
||||
this._firstShow = false
|
||||
|
||||
@@ -114,7 +114,10 @@ Page({
|
||||
onShow() {
|
||||
try {
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 3 })
|
||||
if (tb) {
|
||||
tb.setData({ selected: 3 })
|
||||
tb.updateTheme()
|
||||
}
|
||||
} catch (e) {}
|
||||
themeMod.applyThemeToPage(this)
|
||||
const theme = themeMod.getCurrentTheme()
|
||||
|
||||
Reference in New Issue
Block a user