Page({ data: { userInfo: {} as WechatMiniprogram.UserInfo, todayReadingTime: 0, totalBooks: 0, totalNotes: 0, totalBookmarks: 0, totalReadingDays: 0 }, onLoad() { this.loadUserInfo(); this.loadStatistics(); }, // 加载用户信息 loadUserInfo() { const userInfo = wx.getStorageSync('userInfo'); if (userInfo) { this.setData({ userInfo }); } }, // 加载统计数据 loadStatistics() { // 获取今日阅读时间 const today = new Date().toDateString(); const statistics = wx.getStorageSync('reading_statistics') || {}; const todayReadingTime = Math.floor((statistics[today] || 0) / 60); // 转换为分钟 // 获取笔记和书签数量 const notes = wx.getStorageSync('all_notes') || []; const bookmarks = wx.getStorageSync('all_bookmarks') || []; // 获取阅读过的书籍 const books = wx.getStorageSync('reading_history') || []; // 获取总阅读天数 const readingDays = Object.keys(statistics).length; this.setData({ todayReadingTime, totalBooks: books.length, totalNotes: notes.length, totalBookmarks: bookmarks.length, totalReadingDays: readingDays }); }, // 页面跳转 navigateToNotes() { wx.navigateTo({ url: '/pages/notes/notes' }); }, navigateToBookmarks() { wx.navigateTo({ url: '/pages/notes/notes?tab=bookmarks' }); }, navigateToHistory() { wx.navigateTo({ url: '/pages/history/history' }); }, navigateToSettings() { wx.navigateTo({ url: '/pages/settings/settings' }); } });