refactor(app): 重构应用主题和页面结构

- 移除动态主题切换功能,改为全局统一深色主题
- 实现自定义TabBar组件替换原生tabBar,解决iOS闪白问题
- 创建main容器页面统一管理三个tab页面的生命周期和状态
- 将所有页面的onShow/onHide等生命周期方法迁移到子组件内部
- 更新页面路径从index改为main,并调整路由跳转逻辑
- 移除theme-mixin和相关主题工具函数
- 统一页面背景色设置,优化用户体验一致性
This commit is contained in:
cg
2026-09-23 20:56:14 +08:00
parent a628b73a80
commit d335ec290a
24 changed files with 399 additions and 357 deletions
+9 -20
View File
@@ -1,13 +1,18 @@
<script>
import { getCurrentTheme, applyTheme } from './common/utils'
import client, { refreshAuthToken } from './common/api'
import wsManager from './common/websocket'
export default {
onLaunch() {
console.log('碰盏日记 App Launch')
// 初始化主题
this.initTheme()
// 一次性设置窗口背景色(深色主题),避免切换 tab 时露白底
try {
uni.setBackgroundColor({
backgroundColor: '#0B0B14',
backgroundColorTop: '#0B0B14',
backgroundColorBottom: '#0B0B14'
})
} catch (e) {}
// 尝试刷新 token
this.restoreAuth()
// 初始化 WebSocket 连接(私信功能)
@@ -19,27 +24,11 @@ export default {
},
onShow() {
console.log('App Show')
// 每次回到前台刷新主题(时间可能已变化)
this.initTheme()
},
onHide() {
console.log('App Hide')
},
methods: {
// 初始化并应用深色主题
initTheme() {
const theme = getCurrentTheme()
applyTheme(theme)
// 同步设置page元素背景色(统一深色主题)
const bgColor = '#0B0B14'
try {
uni.setBackgroundColor({
backgroundColor: bgColor,
backgroundColorTop: bgColor,
backgroundColorBottom: bgColor
})
} catch (e) {}
},
// 恢复登录态:从缓存恢复 token 并尝试刷新
async restoreAuth() {
const token = uni.getStorageSync('auth_token')
@@ -79,7 +68,7 @@ export default {
uni.reLaunch({ url: '/pages/onboarding/onboarding', fail: () => {} })
}, 100)
}
// 否则正常进入首页(index)
// 否则正常进入主容器(main),pages.json 中 main 为第一个页面
}
}
}