|
|
// profile.ts
|
|
|
|
|
|
// 用户信息接口
|
|
|
interface UserInfo {
|
|
|
avatarUrl?: string;
|
|
|
nickName?: string;
|
|
|
openid?: string;
|
|
|
}
|
|
|
|
|
|
Page({
|
|
|
data: {
|
|
|
userInfo: {} as UserInfo,
|
|
|
userOpenid: '',
|
|
|
appVersion: '1.0.0',
|
|
|
semesterConfig: {} as any,
|
|
|
currentWeek: 1
|
|
|
},
|
|
|
|
|
|
onLoad() {
|
|
|
this.loadUserInfo();
|
|
|
this.loadUserOpenid();
|
|
|
this.loadSemesterInfo();
|
|
|
},
|
|
|
|
|
|
onShow() {
|
|
|
// 页面显示时重新加载学期信息
|
|
|
this.loadSemesterInfo();
|
|
|
},
|
|
|
|
|
|
// 加载用户信息
|
|
|
loadUserInfo() {
|
|
|
// 从本地存储获取用户信息
|
|
|
const userInfo = wx.getStorageSync('userInfo') || {};
|
|
|
this.setData({ userInfo });
|
|
|
|
|
|
// 如果没有用户信息,尝试获取
|
|
|
if (!userInfo.nickName) {
|
|
|
this.getUserProfile();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 加载用户OpenID
|
|
|
loadUserOpenid() {
|
|
|
const api = require('../../utils/api').default;
|
|
|
const userOpenid = api.getUserOpenid();
|
|
|
this.setData({ userOpenid });
|
|
|
},
|
|
|
|
|
|
// 加载学期信息
|
|
|
loadSemesterInfo() {
|
|
|
const util = require('../../utils/util');
|
|
|
const semesterConfig = util.getSemesterConfig();
|
|
|
const currentWeek = util.getCurrentWeek();
|
|
|
|
|
|
this.setData({
|
|
|
semesterConfig,
|
|
|
currentWeek
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 获取用户信息
|
|
|
getUserProfile() {
|
|
|
wx.getUserProfile({
|
|
|
desc: '用于完善用户资料',
|
|
|
success: (res) => {
|
|
|
const userInfo = res.userInfo;
|
|
|
this.setData({ userInfo });
|
|
|
// 保存到本地存储
|
|
|
wx.setStorageSync('userInfo', userInfo);
|
|
|
},
|
|
|
fail: (error) => {
|
|
|
console.log('获取用户信息失败:', error);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 添加课程
|
|
|
onAddCourse() {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/course-add/course-add?mode=add'
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// OCR导入
|
|
|
onOcrImport() {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/ocr-import/ocr-import'
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 导出课表
|
|
|
onExportSchedule() {
|
|
|
wx.showToast({
|
|
|
title: '功能开发中',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
// TODO: 实现课表导出功能
|
|
|
},
|
|
|
|
|
|
// 清空所有课程
|
|
|
onClearAllCourses() {
|
|
|
wx.showModal({
|
|
|
title: '确认清空',
|
|
|
content: '确定要删除所有课程吗?此操作不可恢复。',
|
|
|
confirmText: '确定清空',
|
|
|
confirmColor: '#ff4757',
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
this.clearAllCourses();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 执行清空操作
|
|
|
async clearAllCourses() {
|
|
|
wx.showLoading({
|
|
|
title: '清空中...'
|
|
|
});
|
|
|
|
|
|
try {
|
|
|
const api = require('../../utils/api').default;
|
|
|
const userOpenid = api.getUserOpenid();
|
|
|
|
|
|
const res = await api.course.clearAllCourses(userOpenid);
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
wx.showToast({
|
|
|
title: '清空成功',
|
|
|
icon: 'success'
|
|
|
});
|
|
|
} else {
|
|
|
api.handleError(res.message, '清空失败');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
const api = require('../../utils/api').default;
|
|
|
api.handleError(error, '网络错误');
|
|
|
} finally {
|
|
|
wx.hideLoading();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 学期设置
|
|
|
onSemesterSetting() {
|
|
|
const util = require('../../utils/util');
|
|
|
const currentConfig = util.getSemesterConfig();
|
|
|
|
|
|
wx.showActionSheet({
|
|
|
itemList: ['春季学期设置', '秋季学期设置', '自定义设置'],
|
|
|
success: (res) => {
|
|
|
if (res.tapIndex === 0) {
|
|
|
// 春季学期
|
|
|
this.setSemesterConfig('spring');
|
|
|
} else if (res.tapIndex === 1) {
|
|
|
// 秋季学期
|
|
|
this.setSemesterConfig('fall');
|
|
|
} else if (res.tapIndex === 2) {
|
|
|
// 自定义设置
|
|
|
this.showCustomSemesterSetting();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 设置学期配置
|
|
|
setSemesterConfig(type: 'spring' | 'fall') {
|
|
|
const util = require('../../utils/util');
|
|
|
const year = new Date().getFullYear();
|
|
|
|
|
|
let config;
|
|
|
if (type === 'spring') {
|
|
|
config = {
|
|
|
startDate: `${year}-02-26`,
|
|
|
name: `${year}年春季学期`,
|
|
|
totalWeeks: 18
|
|
|
};
|
|
|
} else {
|
|
|
config = {
|
|
|
startDate: `${year}-09-02`,
|
|
|
name: `${year}年秋季学期`,
|
|
|
totalWeeks: 18
|
|
|
};
|
|
|
}
|
|
|
|
|
|
util.setSemesterConfig(config);
|
|
|
this.loadSemesterInfo();
|
|
|
|
|
|
wx.showToast({
|
|
|
title: '设置成功',
|
|
|
icon: 'success'
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 显示自定义学期设置
|
|
|
showCustomSemesterSetting() {
|
|
|
const util = require('../../utils/util');
|
|
|
const currentConfig = util.getSemesterConfig();
|
|
|
|
|
|
wx.showModal({
|
|
|
title: '自定义学期设置',
|
|
|
content: `当前:${currentConfig.name}\n开始日期:${currentConfig.startDate}\n总周数:${currentConfig.totalWeeks}`,
|
|
|
showCancel: true,
|
|
|
confirmText: '修改',
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
// 这里可以跳转到详细设置页面,或者使用简单的输入框
|
|
|
wx.showToast({
|
|
|
title: '功能开发中',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 关于我们
|
|
|
onAbout() {
|
|
|
wx.showModal({
|
|
|
title: '关于课表助手',
|
|
|
content: `版本:${this.data.appVersion}\n\n这是一个基于OCR技术的智能课表管理小程序,支持拍照识别课表并自动导入课程信息。\n\n开发者:智棋工作室`,
|
|
|
showCancel: false,
|
|
|
confirmText: '知道了'
|
|
|
});
|
|
|
}
|
|
|
})
|