From c1d19b854b20831b1f902cc5063828df0c0a1f0b Mon Sep 17 00:00:00 2001 From: CH-122 <1521930938@qq.com> Date: Fri, 15 Aug 2025 14:52:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=8B=E6=9C=BA=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=A0=8F=E6=9A=97=E9=BB=91=E6=A8=A1=E5=BC=8F=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E6=98=BE=E7=A4=BA=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend_nuxt/nuxt.config.ts | 23 ++++++++++++++++++++++- frontend_nuxt/utils/theme.js | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/frontend_nuxt/nuxt.config.ts b/frontend_nuxt/nuxt.config.ts index 3c680c484..e11a587a9 100644 --- a/frontend_nuxt/nuxt.config.ts +++ b/frontend_nuxt/nuxt.config.ts @@ -26,7 +26,28 @@ export default defineNuxtConfig({ const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; const theme = mode === 'dark' || mode === 'light' ? mode : (prefersDark ? 'dark' : 'light'); document.documentElement.dataset.theme = theme; - } catch (e) {} + + + let themeColor = '#fff'; + if (theme === 'dark') { + themeColor = '#333'; + } else { + themeColor = '#ffffff'; + } + + const androidMeta = document.createElement('meta'); + androidMeta.name = 'theme-color'; + androidMeta.content = themeColor; + + const iosMeta = document.createElement('meta'); + iosMeta.name = 'apple-mobile-web-app-status-bar-style'; + iosMeta.content = themeColor; + + document.head.appendChild(androidMeta); + document.head.appendChild(iosMeta); + } catch (e) { + console.warn('Theme initialization failed:', e); + } })(); `, }, diff --git a/frontend_nuxt/utils/theme.js b/frontend_nuxt/utils/theme.js index d27fbc223..816fbe987 100644 --- a/frontend_nuxt/utils/theme.js +++ b/frontend_nuxt/utils/theme.js @@ -24,6 +24,29 @@ function apply(mode) { : mode if (root.dataset.theme === newMode) return root.dataset.theme = newMode + + // 更新 meta 标签 + const androidMeta = document.querySelector('meta[name="theme-color"]') + const iosMeta = document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]') + const themeColor = getComputedStyle(document.documentElement).getPropertyValue('--background-color').trim(); + + if (androidMeta) { + androidMeta.content = themeColor + } else { + const newAndroidMeta = document.createElement('meta') + newAndroidMeta.name = 'theme-color' + newAndroidMeta.content = themeColor + document.head.appendChild(newAndroidMeta) + } + + if (iosMeta) { + iosMeta.content = themeColor + } else { + const newIosMeta = document.createElement('meta') + newIosMeta.name = 'apple-mobile-web-app-status-bar-style' + newIosMeta.content = themeColor + document.head.appendChild(newIosMeta) + } } export function initTheme() {