/** * 数据初始化和管理工具 * 在微信开发者工具控制台中直接粘贴执行 */ // ======================================== // 1️⃣ 初始化完整的示例数据 // ======================================== function initAllDemoData() { console.group('🚀 开始初始化示例数据'); // GPA课程数据(16门课程,4个学期) const gpaCourses = [ // 2023-1学期 { id: 1, name: '高等数学A(上)', score: 92, credit: 5, semester: '2023-1' }, { id: 2, name: '大学英语(一)', score: 88, credit: 3, semester: '2023-1' }, { id: 3, name: '程序设计基础', score: 95, credit: 4, semester: '2023-1' }, { id: 4, name: '思想道德与法治', score: 85, credit: 3, semester: '2023-1' }, // 2023-2学期 { id: 5, name: '高等数学A(下)', score: 90, credit: 5, semester: '2023-2' }, { id: 6, name: '大学英语(二)', score: 87, credit: 3, semester: '2023-2' }, { id: 7, name: '数据结构', score: 93, credit: 4, semester: '2023-2' }, { id: 8, name: '线性代数', score: 89, credit: 3, semester: '2023-2' }, // 2024-1学期 { id: 9, name: '概率论与数理统计', score: 91, credit: 4, semester: '2024-1' }, { id: 10, name: '计算机组成原理', score: 88, credit: 4, semester: '2024-1' }, { id: 11, name: '操作系统', score: 94, credit: 4, semester: '2024-1' }, { id: 12, name: '大学物理', score: 86, credit: 3, semester: '2024-1' }, // 2024-2学期 { id: 13, name: '数据库系统', score: 95, credit: 4, semester: '2024-2' }, { id: 14, name: '计算机网络', score: 92, credit: 4, semester: '2024-2' }, { id: 15, name: '软件工程', score: 90, credit: 3, semester: '2024-2' }, { id: 16, name: '人工智能导论', score: 96, credit: 3, semester: '2024-2' } ]; wx.setStorageSync('gpaCourses', gpaCourses); console.log('✅ GPA课程数据已初始化(16门)'); // 学习时长数据(最近7天) const today = new Date(); const learningData = { totalDays: 7, totalHours: 24.5, dailyRecords: [] }; const dailyActivity = {}; const moduleUsage = { course: 8.5, forum: 6.2, tools: 7.3, ai: 2.5 }; for (let i = 6; i >= 0; i--) { const date = new Date(today); date.setDate(date.getDate() - i); const dateStr = formatDate(date); const duration = 1 + Math.random() * 4; learningData.dailyRecords.push({ date: dateStr, duration: parseFloat(duration.toFixed(1)) }); dailyActivity[dateStr] = Math.floor(60 + Math.random() * 120); } wx.setStorageSync('learning_data', learningData); wx.setStorageSync('daily_activity', dailyActivity); wx.setStorageSync('module_usage', moduleUsage); console.log('✅ 学习时长数据已初始化(7天)'); // 学习画像 const learningProfile = { focus: 85, activity: 90, duration: 75, breadth: 88, interaction: 72, persistence: 95 }; wx.setStorageSync('learning_profile', learningProfile); console.log('✅ 学习画像已初始化'); // 课表数据 const scheduleData = { 1: { '周一-1-2节': { name: '高等数学', location: '教学楼A101', teacher: '张教授', weeks: '1-16周' }, '周一-3-4节': { name: '大学英语', location: '教学楼B203', teacher: '李老师', weeks: '1-16周' }, '周二-1-2节': { name: '数据结构', location: '实验楼C301', teacher: '王教授', weeks: '1-16周' }, '周二-5-6节': { name: '计算机网络', location: '实验楼C302', teacher: '赵老师', weeks: '1-16周' }, '周三-3-4节': { name: '数据库系统', location: '教学楼A205', teacher: '刘教授', weeks: '1-16周' }, '周四-1-2节': { name: '操作系统', location: '实验楼C303', teacher: '陈老师', weeks: '1-16周' }, '周四-5-6节': { name: '软件工程', location: '教学楼B301', teacher: '杨教授', weeks: '1-16周' }, '周五-3-4节': { name: '人工智能导论', location: '教学楼A301', teacher: '周教授', weeks: '1-16周' } } }; wx.setStorageSync('schedule', scheduleData); console.log('✅ 课表数据已初始化(8门课)'); // 倒计时数据 const countdowns = [ { id: 1, name: '期末考试', date: '2025-01-15', color: '#FF6B6B' }, { id: 2, name: '英语四级', date: '2024-12-14', color: '#4ECDC4' }, { id: 3, name: '数学竞赛', date: '2024-11-20', color: '#95E1D3' }, { id: 4, name: '编程大赛', date: '2024-11-30', color: '#F38181' } ]; wx.setStorageSync('countdowns', countdowns); console.log('✅ 倒计时数据已初始化(4个事件)'); // 清除GPA历史记录,让系统重新生成 wx.removeStorageSync('gpa_history'); console.log('✅ 已清除GPA历史记录(将自动重新生成)'); console.log(''); console.log('🎉 所有示例数据初始化完成!'); console.log('📌 请进入"学习数据"页面查看效果'); console.groupEnd(); } // ======================================== // 2️⃣ 查看所有数据 // ======================================== function viewAllData() { console.group('📊 当前所有数据'); const gpaCourses = wx.getStorageSync('gpaCourses'); console.log('GPA课程数量:', gpaCourses?.length || 0); console.log('GPA课程:', gpaCourses); const gpaHistory = wx.getStorageSync('gpa_history'); console.log('GPA历史:', gpaHistory); const learningData = wx.getStorageSync('learning_data'); console.log('学习数据:', learningData); const dailyActivity = wx.getStorageSync('daily_activity'); console.log('每日活动:', dailyActivity); const moduleUsage = wx.getStorageSync('module_usage'); console.log('模块使用:', moduleUsage); const learningProfile = wx.getStorageSync('learning_profile'); console.log('学习画像:', learningProfile); const schedule = wx.getStorageSync('schedule'); console.log('课表:', schedule); const countdowns = wx.getStorageSync('countdowns'); console.log('倒计时:', countdowns); console.groupEnd(); } // ======================================== // 3️⃣ 清除所有数据 // ======================================== function clearAllData() { const confirm = window.confirm('⚠️ 确定要清除所有数据吗?此操作不可恢复!'); if (!confirm) { console.log('❌ 已取消清除操作'); return; } wx.clearStorage(); console.log('✅ 所有数据已清除'); console.log('💡 请重启小程序或刷新页面'); } // ======================================== // 4️⃣ 只清除GPA数据 // ======================================== function clearGPAData() { wx.removeStorageSync('gpaCourses'); wx.removeStorageSync('gpa_history'); console.log('✅ GPA数据已清除'); } // ======================================== // 5️⃣ 只清除学习时长数据 // ======================================== function clearLearningData() { wx.removeStorageSync('learning_data'); wx.removeStorageSync('daily_activity'); wx.removeStorageSync('module_usage'); wx.removeStorageSync('learning_profile'); console.log('✅ 学习时长数据已清除'); } // ======================================== // 6️⃣ 诊断数据完整性 // ======================================== function diagnoseData() { console.group('🔍 数据完整性诊断'); const checks = [ { key: 'gpaCourses', name: 'GPA课程数据', required: true }, { key: 'gpa_history', name: 'GPA历史记录', required: false }, { key: 'learning_data', name: '学习时长数据', required: true }, { key: 'daily_activity', name: '每日活动数据', required: true }, { key: 'module_usage', name: '模块使用数据', required: true }, { key: 'learning_profile', name: '学习画像数据', required: true }, { key: 'schedule', name: '课表数据', required: false }, { key: 'countdowns', name: '倒计时数据', required: false } ]; let allGood = true; checks.forEach(check => { const data = wx.getStorageSync(check.key); const exists = data && (Array.isArray(data) ? data.length > 0 : Object.keys(data).length > 0); if (exists) { console.log(`✅ ${check.name}: 正常`); } else if (check.required) { console.error(`❌ ${check.name}: 缺失(必需)`); allGood = false; } else { console.warn(`⚠️ ${check.name}: 缺失(可选)`); } }); console.log(''); if (allGood) { console.log('🎉 所有必需数据完整!'); } else { console.error('⚠️ 有必需数据缺失,建议运行 initAllDemoData()'); } console.groupEnd(); } // ======================================== // 辅助函数 // ======================================== function formatDate(date) { const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; } // ======================================== // 使用说明 // ======================================== console.log(''); console.log('╔════════════════════════════════════════╗'); console.log('║ 数据管理工具已加载 ║'); console.log('╚════════════════════════════════════════╝'); console.log(''); console.log('📌 可用命令:'); console.log(''); console.log('1️⃣ initAllDemoData() - 初始化所有示例数据'); console.log('2️⃣ viewAllData() - 查看所有数据'); console.log('3️⃣ clearAllData() - 清除所有数据'); console.log('4️⃣ clearGPAData() - 只清除GPA数据'); console.log('5️⃣ clearLearningData() - 只清除学习时长数据'); console.log('6️⃣ diagnoseData() - 诊断数据完整性'); console.log(''); console.log('💡 使用示例:'); console.log(' initAllDemoData(); // 初始化示例数据'); console.log(' diagnoseData(); // 检查数据状态'); console.log('');