feat: 设置页深色模式 3 档开关 (system/light/dark)
This commit is contained in:
@@ -4,6 +4,7 @@ const planMod = require('../../utils/plan')
|
||||
const iconsMod = require('../../utils/icons')
|
||||
const cloud = require('../../utils/cloud')
|
||||
const config = require('../../config')
|
||||
const darkMod = require('../../utils/darkMode')
|
||||
|
||||
/**
|
||||
* Build the simplified plans list shown in the settings UI by overlaying
|
||||
@@ -54,6 +55,13 @@ Page({
|
||||
icons: iconsMod.build(),
|
||||
nickName: '',
|
||||
avatarUrl: '',
|
||||
// Dark mode
|
||||
darkModePref: 'system',
|
||||
darkModeOptions: [
|
||||
{ key: 'system', name: '跟随系统' },
|
||||
{ key: 'light', name: '浅色' },
|
||||
{ key: 'dark', name: '深色' }
|
||||
],
|
||||
// Editor state
|
||||
showPlanEditor: false,
|
||||
editingPlanId: '',
|
||||
@@ -100,10 +108,32 @@ Page({
|
||||
icons: iconsMod.build(theme),
|
||||
plans: buildPlansList(storage.getCustomPlans()),
|
||||
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 ---
|
||||
|
||||
onChooseAvatar(e) {
|
||||
|
||||
Reference in New Issue
Block a user