refactor: ES6+ modernization + 2 bugfixes

- var→const/let, function→arrow/class across all 13 JS files
- Timer: prototype→class with ES6 getters
- plan days: IIFE→Array.from declarative generation
- storage/plan: unified formatDate via util.js
- Bugfix: getPlanDay now filters by planId (plan switch accuracy)
- Bugfix: getTodayRecord searches all months (cross-month boundary)
- WXML/WXSS unchanged; public API unchanged
This commit is contained in:
2026-06-04 16:29:25 +08:00
parent ff2700c067
commit 8c7f633541
13 changed files with 404 additions and 494 deletions
+27 -29
View File
@@ -1,4 +1,4 @@
var THEMES = [
const THEMES = [
{
id: 'orange',
name: '活力橙',
@@ -41,25 +41,23 @@ var THEMES = [
}
]
var DEFAULT_THEME_ID = 'orange'
var THEME_KEY = 'app_theme'
var _lastNavColor = ''
var _navColorTimer = null
const DEFAULT_THEME_ID = 'orange'
const THEME_KEY = 'app_theme'
let _lastNavColor = ''
let _navColorTimer = null
function getThemeById(id) {
return THEMES.find(function (t) { return t.id === id }) || THEMES[0]
}
const getThemeById = (id) => THEMES.find(t => t.id === id) || THEMES[0]
function getCurrentTheme() {
var id = wx.getStorageSync(THEME_KEY) || DEFAULT_THEME_ID
const getCurrentTheme = () => {
const id = wx.getStorageSync(THEME_KEY) || DEFAULT_THEME_ID
return getThemeById(id)
}
function _setNavBarColor(primary) {
const _setNavBarColor = (primary) => {
if (_lastNavColor === primary) return
_lastNavColor = primary
if (_navColorTimer) clearTimeout(_navColorTimer)
_navColorTimer = setTimeout(function () {
_navColorTimer = setTimeout(() => {
try {
wx.setNavigationBarColor({
frontColor: '#ffffff',
@@ -69,35 +67,35 @@ function _setNavBarColor(primary) {
}, 50)
}
function setTheme(id) {
const setTheme = (id) => {
wx.setStorageSync(THEME_KEY, id)
var theme = getThemeById(id)
const theme = getThemeById(id)
_setNavBarColor(theme.primary)
var app = getApp()
const app = getApp()
if (app && app.globalData) app.globalData.theme = theme
return theme
}
function applyThemeToPage(self) {
var theme = getCurrentTheme()
const applyThemeToPage = (self) => {
const theme = getCurrentTheme()
self.setData({
theme: theme,
themeStyle: '--primary:' + theme.primary + ';--primary-light:' + theme.primaryLight + ';--primary-bg:' + theme.primaryBg + ';--primary-rgb:' + theme.primaryRgb + ';'
theme,
themeStyle: `--primary:${theme.primary};--primary-light:${theme.primaryLight};--primary-bg:${theme.primaryBg};--primary-rgb:${theme.primaryRgb};`
})
_setNavBarColor(theme.primary)
}
function getThemeStyle(theme) {
var t = theme || getCurrentTheme()
return '--primary:' + t.primary + ';--primary-light:' + t.primaryLight + ';--primary-bg:' + t.primaryBg + ';--primary-rgb:' + t.primaryRgb + ';'
const getThemeStyle = (theme) => {
const t = theme || getCurrentTheme()
return `--primary:${t.primary};--primary-light:${t.primaryLight};--primary-bg:${t.primaryBg};--primary-rgb:${t.primaryRgb};`
}
module.exports = {
THEMES: THEMES,
DEFAULT_THEME_ID: DEFAULT_THEME_ID,
getThemeById: getThemeById,
getCurrentTheme: getCurrentTheme,
setTheme: setTheme,
applyThemeToPage: applyThemeToPage,
getThemeStyle: getThemeStyle
THEMES,
DEFAULT_THEME_ID,
getThemeById,
getCurrentTheme,
setTheme,
applyThemeToPage,
getThemeStyle
}