首页和登录页支持全局主题

- index.html 添加亮色主题 CSS 变量和样式
- index.html 添加 JS 自动加载全局主题
- app.js 修改 initTheme,未登录时从公开 API 获取全局主题
- 登录页面现在会跟随管理员设置的全局主题

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-28 00:00:53 +08:00
parent 64268135aa
commit 4aaf6765eb
2 changed files with 66 additions and 1 deletions

View File

@@ -288,12 +288,24 @@ createApp({
methods: { methods: {
// ========== 主题管理 ========== // ========== 主题管理 ==========
// 初始化主题 // 初始化主题
initTheme() { async initTheme() {
// 先从localStorage读取避免页面闪烁 // 先从localStorage读取避免页面闪烁
const savedTheme = localStorage.getItem('theme'); const savedTheme = localStorage.getItem('theme');
if (savedTheme) { if (savedTheme) {
this.applyTheme(savedTheme); this.applyTheme(savedTheme);
} }
// 如果没有登录从公开API获取全局主题
if (!this.token) {
try {
const res = await axios.get(`${this.apiBase}/api/public/theme`);
if (res.data.success) {
this.globalTheme = res.data.theme;
this.applyTheme(res.data.theme);
}
} catch (e) {
console.log('无法加载全局主题');
}
}
}, },
// 加载用户主题设置(登录后调用) // 加载用户主题设置(登录后调用)

View File

@@ -22,6 +22,7 @@
box-sizing: border-box; box-sizing: border-box;
} }
/* 暗色主题(默认) */
:root { :root {
--bg-primary: #0a0a0f; --bg-primary: #0a0a0f;
--bg-secondary: #12121a; --bg-secondary: #12121a;
@@ -35,6 +36,43 @@
--glow: rgba(102, 126, 234, 0.4); --glow: rgba(102, 126, 234, 0.4);
} }
/* 亮色主题 */
.light-theme {
--bg-primary: #f0f4f8;
--bg-secondary: #ffffff;
--glass: rgba(102, 126, 234, 0.05);
--glass-border: rgba(102, 126, 234, 0.15);
--text-primary: #1a1a2e;
--text-secondary: rgba(26, 26, 46, 0.7);
--accent-1: #5a67d8;
--accent-2: #6b46c1;
--accent-3: #d53f8c;
--glow: rgba(90, 103, 216, 0.3);
}
/* 亮色主题特定样式 */
body.light-theme .navbar {
background: rgba(255, 255, 255, 0.85);
}
body.light-theme .grid-bg {
background-image:
linear-gradient(rgba(102, 126, 234, 0.05) 1px, transparent 1px),
linear-gradient(90deg, rgba(102, 126, 234, 0.05) 1px, transparent 1px);
}
body.light-theme .gradient-orb {
opacity: 0.3;
}
body.light-theme .feature-card {
background: rgba(255, 255, 255, 0.7);
}
body.light-theme .tech-bar {
background: rgba(255, 255, 255, 0.8);
}
body { body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg-primary); background: var(--bg-primary);
@@ -610,5 +648,20 @@
玩玩云 © 2025 玩玩云 © 2025
</div> </div>
</div> </div>
<script>
// 加载全局主题
(async function() {
try {
const response = await fetch('/api/public/theme');
const data = await response.json();
if (data.success && data.theme === 'light') {
document.body.classList.add('light-theme');
}
} catch (e) {
console.log('无法加载主题设置');
}
})();
</script>
</body> </body>
</html> </html>