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
-89
View File
@@ -277,95 +277,6 @@ export function calcLocalStreak(records) {
return { streak, streakType, drankStreak, abstainStreak }
}
/**
* 主题系统:全局统一使用深色主题(琥珀夜光),已移除白天主题
*/
export function getCurrentTheme() {
return 'dark'
}
export function applyTheme(theme) {
// 同步存储当前主题
uni.setStorageSync('current_theme', theme)
// 应用导航栏和TabBar主题
applyNavBarTheme(theme)
applyTabBarTheme(theme)
}
export function applyNavBarTheme(theme) {
// 仅深色主题
try {
uni.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#0B0B14',
animation: { duration: 300, timingFunc: 'easeInOut' }
})
} catch (e) {}
}
export function applyTabBarTheme(theme) {
// 仅在 tabBar 页面上调用 setTabBarStyle,避免报错
// 页面清单直接从 pages.json 读取,新增 tab 页无需改这里
let tabBarPages = []
try {
// #ifdef MP-WEIXIN
tabBarPages = (typeof __wxConfig !== 'undefined' && __wxConfig.tabBar && __wxConfig.tabBar.list)
? __wxConfig.tabBar.list.map(t => t.pagePath)
: []
// #endif
if (!tabBarPages.length && typeof require === 'function') {
const cfg = require('../pages.json')
tabBarPages = (cfg.tabBar && cfg.tabBar.list) ? cfg.tabBar.list.map(t => t.pagePath) : []
}
} catch (e) {
tabBarPages = []
}
// 两种方式都取不到清单时兜底,保证主题正常应用
if (!tabBarPages.length) {
tabBarPages = ['pages/index/index', 'pages/circle/circle', 'pages/profile/profile']
}
const pages = getCurrentPages()
if (!pages.length) return
const currentPath = pages[pages.length - 1].route
if (!tabBarPages.includes(currentPath)) return
// 仅深色主题
const s = {
color: '#9494AC',
selectedColor: '#E8A838',
backgroundColor: '#151520',
borderStyle: 'black'
}
try {
uni.setTabBarStyle({
color: s.color,
selectedColor: s.selectedColor,
backgroundColor: s.backgroundColor,
borderStyle: s.borderStyle,
// 必须传 fail 回调吞错:不传时 uni API 返回 Promise,
// 异步 reject 无法被 try/catch 捕获,会产生 UnhandledPromiseRejection
fail: () => {}
})
} catch (e) {}
}
export function getThemeColors(theme) {
// 仅保留深色主题色值(参数保留以兼容既有调用)
return {
textPrimary: '#FFFFFF',
textSecondary: '#C0C0D2',
textTertiary: '#9494AC',
amber: '#E8A838',
bgBase: '#0B0B14',
bgCard: '#1A1A28',
cardGradStart: '#1A1510',
cardGradEnd: '#0D0B08',
borderSubtle: 'rgba(232,168,56,0.15)',
bgPlaceholder: 'rgba(255,255,255,0.03)',
emojiBg: 'rgba(232,168,56,0.08)'
}
}
/**
* 检查成就解锁
*/