From a60d9d1e54c5c2162e8a9e7a41743aa1a543edd5 Mon Sep 17 00:00:00 2001 From: AnthonyDuan Date: Sun, 7 Dec 2025 11:25:50 +0800 Subject: [PATCH] =?UTF-8?q?ui:=20=E5=AF=BC=E8=88=AA=E5=9C=86=E6=B6=A6?= =?UTF-8?q?=E4=B8=8E=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=EF=BC=9B=E8=AF=A6=E6=83=85=E9=A1=B5=E4=BD=9C=E8=80=85=E4=B8=8E?= =?UTF-8?q?=E5=85=B3=E6=B3=A8=EF=BC=9B=E4=B8=BB=E9=A1=B5=E7=B2=89=E4=B8=9D?= =?UTF-8?q?/=E5=85=B3=E6=B3=A8=E4=B8=8E=E5=8D=A1=E7=89=87=E7=BD=91?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/blueprints/users.py | 13 +++++++++-- app/static/theme.css | 4 ++++ app/templates/base.html | 39 +++++++++++++++++++------------- app/templates/posts/detail.html | 13 ++++++++++- app/templates/users/profile.html | 38 +++++++++++++++++++++++-------- 5 files changed, 78 insertions(+), 29 deletions(-) diff --git a/app/blueprints/users.py b/app/blueprints/users.py index 7ee3ace..a3008e1 100644 --- a/app/blueprints/users.py +++ b/app/blueprints/users.py @@ -1,14 +1,23 @@ from flask import Blueprint, render_template, request, redirect, url_for from flask_login import login_required, current_user from ..extensions import db -from ..models import User, Profile, Notification +from ..models import User, Profile, Notification, Follow bp = Blueprint("users", __name__, url_prefix="/users") @bp.route("/") def profile(user_id): user = User.query.get_or_404(user_id) - return render_template("users/profile.html", user=user) + followers_count = Follow.query.filter_by(followee_id=user.id).count() + following_count = Follow.query.filter_by(follower_id=user.id).count() + is_following = False + try: + from flask_login import current_user + if current_user.is_authenticated: + is_following = Follow.query.filter_by(follower_id=current_user.id, followee_id=user.id).first() is not None + except Exception: + pass + return render_template("users/profile.html", user=user, followers_count=followers_count, following_count=following_count, is_following=is_following) @bp.route("/me/edit", methods=["GET", "POST"]) @login_required diff --git a/app/static/theme.css b/app/static/theme.css index e84aff0..c8388a0 100644 --- a/app/static/theme.css +++ b/app/static/theme.css @@ -9,6 +9,10 @@ body { background: #f8fafc; } .container { max-width: 1100px; } .navbar { border-radius: var(--radius); box-shadow: var(--shadow); } +.nav-menu a { padding: 8px 14px; border-radius: 999px; } +.nav-menu a:hover { background: #f1f5ff; } +.nav-user { display:flex; align-items:center; gap:12px; } +.avatar { width: 32px; height: 32px; border-radius: 50%; background: #e5e7eb; display:inline-flex; align-items:center; justify-content:center; font-weight:600; color:#4b5563; } .card { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); } .btn { border-radius: var(--radius-sm); } .form-control, .form-select, textarea { border-radius: var(--radius-sm); } diff --git a/app/templates/base.html b/app/templates/base.html index 8270e37..b55aa89 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -11,22 +11,29 @@ diff --git a/app/templates/posts/detail.html b/app/templates/posts/detail.html index 17a03d2..98321f2 100644 --- a/app/templates/posts/detail.html +++ b/app/templates/posts/detail.html @@ -3,7 +3,18 @@ {% block content %}
-

{{ post.title }}

+
+
+ {{ post.user.username[:1]|upper }} +
+

{{ post.title }}

+ {{ post.user.username }} +
+
+ {% if current_user.is_authenticated and current_user.id != post.user.id %} + 关注作者 + {% endif %} +

{{ post.description }}

{{ post.visibility.value }}
diff --git a/app/templates/users/profile.html b/app/templates/users/profile.html index f9d3b9a..bd198f2 100644 --- a/app/templates/users/profile.html +++ b/app/templates/users/profile.html @@ -1,19 +1,37 @@ {% extends 'base.html' %} {% block title %}主页{% endblock %} {% block content %} -
-

{{ user.username }}

- {% if current_user.is_authenticated and current_user.id != user.id %} - 关注 - {% endif %} +
+
+
+ {{ user.username[:1]|upper }} +

{{ user.username }}

+
+ {% if current_user.is_authenticated and current_user.id != user.id %} + {% if is_following %} + 已关注 + {% else %} + 关注 + {% endif %} + {% endif %} +
+
粉丝 {{ followers_count }} · 关注 {{ following_count }}
+

{{ user.profile.bio }}

-

{{ user.profile.bio }}


-
作品
-
+
作品
+
{% for p in user.posts %} -
- {{ p.title }} +
+ {% set first = p.images[0] if p.images %} + {% if first %} + + {{ p.title }} + + {% endif %} +
{% endfor %}