Files
wx_pbzc/custom-tab-bar/index.js
T
lc fb3bc6c045 fix: CSS custom properties not resolving from inline style
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
2026-06-04 17:03:09 +08:00

38 lines
753 B
JavaScript

const themeMod = require('../utils/theme')
Component({
data: {
selected: 0,
themeStyle: themeMod.BASE_VARS
},
lifetimes: {
attached() {
const theme = themeMod.getCurrentTheme()
this.setData({ themeStyle: themeMod.getThemeStyle(theme) })
}
},
pageLifetimes: {
show() {
const theme = themeMod.getCurrentTheme()
this.setData({ themeStyle: themeMod.getThemeStyle(theme) })
}
},
methods: {
switchTab(e) {
const index = e.currentTarget.dataset.index
const pages = [
'/pages/index/index',
'/pages/records/records',
'/pages/settings/settings'
]
if (index === this.data.selected) return
wx.switchTab({ url: pages[index] })
}
}
})