Skip to content

feat: 在设置页面添加主题切换按钮#18

Merged
aba2222 merged 2 commits into
aba2222:mainfrom
xiokuai:feature/theme-toggle
Feb 23, 2026
Merged

feat: 在设置页面添加主题切换按钮#18
aba2222 merged 2 commits into
aba2222:mainfrom
xiokuai:feature/theme-toggle

Conversation

@xiokuai
Copy link
Copy Markdown
Contributor

@xiokuai xiokuai commented Feb 20, 2026

Summary

  • 在账户设置页面添加主题切换功能,支持「跟随系统」「浅色」「深色」三种模式
  • 使用 localStorage 持久化用户的主题偏好,刷新页面后保留选择
  • 修改 base.html 中的主题初始化逻辑,优先读取 localStorage 中的设置

Changes

  • forum/templates/base.html: 重构主题初始化脚本,支持 localStorage 覆盖系统偏好;将 CSS 暗色背景从 @media 查询改为 [data-bs-theme="dark"] 选择器
  • forum/templates/forum/user_settings.html: 新增主题设置区域,使用 Bootstrap btn-group 单选按钮组

Test

在本地开发服务器上手动测试通过,三种主题模式均可正常切换并持久化。

Allow users to switch between light/dark/auto themes via localStorage,
instead of relying solely on OS prefers-color-scheme.
@aba2222
Copy link
Copy Markdown
Owner

aba2222 commented Feb 21, 2026

主题设置不应该在需要登录的区域(user_settings),否则未登录的用户就无法切换主题。更合适的地方应该是导航栏上。

根据 review 反馈,主题切换不应在需要登录的设置页面,
改为导航栏右侧图标按钮,未登录用户也可使用。
@aba2222 aba2222 merged commit 90352e5 into aba2222:main Feb 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants