✨ 添加主题切换功能:支持暗色/亮色玻璃主题
功能说明: - 管理员可在系统设置中配置全局默认主题 - 普通用户可在设置页面选择:跟随全局/暗色/亮色 - 分享页面自动继承分享者的主题偏好 - 主题设置实时保存,刷新后保持 技术实现: - 后端:数据库添加theme_preference字段,新增主题API - 前端:CSS变量实现主题切换,localStorage缓存避免闪烁 - 分享页:加载时获取分享者主题设置 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
/* 防止 Vue 初始化前显示原始模板 */
|
||||
[v-cloak] { display: none !important; }
|
||||
|
||||
/* ========== 暗色主题 CSS 变量 ========== */
|
||||
/* ========== 暗色主题 CSS 变量(默认) ========== */
|
||||
:root {
|
||||
--bg-primary: #0a0a0f;
|
||||
--bg-secondary: #12121a;
|
||||
@@ -31,6 +31,31 @@
|
||||
--warning: #f59e0b;
|
||||
}
|
||||
|
||||
/* ========== 亮色玻璃主题 ========== */
|
||||
.light-theme {
|
||||
--bg-primary: #f0f4f8;
|
||||
--bg-secondary: #ffffff;
|
||||
--bg-card: rgba(255, 255, 255, 0.7);
|
||||
--bg-card-hover: rgba(255, 255, 255, 0.9);
|
||||
--glass-border: rgba(102, 126, 234, 0.2);
|
||||
--glass-border-hover: rgba(102, 126, 234, 0.4);
|
||||
--text-primary: #1a1a2e;
|
||||
--text-secondary: rgba(26, 26, 46, 0.7);
|
||||
--text-muted: rgba(26, 26, 46, 0.5);
|
||||
--accent-1: #5a67d8;
|
||||
--accent-2: #6b46c1;
|
||||
--accent-3: #d53f8c;
|
||||
--glow: rgba(90, 103, 216, 0.3);
|
||||
}
|
||||
|
||||
/* 亮色主题背景渐变 */
|
||||
body.light-theme::before {
|
||||
background:
|
||||
radial-gradient(ellipse at top right, rgba(102, 126, 234, 0.12) 0%, transparent 50%),
|
||||
radial-gradient(ellipse at bottom left, rgba(118, 75, 162, 0.12) 0%, transparent 50%),
|
||||
linear-gradient(135deg, #e0e7ff 0%, #f0f4f8 50%, #fdf2f8 100%);
|
||||
}
|
||||
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
@@ -746,6 +771,8 @@
|
||||
loading: true,
|
||||
errorMessage: '',
|
||||
viewMode: "grid", // 视图模式: grid 大图标, list 列表(默认大图标)
|
||||
// 主题
|
||||
currentTheme: 'dark',
|
||||
// 媒体预览
|
||||
showImageViewer: false,
|
||||
showVideoPlayer: false,
|
||||
@@ -777,10 +804,36 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// 加载分享页面主题(基于分享者的主题偏好)
|
||||
await this.loadTheme();
|
||||
|
||||
// 尝试验证分享
|
||||
await this.verifyShare();
|
||||
},
|
||||
|
||||
// 加载主题
|
||||
async loadTheme() {
|
||||
try {
|
||||
const response = await axios.get(`${this.apiBase}/api/share/${this.shareCode}/theme`);
|
||||
if (response.data.success) {
|
||||
this.currentTheme = response.data.theme;
|
||||
this.applyTheme(this.currentTheme);
|
||||
}
|
||||
} catch (error) {
|
||||
// 出错时使用默认暗色主题
|
||||
console.error('加载主题失败:', error);
|
||||
}
|
||||
},
|
||||
|
||||
// 应用主题
|
||||
applyTheme(theme) {
|
||||
if (theme === 'light') {
|
||||
document.body.classList.add('light-theme');
|
||||
} else {
|
||||
document.body.classList.remove('light-theme');
|
||||
}
|
||||
},
|
||||
|
||||
async verifyShare() {
|
||||
this.errorMessage = '';
|
||||
this.loading = true;
|
||||
|
||||
Reference in New Issue
Block a user