fb3bc6c045
Root cause: WXSS compiler resolves var(--primary) at compile time
against page{} declarations in app.wxss. The orange defaults
(--primary:#FF6B35 etc.) were being baked into compiled WXSS,
so the inline style theme override on .container was ignored.
Records and settings pages always rendered orange regardless of
the user's theme choice.
Fix:
1. Remove --primary, --primary-light, --primary-bg, --primary-rgb
from page{} in app.wxss, forcing WXSS to resolve var() at
runtime from inline style on .container
2. Expand BASE_VARS in theme.js to include default orange theme
vars, so the initial render (before onLoad) still has valid
CSS custom properties — no flash of unstyled content
3. Export BASE_VARS from theme.js
4. Change all 4 pages + custom-tab-bar initial data.themeStyle
from '' to themeMod.BASE_VARS, eliminating the empty-string
gap between first render and onLoad
101 lines
2.6 KiB
JavaScript
101 lines
2.6 KiB
JavaScript
const storage = require('../../utils/storage')
|
|
const planMod = require('../../utils/plan')
|
|
const util = require('../../utils/util')
|
|
const themeMod = require('../../utils/theme')
|
|
|
|
Page({
|
|
data: {
|
|
theme: { primary: '#FF6B35', primaryLight: '#FF8C5A', primaryBg: '#FFF3ED', primaryRgb: '255,107,53' },
|
|
themeStyle: themeMod.BASE_VARS,
|
|
todayTarget: 0,
|
|
todayDone: false,
|
|
todayDuration: 0,
|
|
todayTargetText: '',
|
|
streakCount: 0,
|
|
planName: '',
|
|
planDay: 1,
|
|
planTotal: 7,
|
|
planProgress: 0,
|
|
showPicker: false,
|
|
presets: [30, 60, 90, 120, 180, 300],
|
|
customDuration: 60,
|
|
customInput: ''
|
|
},
|
|
|
|
onLoad() {
|
|
themeMod.applyThemeToPage(this)
|
|
this.refresh()
|
|
},
|
|
|
|
onShow() {
|
|
themeMod.applyThemeToPage(this)
|
|
try {
|
|
const tb = this.getTabBar()
|
|
if (tb) tb.setData({ selected: 0 })
|
|
} catch (e) {}
|
|
this.refresh()
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.refresh()
|
|
wx.stopPullDownRefresh()
|
|
},
|
|
|
|
refresh() {
|
|
const settings = storage.getSettings()
|
|
const streak = storage.getStreak()
|
|
const todayRecord = storage.getTodayRecord()
|
|
|
|
const allRecords = Object.values(storage.getRecords()).flat()
|
|
const plan = planMod.getPlan(settings.planId)
|
|
const planDay = planMod.getPlanDay(settings.planId, allRecords)
|
|
const target = planMod.getTodayTarget(settings.planId, Math.min(planDay, plan.totalDays))
|
|
|
|
this.setData({
|
|
todayTarget: target,
|
|
todayDone: todayRecord && todayRecord.duration >= target,
|
|
todayDuration: todayRecord ? todayRecord.duration : 0,
|
|
todayTargetText: util.formatTime(target),
|
|
streakCount: streak.count,
|
|
planName: plan.name,
|
|
planDay: Math.min(planDay, plan.totalDays),
|
|
planTotal: plan.totalDays,
|
|
planProgress: Math.round((Math.min(planDay, plan.totalDays) / plan.totalDays) * 100)
|
|
})
|
|
},
|
|
|
|
onStartTrain() {
|
|
wx.navigateTo({ url: '/pages/timer/timer' })
|
|
},
|
|
|
|
onFreeTrain() {
|
|
this.setData({ showPicker: true, customInput: '', customDuration: 60 })
|
|
},
|
|
|
|
onClosePicker() {
|
|
this.setData({ showPicker: false })
|
|
},
|
|
|
|
onSelectPreset(e) {
|
|
const val = e.currentTarget.dataset.value
|
|
this.setData({ customDuration: val, customInput: '' })
|
|
},
|
|
|
|
onCustomInput(e) {
|
|
const val = parseInt(e.detail.value) || 0
|
|
this.setData({ customInput: e.detail.value, customDuration: val })
|
|
},
|
|
|
|
onConfirmFree() {
|
|
const dur = this.data.customDuration
|
|
if (!dur || dur <= 0) {
|
|
wx.showToast({ title: '请输入有效时长', icon: 'none' })
|
|
return
|
|
}
|
|
this.setData({ showPicker: false })
|
|
wx.navigateTo({ url: `/pages/timer/timer?free=${dur}` })
|
|
},
|
|
|
|
noop() {}
|
|
})
|