1eff3d60c4
- 计划编辑弹窗移出 .container 避免 fixed 降级 + 修复滚动 - dock bottom 40rpx→8rpx 紧贴底部, sheet padding 同步调整 - 计划编辑器取消/恢复默认按钮可见性修复(bg 匹配容器) - ui-btn--danger 按钮可见性修复 - 清除确认弹窗跟随暗黑模式切换 - icons.js build() 中 Fill 路径覆盖 outlined 路径修复 - plan.js getPlanDay 忽略 customPlans 修复 - darkMode.js 冗余三元简化 - util.js fileToDataURI fallback 可读性提升 - theme.js: BASE_VARS 与 getThemeStyle 统一来源, 去 50ms navbar 延迟 - app.wxss: 移除 page transition 和 background-color 减少闪白 - 云函数 wx-server-sdk 版本统一 ~2.6.3, tts cloud.init 一致化 - 闪白问题: wx.setBackgroundColor 三层防护(onLaunch/applyThemeToPage/switchTab) Co-Authored-By: Claude <noreply@anthropic.com>
111 lines
5.8 KiB
JavaScript
111 lines
5.8 KiB
JavaScript
const themeMod = require('../utils/theme')
|
|
const darkMod = require('../utils/darkMode')
|
|
|
|
// Resolve the active theme synchronously at module load so the first paint
|
|
// already has the correct CSS variables — avoids a flash of the default theme.
|
|
const _initialTheme = themeMod.getCurrentTheme()
|
|
const _initialThemeStyle = themeMod.getThemeStyle(_initialTheme, darkMod.getInitialDarkMode())
|
|
|
|
// Inactive icon color follows the dark mode: matches --text-secondary in dark
|
|
// mode and a softer gray in light mode. Kept in sync with utils/theme.js so
|
|
// icons don't sit awkwardly on the dock background in either theme.
|
|
const LIGHT_INACTIVE = '#999999'
|
|
const DARK_INACTIVE = '#98989F'
|
|
|
|
const _getInactiveColor = () =>
|
|
darkMod.getInitialDarkMode() ? DARK_INACTIVE : LIGHT_INACTIVE
|
|
|
|
const _initialInactiveColor = _getInactiveColor()
|
|
|
|
const _svg = (path, fill) =>
|
|
'data:image/svg+xml,' + encodeURIComponent(
|
|
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="' + fill + '">' +
|
|
path + '</svg>'
|
|
)
|
|
|
|
// 24x24 Material-style paths
|
|
const PATH_HOME = '<path d="M12 3l9 8h-3v9h-5v-6h-2v6H6v-9H3l9-8z"/>'
|
|
const PATH_HOME_LINE = '<path d="M12 5.2L5.5 11H7v8h2v-6h6v6h2v-8h1.5L12 5.2M12 3l9 8h-3v9h-5v-6h-2v6H6v-9H3l9-8z" fill-rule="evenodd"/>'
|
|
const PATH_CALENDAR = '<path d="M19 4h-2V2h-2v2H9V2H7v2H5C3.9 4 3 4.9 3 6v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V10h14v10zm0-12H5V6h14v2z"/><path d="M7 12h5v5H7z"/>'
|
|
const PATH_CALENDAR_LINE = '<path d="M19 4h-2V2h-2v2H9V2H7v2H5C3.9 4 3 4.9 3 6v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V10h14v10zm0-12H5V6h14v2z" fill-rule="evenodd"/>'
|
|
const PATH_RANK = '<path d="M7.5 21H2V9h5.5v12zm7.25-14h-5.5v14h5.5V7zM22 11h-5.5v10H22V11z"/>'
|
|
const PATH_RANK_LINE = '<path d="M7.5 21H2V9h5.5v12zm7.25-14h-5.5v14h5.5V7zM22 11h-5.5v10H22V11z" fill-rule="evenodd"/>'
|
|
const PATH_SETTINGS = '<path d="M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 00.12-.61l-1.92-3.32a.49.49 0 00-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 00-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96a.49.49 0 00-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.07.62-.07.94s.02.64.07.94l-2.03 1.58a.49.49 0 00-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/>'
|
|
const PATH_SETTINGS_LINE = '<path d="M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 00-.12-.61l-1.92-3.32a.49.49 0 00-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 00-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96a.49.49 0 00-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.07.62-.07.94s.02.64.07.94l-2.03 1.58a.49.49 0 00-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z" fill-rule="evenodd"/>'
|
|
|
|
const _buildIcons = (activeHex, inactiveHex) => {
|
|
const a = activeHex
|
|
return {
|
|
home: _svg(PATH_HOME_LINE, inactiveHex),
|
|
homeFill: _svg(PATH_HOME, a),
|
|
calendar: _svg(PATH_CALENDAR_LINE, inactiveHex),
|
|
calendarFill: _svg(PATH_CALENDAR, a),
|
|
rank: _svg(PATH_RANK_LINE, inactiveHex),
|
|
rankFill: _svg(PATH_RANK, a),
|
|
settings: _svg(PATH_SETTINGS_LINE, inactiveHex),
|
|
settingsFill: _svg(PATH_SETTINGS, a)
|
|
}
|
|
}
|
|
|
|
Component({
|
|
data: {
|
|
selected: 0,
|
|
theme: _initialTheme,
|
|
themeStyle: _initialThemeStyle,
|
|
svgIcons: _buildIcons(_initialTheme.primary, _initialInactiveColor)
|
|
},
|
|
|
|
lifetimes: {
|
|
attached() {
|
|
themeMod.applyThemeToPage(this)
|
|
// Rebuild icons in case the user changed theme/dark mode since module load
|
|
const theme = themeMod.getCurrentTheme()
|
|
this.setData({ svgIcons: _buildIcons(theme.primary, _getInactiveColor()) })
|
|
// The custom tabBar isn't in getCurrentPages(), so app.js's
|
|
// watchDarkMode (which notifies pages) never reaches it. Listen for
|
|
// system theme changes ourselves so the dock flips dark/light live,
|
|
// not just on the next tab switch.
|
|
if (!this._themeChangeBound && typeof wx.onThemeChange === 'function') {
|
|
this._onThemeChange = () => {
|
|
themeMod.applyThemeToPage(this)
|
|
this.setData({ svgIcons: _buildIcons(themeMod.getCurrentTheme().primary, _getInactiveColor()) })
|
|
}
|
|
try {
|
|
wx.onThemeChange(this._onThemeChange)
|
|
this._themeChangeBound = true
|
|
} catch (e) {}
|
|
}
|
|
}
|
|
},
|
|
|
|
pageLifetimes: {
|
|
show() {
|
|
themeMod.applyThemeToPage(this)
|
|
const theme = themeMod.getCurrentTheme()
|
|
this.setData({ svgIcons: _buildIcons(theme.primary, _getInactiveColor()) })
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
switchTab(e) {
|
|
const index = e.currentTarget.dataset.index
|
|
const pages = [
|
|
'/pages/index/index',
|
|
'/pages/records/records',
|
|
'/pages/leaderboard/leaderboard',
|
|
'/pages/settings/settings'
|
|
]
|
|
if (index === this.data.selected) return
|
|
// 切 tab 前设窗口背景色,避免真机过渡动画露出白色底色
|
|
try { themeMod.applyWindowBg() } catch (e) {}
|
|
wx.switchTab({ url: pages[index] })
|
|
},
|
|
// Called by settings.onSelectDarkMode - the dock isn't in
|
|
// getCurrentPages() so the page-loop there misses it.
|
|
updateTheme() {
|
|
themeMod.applyThemeToPage(this)
|
|
this.setData({ svgIcons: _buildIcons(themeMod.getCurrentTheme().primary, _getInactiveColor()) })
|
|
}
|
|
}
|
|
})
|