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:
+25
-27
@@ -1,5 +1,5 @@
|
||||
var storage = require('../../utils/storage')
|
||||
var themeMod = require('../../utils/theme')
|
||||
const storage = require('../../utils/storage')
|
||||
const themeMod = require('../../utils/theme')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -19,9 +19,9 @@ Page({
|
||||
vibrate: true
|
||||
},
|
||||
|
||||
onLoad: function () {
|
||||
var s = storage.getSettings()
|
||||
var theme = themeMod.getCurrentTheme()
|
||||
onLoad() {
|
||||
const s = storage.getSettings()
|
||||
const theme = themeMod.getCurrentTheme()
|
||||
themeMod.applyThemeToPage(this)
|
||||
this.setData({
|
||||
currentPlanId: s.planId,
|
||||
@@ -33,70 +33,68 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
onShow() {
|
||||
try {
|
||||
var tb = this.getTabBar()
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ selected: 2 })
|
||||
} catch (e) {}
|
||||
themeMod.applyThemeToPage(this)
|
||||
},
|
||||
|
||||
onSelectTheme: function (e) {
|
||||
var id = e.currentTarget.dataset.id
|
||||
var theme = themeMod.setTheme(id)
|
||||
onSelectTheme(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
const theme = themeMod.setTheme(id)
|
||||
this.setData({ currentThemeId: id })
|
||||
|
||||
try {
|
||||
var tb = this.getTabBar()
|
||||
if (tb) {
|
||||
tb.setData({ themeStyle: themeMod.getThemeStyle(theme) })
|
||||
}
|
||||
const tb = this.getTabBar()
|
||||
if (tb) tb.setData({ themeStyle: themeMod.getThemeStyle(theme) })
|
||||
} catch (e) {}
|
||||
|
||||
themeMod.applyThemeToPage(this)
|
||||
},
|
||||
|
||||
onSelectPlan: function (e) {
|
||||
var planId = e.currentTarget.dataset.id
|
||||
var s = storage.getSettings()
|
||||
onSelectPlan(e) {
|
||||
const planId = e.currentTarget.dataset.id
|
||||
const s = storage.getSettings()
|
||||
s.planId = planId
|
||||
storage.saveSettings(s)
|
||||
this.setData({ currentPlanId: planId })
|
||||
wx.showToast({ title: '计划已切换', icon: 'success', duration: 1200 })
|
||||
},
|
||||
|
||||
onToggleReminder: function (e) {
|
||||
var s = storage.getSettings()
|
||||
onToggleReminder(e) {
|
||||
const s = storage.getSettings()
|
||||
s.dailyReminder = e.detail.value
|
||||
storage.saveSettings(s)
|
||||
this.setData({ dailyReminder: e.detail.value })
|
||||
},
|
||||
|
||||
onReminderTimeChange: function (e) {
|
||||
var s = storage.getSettings()
|
||||
onReminderTimeChange(e) {
|
||||
const s = storage.getSettings()
|
||||
s.reminderTime = e.detail.value
|
||||
storage.saveSettings(s)
|
||||
this.setData({ reminderTime: e.detail.value })
|
||||
},
|
||||
|
||||
onToggleVoice: function (e) {
|
||||
var s = storage.getSettings()
|
||||
onToggleVoice(e) {
|
||||
const s = storage.getSettings()
|
||||
s.voiceGuide = e.detail.value
|
||||
storage.saveSettings(s)
|
||||
this.setData({ voiceGuide: e.detail.value })
|
||||
},
|
||||
|
||||
onToggleVibrate: function (e) {
|
||||
var s = storage.getSettings()
|
||||
onToggleVibrate(e) {
|
||||
const s = storage.getSettings()
|
||||
s.vibrate = e.detail.value
|
||||
storage.saveSettings(s)
|
||||
this.setData({ vibrate: e.detail.value })
|
||||
},
|
||||
|
||||
onCopyWechat: function () {
|
||||
onCopyWechat() {
|
||||
wx.setClipboardData({
|
||||
data: '刘承',
|
||||
success: function () {
|
||||
success: () => {
|
||||
wx.showToast({ title: '已复制', icon: 'success', duration: 1500 })
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user