This commit is contained in:
ChuXun
2025-10-19 20:28:31 +08:00
parent c81f8a8b03
commit eaab9a762a
100 changed files with 23416 additions and 0 deletions

186
app.js Normal file
View File

@@ -0,0 +1,186 @@
// app.js
App({
onLaunch() {
console.log('========================================');
console.log('🚀 小程序启动');
console.log('========================================');
// 初始化日志
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 静默登录获取code
wx.login({
success: res => {
console.log('登录成功', res.code)
},
fail: err => {
console.error('登录失败', err)
}
})
// 🔥 强制初始化示例数据(用于演示和答辩)
// 如果不需要示例数据,注释掉下面这行
this.initDefaultData()
console.log('========================================');
},
onError(error) {
console.error('小程序错误:', error)
wx.showToast({
title: '程序异常,请重试',
icon: 'none'
})
},
// 初始化默认数据
initDefaultData() {
// 检查是否已初始化过示例数据
const dataInitialized = wx.getStorageSync('demo_data_initialized');
if (!dataInitialized) {
console.log('[App] 初始化示例数据...');
this.initDemoData();
wx.setStorageSync('demo_data_initialized', true);
}
// 确保基础数据结构存在
if (!wx.getStorageSync('userInfo')) {
wx.setStorageSync('userInfo', {
nickname: '同学',
avatar: '/images/avatar-default.png',
isLogin: false
})
}
if (!wx.getStorageSync('favoriteCourses')) {
wx.setStorageSync('favoriteCourses', [])
}
if (!wx.getStorageSync('favoritePosts')) {
wx.setStorageSync('favoritePosts', [])
}
},
// 初始化演示数据
initDemoData() {
// 1. 初始化GPA课程数据4个学期共16门课
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('[App] 初始化16门GPA课程数据');
// 2. 初始化学习时长数据最近7天
const today = new Date();
const learningData = {
totalDays: 7,
totalHours: 24.5,
dailyRecords: []
};
const dailyActivity = {};
const moduleUsage = {
course: 8.5, // 课程中心使用8.5小时
forum: 6.2, // 论坛使用6.2小时
tools: 7.3, // 工具使用7.3小时
ai: 2.5 // AI助手使用2.5小时
};
// 生成最近7天的学习记录
for (let i = 6; i >= 0; i--) {
const date = new Date(today);
date.setDate(date.getDate() - i);
const dateStr = this.formatDate(date);
// 每天1-5小时随机学习时长
const duration = 1 + Math.random() * 4;
learningData.dailyRecords.push({
date: dateStr,
duration: parseFloat(duration.toFixed(1))
});
// 每日活跃度60-180分钟
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('[App] 初始化学习时长数据7天');
// 3. 初始化学习画像
const learningProfile = {
focus: 85, // 专注度
activity: 90, // 活跃度
duration: 75, // 学习时长
breadth: 88, // 知识广度
interaction: 72, // 互动性
persistence: 95 // 坚持度
};
wx.setStorageSync('learning_profile', learningProfile);
console.log('[App] 初始化学习画像数据');
// 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('[App] 初始化课表数据');
// 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('[App] 初始化倒计时数据');
console.log('[App] ✅ 所有示例数据初始化完成');
},
// 格式化日期为 YYYY-MM-DD
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}`;
},
globalData: {
version: '1.0.0'
}
})