From 7da9e9a43c80e01d0f6a32a2fbfa6a23432c4206 Mon Sep 17 00:00:00 2001 From: hmo Date: Thu, 23 Apr 2026 21:02:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=9B=AE=E6=A0=87=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=BA=A7=E5=88=AB=E5=92=8C=E5=AD=90=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E6=95=B0=E9=87=8F=EF=BC=8C=E4=BF=AE=E5=A4=8DModal?= =?UTF-8?q?=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models.py | 2 ++ app/routes/goals.py | 8 +++++++- app/templates/goals.html | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/app/models.py b/app/models.py index cd33ae7..ae655f1 100644 --- a/app/models.py +++ b/app/models.py @@ -197,6 +197,7 @@ class Goal(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) content = db.Column(db.Text) + level = db.Column(db.String(20), default="入门") # 启蒙/入门/进阶/熟练/精通 created_at = db.Column(db.DateTime, default=datetime.now) updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now) @@ -205,6 +206,7 @@ class Goal(db.Model): "id": self.id, "name": self.name, "content": self.content, + "level": self.level, "created_at": self.created_at.isoformat() if self.created_at else None, "updated_at": self.updated_at.isoformat() if self.updated_at else None, } diff --git a/app/routes/goals.py b/app/routes/goals.py index 14afb6d..ffd93ca 100644 --- a/app/routes/goals.py +++ b/app/routes/goals.py @@ -22,7 +22,11 @@ def get_goals(): @login_required_json def create_goal(): data = request.get_json() - goal = Goal(name=data["name"], content=data.get("content", "")) + goal = Goal( + name=data["name"], + content=data.get("content", ""), + level=data.get("level", "入门") + ) db.session.add(goal) db.session.commit() return jsonify(goal.to_dict()), 201 @@ -42,6 +46,8 @@ def update_goal(goal_id): goal.name = data["name"] if "content" in data: goal.content = data["content"] + if "level" in data: + goal.level = data["level"] db.session.commit() return jsonify(goal.to_dict()) diff --git a/app/templates/goals.html b/app/templates/goals.html index f29bde1..4edc79f 100644 --- a/app/templates/goals.html +++ b/app/templates/goals.html @@ -36,6 +36,16 @@ +
+ + +
@@ -91,12 +101,24 @@ async function loadGoals() { const res = await fetch(API_BASE); const goals = await res.json(); const grid = document.getElementById('goals-grid'); - grid.innerHTML = goals.map(g => ` + + // 获取每个目标的子目标数量 + const goalsWithChildren = await Promise.all(goals.map(async g => { + const childrenRes = await fetch(`${API_BASE}/${g.id}/children`); + const children = await childrenRes.json(); + return {...g, childCount: children.length}; + })); + + grid.innerHTML = goalsWithChildren.map(g => `
${escapeHtml(g.name)}
-

${escapeHtml(g.content || '').substring(0, 100)}...

+
+ ${g.level} + ${g.childCount > 0 ? `${g.childCount}个子目标` : ''} +
+

${escapeHtml(g.content || '').substring(0, 80)}${g.content && g.content.length > 80 ? '...' : ''}