Files
王宏豪 cd04c1b5ef feat(database): 迁移用户关联字段并优化打卡系统
- 修改数据库配置将MYSQL_DB从mys_info_v3改为mys_info_test
- 新增auth_users表wechat_openid字段并建立唯一索引
- 为plan_checkins表添加计划性能索引(idx_plan_period_student)
- 将checkin_records_old表关联方式从student_id改为user_id
- 将plan_checkins表关联方式从student_id改为user_id并更新附件路径
- 移除routes/auth.py中的uuid导入使用安全token生成函数
- 重构routes/checkin.py打卡逻辑去除course_type字段并优化返回结构
- 添加打卡时间限制验证功能防止过期打卡操作
- 实现小组统计功能支持老师查看各组打卡情况
- 更新主页index.html界面适配新的打卡和计划功能
- 调整计划提交时间规则为周五至周四周期
- 添加月度和年度计划提交状态验证机制
2026-09-10 14:11:58 +08:00

163 lines
4.7 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const api = require('../../utils/api');
const auth = require('../../utils/auth');
const H5_HOME_URL = api.H5_BASE_URL + '/';
Page({
data: {
// 登录态标记
isLoggedIn: false,
// web-view 模式
webviewUrl: '',
webviewError: false,
errorMsg: '',
webviewKey: 0,
// 游客模式
greeting: '',
displayName: '',
encouragement: '',
modules: [],
introData: null
},
_webviewLoaded: false,
_lastToken: null,
_webviewKey: 0,
onShow() {
const currentToken = auth.getToken();
const isLoggedIn = !!currentToken;
if (isLoggedIn) {
// 已登录:每次进入首页都重新加载 H5 首页(确保从内部页面回到首页)
this._lastToken = currentToken;
this.setData({ isLoggedIn: true });
this.loadWebview();
this._webviewLoaded = true;
} else {
// 游客模式:token 未变化且已有数据时不重新加载
if (currentToken === this._lastToken && this.data.displayName) {
return;
}
this._lastToken = currentToken;
this.setData({ isLoggedIn: false });
this.loadGuestHome();
this._webviewLoaded = false;
}
},
// ---- 已登录:web-view 模式 ----
loadWebview() {
const token = auth.getToken();
const url = api.BASE_URL + '/api/v1/webview/redirect'
+ '?token=' + encodeURIComponent(token)
+ '&target=' + encodeURIComponent(H5_HOME_URL)
+ '&_t=' + Date.now();
// key 自增,强制 web-view 组件销毁重建,解决切 tab 回来白屏问题
// 时间戳参数确保 url 每次不同,强制重新加载并跳转到 H5 首页
this._webviewKey += 1;
this.setData({
webviewUrl: url,
webviewError: false,
errorMsg: '',
webviewKey: this._webviewKey
});
},
onWebviewError(e) {
this.setData({
webviewError: true,
errorMsg: (e && e.detail && e.detail.errMsg) || '加载失败,请检查网络后重试'
});
},
onRetry() {
this.setData({ webviewUrl: '', webviewError: false, errorMsg: '' });
setTimeout(() => {
this.loadWebview();
}, 50);
},
// ---- 未登录:游客原生首页 ----
loadGuestHome() {
this.setData({
greeting: '欢迎来到明缘云道场',
displayName: '游客',
encouragement: '登录后即可打卡、提交计划',
modules: this.getGuestModules(),
introData: this.getIntroData()
});
},
getGuestModules() {
return [
{ id: 'checkin', icon: '📋', label: '打卡介绍', desc: '每日打卡记录', visible: true, url: '', guest: true },
{ id: 'plan', icon: '📝', label: '计划介绍', desc: '周/月/年计划', visible: true, url: '', guest: true },
{ id: 'about', icon: 'ℹ️', label: '关于我们', desc: '了解明缘云道场', visible: true, url: '', guest: true }
];
},
getIntroData() {
return {
title: '产品介绍',
sections: [
{
icon: '📚',
heading: '学习成长工具',
text: '明缘云道场是一款专注于个人成长的效率工具,通过每周打卡与计划管理,帮助你养成良好的学习习惯,实现持续进步。好好学习,天天向上。'
},
{
icon: '✅',
heading: '周打卡',
text: '每周打卡,支持多种状态记录(正常、迟到、请假、早退、不参加讨论等)。查看小组打卡情况,与同学们互相监督、共同进步。'
},
{
icon: '📝',
heading: '计划管理',
text: '提供周计划、月计划、年计划三级管理,支持文字与图片上传。清晰追踪每个周期的目标完成情况,让成长有迹可循。'
},
{
icon: '👥',
heading: '小组共学',
text: '加入学习小组,查看组员的打卡与计划完成情况。在集体的氛围中保持学习动力,与志同道合的伙伴一起成长。'
}
]
};
},
goLogin() {
wx.switchTab({ url: '/pages/profile/profile' });
},
onModuleTap(e) {
const url = e.currentTarget.dataset.url;
wx.showModal({
title: '登录提示',
content: '登录后使用此功能,是否前往登录?',
confirmText: '去登录',
confirmColor: '#C67B30',
success: (res) => {
if (res.confirm) {
wx.switchTab({ url: '/pages/profile/profile' });
}
}
});
},
// ---- 分享 ----
onShareAppMessage() {
return {
title: '明缘云道场 · 学习成长,每日精进',
path: '/pages/home/home'
};
},
onShareTimeline() {
return {
title: '明缘云道场 · 打卡学习好工具',
query: 'from=timeline'
};
}
});