feat(theme): 完善顶部导航栏与底部菜单浅色暖色系适配及多端Tab生命周期同步
这个提交包含在:
@@ -28,7 +28,17 @@ export const THEMES = {
|
||||
textPrimary: '#F8FAFC',
|
||||
textSecondary: '#94A3B8',
|
||||
textMuted: '#64748B',
|
||||
shadowBrand: '0 8rpx 24rpx rgba(99, 102, 241, 0.35)'
|
||||
shadowBrand: '0 8rpx 24rpx rgba(99, 102, 241, 0.35)',
|
||||
navBar: {
|
||||
backgroundColor: '#0A0F1D',
|
||||
frontColor: '#ffffff'
|
||||
},
|
||||
tabBar: {
|
||||
color: '#94A3B8',
|
||||
selectedColor: '#6366F1',
|
||||
backgroundColor: '#151D30',
|
||||
borderStyle: 'black'
|
||||
}
|
||||
}
|
||||
},
|
||||
[THEME_KEYS.WARM]: {
|
||||
@@ -50,13 +60,61 @@ export const THEMES = {
|
||||
textPrimary: '#1C1917',
|
||||
textSecondary: '#57534E',
|
||||
textMuted: '#78716C',
|
||||
shadowBrand: '0 8rpx 24rpx rgba(234, 88, 12, 0.25)'
|
||||
shadowBrand: '0 8rpx 24rpx rgba(234, 88, 12, 0.25)',
|
||||
navBar: {
|
||||
backgroundColor: '#FDFBF7',
|
||||
frontColor: '#000000'
|
||||
},
|
||||
tabBar: {
|
||||
color: '#78716C',
|
||||
selectedColor: '#EA580C',
|
||||
backgroundColor: '#FFFFFF',
|
||||
borderStyle: 'white'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'peiwan_app_theme';
|
||||
|
||||
/**
|
||||
* 将主题色彩同步应用至小程序与原生顶部导航栏及底部 TabBar
|
||||
*/
|
||||
export function applyThemeToNativeUI(themeKey) {
|
||||
const theme = THEMES[themeKey] || THEMES[THEME_KEYS.COOL];
|
||||
const { navBar, tabBar } = theme.tokens;
|
||||
|
||||
// 1. 设置顶部系统导航栏颜色
|
||||
try {
|
||||
if (typeof uni !== 'undefined' && uni.setNavigationBarColor) {
|
||||
uni.setNavigationBarColor({
|
||||
frontColor: navBar.frontColor,
|
||||
backgroundColor: navBar.backgroundColor,
|
||||
animation: {
|
||||
duration: 200,
|
||||
timingFunc: 'easeOut'
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略特定页面无系统导航栏异常
|
||||
}
|
||||
|
||||
// 2. 设置底部原生 TabBar 菜单颜色
|
||||
try {
|
||||
if (typeof uni !== 'undefined' && uni.setTabBarStyle) {
|
||||
uni.setTabBarStyle({
|
||||
color: tabBar.color,
|
||||
selectedColor: tabBar.selectedColor,
|
||||
backgroundColor: tabBar.backgroundColor,
|
||||
borderStyle: tabBar.borderStyle
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略非 TabBar 页面抛出的异常
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前持久化的主题标识
|
||||
*/
|
||||
@@ -88,7 +146,7 @@ export function getCurrentTokens() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换全局主题并持久化,广播全局事件
|
||||
* 切换全局主题并持久化,广播全局事件,同步更新顶部与底部 UI
|
||||
*/
|
||||
export function setTheme(themeKey) {
|
||||
const targetKey = THEMES[themeKey] ? themeKey : THEME_KEYS.COOL;
|
||||
@@ -97,6 +155,9 @@ export function setTheme(themeKey) {
|
||||
} catch (e) {
|
||||
// 忽略持久化异常
|
||||
}
|
||||
|
||||
// 同步原生顶部与底部栏色彩
|
||||
applyThemeToNativeUI(targetKey);
|
||||
|
||||
// 广播主题变更事件
|
||||
try {
|
||||
|
||||
在新工单中引用
屏蔽一个用户