187 lines
7.9 KiB
JavaScript
187 lines
7.9 KiB
JavaScript
/**
|
||
* 🔥 直接初始化数据到微信小程序本地存储
|
||
*
|
||
* 使用方法:
|
||
* 1. 打开微信开发者工具
|
||
* 2. 打开控制台(Console)
|
||
* 3. 复制粘贴这整个文件的代码
|
||
* 4. 按回车执行
|
||
*
|
||
* ⚠️ 这会直接写入数据到 wx.storage(持久化存储)
|
||
*/
|
||
|
||
console.log('');
|
||
console.log('╔════════════════════════════════════════════════╗');
|
||
console.log('║ 🔥 开始初始化持久化存储数据 ║');
|
||
console.log('╚════════════════════════════════════════════════╝');
|
||
console.log('');
|
||
|
||
// ========================================
|
||
// 1. 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('✅ 已写入 gpaCourses: 16门课程');
|
||
|
||
// ========================================
|
||
// 2. 学习时长数据(最近30天)
|
||
// ========================================
|
||
const today = new Date();
|
||
const learningData = {
|
||
totalDays: 30,
|
||
totalHours: 85.5,
|
||
dailyRecords: []
|
||
};
|
||
|
||
const dailyActivity = {};
|
||
const moduleUsage = {
|
||
course: 28.5, // 课程中心
|
||
forum: 22.3, // 论坛
|
||
tools: 25.7, // 工具
|
||
ai: 9.0 // AI助手
|
||
};
|
||
|
||
// 生成最近30天的数据
|
||
for (let i = 29; i >= 0; i--) {
|
||
const date = new Date(today);
|
||
date.setDate(date.getDate() - i);
|
||
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||
const day = String(date.getDate()).padStart(2, '0');
|
||
const dateStr = `${year}-${month}-${day}`;
|
||
|
||
// 每天2-4小时学习时长
|
||
const duration = 2 + Math.random() * 2;
|
||
learningData.dailyRecords.push({
|
||
date: dateStr,
|
||
duration: parseFloat(duration.toFixed(1))
|
||
});
|
||
|
||
// 每日活跃度(90-180分钟)
|
||
const activity = Math.floor(90 + Math.random() * 90);
|
||
dailyActivity[dateStr] = activity;
|
||
}
|
||
|
||
wx.setStorageSync('learning_data', learningData);
|
||
console.log('✅ 已写入 learning_data: 30天学习记录');
|
||
|
||
wx.setStorageSync('daily_activity', dailyActivity);
|
||
console.log('✅ 已写入 daily_activity: 30天活跃度数据');
|
||
console.log(' 示例数据:', Object.keys(dailyActivity).slice(0, 3).map(k => `${k}: ${dailyActivity[k]}分钟`));
|
||
|
||
wx.setStorageSync('module_usage', moduleUsage);
|
||
console.log('✅ 已写入 module_usage: 4个模块使用时长');
|
||
|
||
// ========================================
|
||
// 3. 学习画像(6个维度)
|
||
// ========================================
|
||
const learningProfile = {
|
||
focus: 85, // 专注度
|
||
activity: 90, // 活跃度
|
||
duration: 75, // 学习时长
|
||
breadth: 88, // 知识广度
|
||
interaction: 72, // 互动性
|
||
persistence: 95 // 坚持度
|
||
};
|
||
|
||
wx.setStorageSync('learning_profile', learningProfile);
|
||
console.log('✅ 已写入 learning_profile: 6维度学习画像');
|
||
|
||
// ========================================
|
||
// 4. 课表数据
|
||
// ========================================
|
||
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('✅ 已写入 schedule: 8门课程安排');
|
||
|
||
// ========================================
|
||
// 5. 倒计时数据
|
||
// ========================================
|
||
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('✅ 已写入 countdowns: 4个重要事件');
|
||
|
||
// ========================================
|
||
// 6. 清除GPA历史记录(让系统重新生成)
|
||
// ========================================
|
||
wx.removeStorageSync('gpa_history');
|
||
console.log('✅ 已清除 gpa_history(将从课程数据自动生成)');
|
||
|
||
// ========================================
|
||
// 7. 标记数据已初始化
|
||
// ========================================
|
||
wx.setStorageSync('demo_data_initialized', true);
|
||
wx.setStorageSync('data_version', '2.0');
|
||
console.log('✅ 已设置数据版本标记');
|
||
|
||
console.log('');
|
||
console.log('╔════════════════════════════════════════════════╗');
|
||
console.log('║ 🎉 所有数据已写入持久化存储! ║');
|
||
console.log('╚════════════════════════════════════════════════╝');
|
||
console.log('');
|
||
console.log('📌 数据存储位置: wx.storage (本地持久化)');
|
||
console.log('📌 数据将在卸载小程序后清除');
|
||
console.log('');
|
||
console.log('🔍 验证数据:');
|
||
console.log(' wx.getStorageSync("gpaCourses") // 查看GPA课程');
|
||
console.log(' wx.getStorageSync("daily_activity") // 查看每日活跃度');
|
||
console.log(' wx.getStorageSync("learning_data") // 查看学习数据');
|
||
console.log('');
|
||
console.log('📊 现在进入"学习数据"页面即可看到完整图表!');
|
||
console.log('');
|
||
|
||
// ========================================
|
||
// 8. 显示数据摘要
|
||
// ========================================
|
||
console.group('📦 数据摘要');
|
||
console.log('GPA课程数:', gpaCourses.length);
|
||
console.log('学习记录天数:', learningData.dailyRecords.length);
|
||
console.log('活跃度记录天数:', Object.keys(dailyActivity).length);
|
||
console.log('课表课程数:', Object.keys(scheduleData[1]).length);
|
||
console.log('倒计时事件数:', countdowns.length);
|
||
console.groupEnd();
|