App({ globalData: { token: '', user: null, apiUrl: 'http://localhost:8080', themeMode: 'light', }, onLaunch() { const token = wx.getStorageSync('token') if (token) { this.globalData.token = token try { const user = wx.getStorageSync('user') if (user) this.globalData.user = user } catch(e) {} } this.initTheme() }, initTheme() { const stored = wx.getStorageSync('inchstep-theme') if (stored === 'light' || stored === 'dark') { this.globalData.themeMode = stored } else { try { const sysInfo = wx.getSystemInfoSync() this.globalData.themeMode = sysInfo.theme === 'dark' ? 'dark' : 'light' } catch(e) {} } this.applyTheme(this.globalData.themeMode) }, applyTheme(mode) { this.globalData.themeMode = mode wx.setStorageSync('inchstep-theme', mode) try { wx.setNavigationBarColor({ frontColor: mode === 'dark' ? '#ffffff' : '#000000', backgroundColor: mode === 'dark' ? '#1C1C1E' : '#F5F5F7', }) wx.setTabBarStyle({ backgroundColor: mode === 'dark' ? '#1C1C1E' : '#F5F5F7', borderStyle: mode === 'dark' ? 'black' : 'white', }) } catch(e) {} this.notifyPages(mode) }, toggleTheme() { const newMode = this.globalData.themeMode === 'light' ? 'dark' : 'light' this.applyTheme(newMode) }, notifyPages(mode) { const pages = getCurrentPages() pages.forEach(page => { if (page.setData && typeof page.setThemeData === 'function') { page.setThemeData(mode) } else if (page.setData) { page.setData({ themeMode: mode }) } }) }, })