From 0203d8513c7bbf0c134021cf64c5b7153734f274 Mon Sep 17 00:00:00 2001 From: Lexcubia Date: Tue, 22 Apr 2025 20:53:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(.gitignore):=20=E6=B7=BB=E5=8A=A0=20di?= =?UTF-8?q?st.zip=20=E6=96=87=E4=BB=B6=E5=88=B0=E5=BF=BD=E7=95=A5=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 .gitignore 文件中添加 dist.zip,避免打包文件被版本控制 fix(styles): 优化 setTheme 函数的参数处理 - 在 setTheme 函数中增加了对 themeName 类型的检查 - 确保只有在 themeName 是字符串时才使用它,否则使用默认主题 - 这样可以防止非字符串类型的 themeName 导致的错误 --- .gitignore | 1 + src/styles/theme.js | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8cdddb7..ea3fc3d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ lerna-debug.log* node_modules dist dist-ssr +dist.zip release *.local diff --git a/src/styles/theme.js b/src/styles/theme.js index 155a5d2..263b943 100644 --- a/src/styles/theme.js +++ b/src/styles/theme.js @@ -79,9 +79,11 @@ export function applyDisplayMode(mode) { // --- Modified setTheme Function --- export function setTheme(themeName) { - const theme = themes[themeName] || themes.default // Fallback to default + // 确保 themeName 是字符串类型 + const themeKey = typeof themeName === 'string' ? themeName : 'default'; + const theme = themes[themeKey] || themes.default // Fallback to default if (!theme) { - console.error(`Theme "${themeName}" not found.`); + console.error(`Theme "${themeKey}" not found.`); return; } @@ -145,5 +147,5 @@ export function setTheme(themeName) { if (currentThemeClass) { document.body.classList.remove(currentThemeClass); } - document.body.classList.add(`theme-${themeName}`); + document.body.classList.add(`theme-${themeKey}`); } \ No newline at end of file