feat(init): 添加完整的认证和业务路由模块
- 实现微信登录、手机号绑定、token验证和登出功能 - 添加打卡系统,支持正常、迟到、请假等状态记录 - 集成课程投票功能,支持多课程选择和评分评论 - 开发反馈系统,支持图文反馈提交和管理员处理 - 构建首页页面模块,动态展示学习资源和个人信息 - 设计计划管理系统,支持周/月/年计划制定和跟踪 - 实现小组计划统计和历史记录查询功能 - 完善用户认证会话管理和数据库交互逻辑
This commit is contained in:
87
routes/pages.py
Normal file
87
routes/pages.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from .. import config
|
||||
from ..user import user_payload
|
||||
from .auth import get_current_user
|
||||
|
||||
router = APIRouter(prefix="/api/v1/pages", tags=["pages"])
|
||||
|
||||
|
||||
def _greeting():
|
||||
hour = datetime.now().hour
|
||||
if hour < 6:
|
||||
return "夜深了,还在用功"
|
||||
if hour < 9:
|
||||
return "早上好,今天又起了一个大早"
|
||||
if hour < 12:
|
||||
return "上午好"
|
||||
if hour < 14:
|
||||
return "中午好,记得吃饭"
|
||||
if hour < 18:
|
||||
return "下午好"
|
||||
if hour < 21:
|
||||
return "晚上好"
|
||||
return "夜深了,早点休息"
|
||||
|
||||
|
||||
def _xinhuo_member(sid):
|
||||
return sid.startswith("N") or sid.startswith("0")
|
||||
|
||||
|
||||
def _norm_group(group):
|
||||
g = (group or "").replace("组", "").strip()
|
||||
if len(g) == 1:
|
||||
g = "0" + g
|
||||
return g
|
||||
|
||||
|
||||
@router.get("/home")
|
||||
def home(user=Depends(get_current_user)):
|
||||
base = config.H5_BASE_URL
|
||||
role = user.get("role", "student")
|
||||
is_teacher = role == "teacher"
|
||||
sid = user.get("student_id", "")
|
||||
payload = user_payload(user)
|
||||
group = payload["group"]
|
||||
periods = {cg.get("period") for cg in payload["class_groups"]}
|
||||
|
||||
def period_url(period, group_name):
|
||||
if is_teacher:
|
||||
return base + "/" + period + "/"
|
||||
g = _norm_group(group_name)
|
||||
if g.isdigit():
|
||||
return base + "/" + period + "/" + g + "-组.html"
|
||||
return base + "/" + period + "/自由小组.html"
|
||||
|
||||
modules = [
|
||||
{"id": "xinhuo", "type": "period", "icon": "🔥", "label": "薪火相传", "desc": "年课 / 终身学习小组",
|
||||
"url": base + "/xinhuo/" if is_teacher else base + "/xinhuo/index.html",
|
||||
"visible": is_teacher or _xinhuo_member(sid)},
|
||||
{"id": "19qi", "type": "period", "icon": "📖", "label": "19期研修", "desc": "小班课 · 第19期",
|
||||
"url": period_url("19qi", group), "visible": is_teacher or ("19期" in periods)},
|
||||
{"id": "18qi", "type": "period", "icon": "📖", "label": "18期研修", "desc": "小班课 · 第18期",
|
||||
"url": period_url("18qi", group), "visible": is_teacher or ("18期" in periods)},
|
||||
{"id": "20qi", "type": "period", "icon": "📖", "label": "20期小班课", "desc": "小班课 · 第20期",
|
||||
"url": period_url("20qi", group), "visible": is_teacher or ("20期" in periods)},
|
||||
{"id": "teacher", "type": "teacher", "icon": "🎓", "label": "老师大班授权", "desc": "年课 / 长期学员入口",
|
||||
"url": base + "/teacher/" if (is_teacher or _xinhuo_member(sid)) else base + "/xinhuo/upgrade-info.html",
|
||||
"visible": True},
|
||||
{"id": "student360", "type": "profile", "icon": "🧬", "label": "学员360", "desc": "薪火相传 · 个人成长档案",
|
||||
"url": base + "/xinhuo360/index.html" if is_teacher else base + "/student360/pages/" + sid + "-" + payload["name"] + ".html",
|
||||
"visible": True},
|
||||
{"id": "course-matrix", "type": "course", "icon": "🧠", "label": "AI量化课程矩阵", "desc": "12门课程 · 选出你最想学的3门",
|
||||
"url": base + "/course-matrix.html", "visible": True},
|
||||
{"id": "demo", "type": "demo", "icon": "🧭", "label": "功能演示", "desc": "先看看讨论和量化报告的样子",
|
||||
"url": base + "/xinhuo/virtual-group.html", "visible": True},
|
||||
{"id": "yijing", "type": "study", "icon": "☯", "label": "易经学习", "desc": "周易六十四卦 · 经文详解",
|
||||
"url": base + "/yijing/", "visible": True},
|
||||
]
|
||||
|
||||
return {
|
||||
"greeting": _greeting(),
|
||||
"display_name": payload["display_name"],
|
||||
"encouragement": "日拱一卒,功不唐捐。",
|
||||
"modules": [m for m in modules if m["visible"]],
|
||||
}
|
||||
Reference in New Issue
Block a user