From 66ac576082f91f76b01c6a061bf3cf198967dd91 Mon Sep 17 00:00:00 2001 From: Yuzhiran Dev Date: Sat, 11 Jul 2026 01:39:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20tabBar=20=E8=B7=9F=E9=9A=8F=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pages.json 默认配色改为亮色(白底紫字) App.vue + settings.vue 用 uni.setTabBarStyle() 动态切换 暗色模式:黑底紫字(rgba(255,255,255,0.25) / #b388ff / #08080f) 亮色模式:白底紫字(rgba(0,0,0,0.35) / #7c4dff / #ffffff) --- frontend/ai-dimension/src/App.vue | 28 +++++++++++++++++-- frontend/ai-dimension/src/pages.json | 22 +++++++-------- .../src/pages/settings/settings.vue | 16 +++++++++-- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/frontend/ai-dimension/src/App.vue b/frontend/ai-dimension/src/App.vue index 9ea99f6..03e11ab 100644 --- a/frontend/ai-dimension/src/App.vue +++ b/frontend/ai-dimension/src/App.vue @@ -27,7 +27,7 @@ function initTheme() { function applyTheme(theme) { try { - // H5 环境直接操作 document + // H5 环境:操作 document class const root = document.documentElement if (theme === 'dark') { root.classList.add('theme-dark') @@ -37,7 +37,31 @@ function applyTheme(theme) { root.classList.add('theme-light') } } catch (e) { - // 小程序环境:document 不存在,直接忽略 + // 小程序环境:document 不存在 + } + // 小程序 tabBar 原生组件同步切换 + applyTabBarTheme(theme) +} + +function applyTabBarTheme(theme) { + try { + if (theme === 'dark') { + uni.setTabBarStyle({ + color: 'rgba(255,255,255,0.25)', + selectedColor: '#b388ff', + backgroundColor: '#08080f', + borderStyle: 'black' + }) + } else { + uni.setTabBarStyle({ + color: 'rgba(0,0,0,0.35)', + selectedColor: '#7c4dff', + backgroundColor: '#ffffff', + borderStyle: 'white' + }) + } + } catch (e) { + // H5 环境 setTabBarStyle 可能不支持 } } diff --git a/frontend/ai-dimension/src/pages.json b/frontend/ai-dimension/src/pages.json index 2b2c9ba..a0a08c5 100644 --- a/frontend/ai-dimension/src/pages.json +++ b/frontend/ai-dimension/src/pages.json @@ -18,21 +18,21 @@ {"path": "pages/profile/profile", "style": {"navigationBarTitleText": "我的", "navigationStyle": "custom"}} ], "globalStyle": { - "navigationBarTextStyle": "white", + "navigationBarTextStyle": "black", "navigationBarTitleText": "宇之然AI维度", - "navigationBarBackgroundColor": "#050508", - "backgroundColor": "#050508", - "backgroundColorTop": "#050508", - "backgroundColorBottom": "#050508", + "navigationBarBackgroundColor": "#f5f5f7", + "backgroundColor": "#f5f5f7", + "backgroundColorTop": "#f5f5f7", + "backgroundColorBottom": "#f5f5f7", "app-plus": { - "background": "#050508" + "background": "#f5f5f7" } }, "tabBar": { - "color": "rgba(255,255,255,0.25)", - "selectedColor": "#b388ff", - "backgroundColor": "#08080f", - "borderStyle": "black", + "color": "rgba(0,0,0,0.35)", + "selectedColor": "#7c4dff", + "backgroundColor": "#ffffff", + "borderStyle": "white", "list": [ {"pagePath": "pages/index/index", "text": "探索"}, {"pagePath": "pages/chat/chat", "text": "问答"}, @@ -40,4 +40,4 @@ {"pagePath": "pages/profile/profile", "text": "我的"} ] } -} +} \ No newline at end of file diff --git a/frontend/ai-dimension/src/pages/settings/settings.vue b/frontend/ai-dimension/src/pages/settings/settings.vue index e75247e..c1c2f59 100644 --- a/frontend/ai-dimension/src/pages/settings/settings.vue +++ b/frontend/ai-dimension/src/pages/settings/settings.vue @@ -99,9 +99,19 @@ function applyTheme(theme) { root.classList.remove('theme-dark') root.classList.add('theme-light') } - } catch (e) { - // mini-program 忽略 - } + } catch (e) {} + // tabBar 同步 + applyTabBarTheme(theme) +} + +function applyTabBarTheme(theme) { + try { + if (theme === 'dark') { + uni.setTabBarStyle({ color: 'rgba(255,255,255,0.25)', selectedColor: '#b388ff', backgroundColor: '#08080f', borderStyle: 'black' }) + } else { + uni.setTabBarStyle({ color: 'rgba(0,0,0,0.35)', selectedColor: '#7c4dff', backgroundColor: '#ffffff', borderStyle: 'white' }) + } + } catch (e) {} } function showAbout() {