feat: 设置页深色模式 3 档开关 (system/light/dark)

This commit is contained in:
2026-07-08 11:39:32 +08:00
parent 5bbd84868a
commit e0e5f6b449
2 changed files with 51 additions and 1 deletions
+31 -1
View File
@@ -4,6 +4,7 @@ const planMod = require('../../utils/plan')
const iconsMod = require('../../utils/icons') const iconsMod = require('../../utils/icons')
const cloud = require('../../utils/cloud') const cloud = require('../../utils/cloud')
const config = require('../../config') const config = require('../../config')
const darkMod = require('../../utils/darkMode')
/** /**
* Build the simplified plans list shown in the settings UI by overlaying * Build the simplified plans list shown in the settings UI by overlaying
@@ -54,6 +55,13 @@ Page({
icons: iconsMod.build(), icons: iconsMod.build(),
nickName: '', nickName: '',
avatarUrl: '', avatarUrl: '',
// Dark mode
darkModePref: 'system',
darkModeOptions: [
{ key: 'system', name: '跟随系统' },
{ key: 'light', name: '浅色' },
{ key: 'dark', name: '深色' }
],
// Editor state // Editor state
showPlanEditor: false, showPlanEditor: false,
editingPlanId: '', editingPlanId: '',
@@ -100,10 +108,32 @@ Page({
icons: iconsMod.build(theme), icons: iconsMod.build(theme),
plans: buildPlansList(storage.getCustomPlans()), plans: buildPlansList(storage.getCustomPlans()),
nickName: profile.nickname || '', nickName: profile.nickname || '',
avatarUrl: profile.avatarUrl || '' avatarUrl: profile.avatarUrl || '',
darkModePref: darkMod.getPref()
}) })
}, },
applyThemeToPage() {
themeMod.applyThemeToPage(this)
},
onSelectDarkMode(e) {
const key = e.currentTarget.dataset.key
darkMod.setPref(key)
this.setData({ darkModePref: key })
// 通知所有已打开页面重渲染
const pages = getCurrentPages()
pages.forEach(p => {
if (p && typeof p.applyThemeToPage === 'function') {
p.applyThemeToPage()
} else if (p && p.route) {
// Tab page without method: re-apply via themeMod
try { themeMod.applyThemeToPage(p) } catch (e) {}
}
})
themeMod.applyThemeToPage(this)
},
// --- Profile handlers --- // --- Profile handlers ---
onChooseAvatar(e) { onChooseAvatar(e) {
+20
View File
@@ -54,6 +54,26 @@
</view> </view>
</ui-card> </ui-card>
<!-- 深色模式 -->
<ui-card variant="in">
<view class="section-header">
<image class="section-icon" src="{{icons.skinFill}}" mode="aspectFit"></image>
<text class="section-title">深色模式</text>
</view>
<view class="theme-list">
<view
class="theme-item {{darkModePref === item.key ? 'active' : ''}}"
wx:for="{{darkModeOptions}}"
wx:key="key"
data-key="{{item.key}}"
bindtap="onSelectDarkMode"
>
<text class="theme-name">{{item.name}}</text>
<image class="theme-check-img" wx:if="{{darkModePref === item.key}}" src="{{icons.check}}" mode="aspectFit"></image>
</view>
</view>
</ui-card>
<!-- 训练计划选择 --> <!-- 训练计划选择 -->
<ui-card variant="in"> <ui-card variant="in">
<view class="section-header"> <view class="section-header">