From fbad02d8234f32e92c6b3cebb5a6662e4e424bee Mon Sep 17 00:00:00 2001 From: Pine Date: Fri, 4 Sep 2026 22:05:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(pages):=20=E4=B8=AA=E4=BA=BA=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=E6=9C=AA=E8=87=AA=E5=AE=9A=E4=B9=89=E6=97=B6=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=B9=B3=E5=8F=B0=E9=BB=98=E8=AE=A4=E5=90=8D=E7=89=87?= =?UTF-8?q?=20=E2=80=94=20=E4=BA=BA=E6=89=8D=E6=A1=A3=E6=A1=88+=E5=B7=B2?= =?UTF-8?q?=E4=B8=8A=E6=9E=B6=E6=9C=8D=E5=8A=A1+=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E7=9B=B4=E9=93=BE=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/routers/rbac_pages.py | 62 +++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/app/api/routers/rbac_pages.py b/app/api/routers/rbac_pages.py index 03388a9..672e1c1 100644 --- a/app/api/routers/rbac_pages.py +++ b/app/api/routers/rbac_pages.py @@ -2,7 +2,7 @@ - GET /pages/{user_id} 公开渲染数据:页面内容 + 身份条(昵称/头像/信用/徽章) + 能力接入说明(capabilities 非空 → connected 接入说明;空 → unverified 提醒访客核实)。 - 未发布页仅本人可见(返回 published=false),他人访问返回 404。 + 未设置个人主页或他人访问未上架页 → 返回 page=null + default(人才档案 + 已上架服务)。 - GET /pages/me 我的个人主页(含发布状态) - PUT /pages/me 保存个人主页(html 源码 或 embed 第三方网页 + 能力声明) - POST /pages/me/publish 上架/下架 @@ -83,9 +83,10 @@ async def _compute_badges(db: Database, user_id: str) -> list[dict]: def _public_profile(user: dict, badges: list[dict], credit: int | None) -> dict: + from ...infrastructure.oss import resolve_url return { "nickname": user.get("nickname") or user.get("username") or "OPC 用户", - "avatar": user.get("avatar") or "", + "avatar": resolve_url(user.get("avatar") or ""), "creditScore": credit, "badges": badges, } @@ -120,38 +121,57 @@ async def publish_my_page(body: dict = Body(default={}), db: Database = Depends( # ── 公开渲染数据(人才市场等入口跳转查看)─────────────────────────────── -@router.get("/{user_id}", summary="获取用户个人主页(公开渲染数据)") +@router.get("/{user_id}", summary="获取用户个人主页(公开渲染数据;未设置时返回默认名片数据)") async def get_user_page(user_id: str, db: Database = Depends(get_db), viewer: dict = Depends(get_current_user)): page = await db.user_pages.get(user_id) - if page is None: - raise HTTPException(status_code=404, detail="该用户尚未创建个人主页") - is_self = (viewer.get("id") or "") == user_id - if not page.get("published") and not is_self: - raise HTTPException(status_code=404, detail="该用户个人主页未上架") - user = (await db.users.get_by_id(user_id)) or {} + if not user: + raise HTTPException(status_code=404, detail="用户不存在") + is_self = (viewer.get("id") or "") == user_id badges = await _compute_badges(db, user_id) opc_profile = await db.opc_profiles.get(user_id) credit = (opc_profile or {}).get("credit_score") - capabilities = page.get("capabilities") or [] + + # 已上架(或本人自己的页)→ 渲染用户自写页面 + if page and (page.get("published") or is_self): + capabilities = page.get("capabilities") or [] + notice = { + "type": "connected" if capabilities else "unverified", + "capabilities": capabilities, + "text": ("本页面已接入平台数据能力,所展示数据为平台实时数据" if capabilities + else "本页面内容由用户自行编写,平台未对其中数据与信息进行核验,请注意核实"), + } + return { + "page": { + "pageType": page.get("pageType"), + "htmlContent": page.get("htmlContent") if page.get("pageType") == "html" else "", + "embedUrl": page.get("embedUrl") if page.get("pageType") == "embed" else "", + "capabilities": capabilities, + "published": page.get("published"), + }, + "profile": _public_profile(user, badges, credit), + "notice": notice, + "ownerIsSelf": is_self, + } + + # 未设置个人主页 / 他人访问未上架页 → 渲染平台默认名片(基础资料 + 已上架服务) + talent = await db.hall_talents.get(user_id) + services = await db.hall_services.list(status="published", opc_id=user_id) notice = { - "type": "connected" if capabilities else "unverified", - "capabilities": capabilities, - "text": ("本页面已接入平台数据能力,所展示数据为平台实时数据" if capabilities - else "本页面内容由用户自行编写,平台未对其中数据与信息进行核验,请注意核实"), + "type": "unverified", + "capabilities": [], + "text": "该用户尚未自定义个人主页,以下内容为平台公开信息,请注意核实", } return { - "page": { - "pageType": page.get("pageType"), - "htmlContent": page.get("htmlContent") if page.get("pageType") == "html" else "", - "embedUrl": page.get("embedUrl") if page.get("pageType") == "embed" else "", - "capabilities": capabilities, - "published": page.get("published"), - }, + "page": None, "profile": _public_profile(user, badges, credit), "notice": notice, "ownerIsSelf": is_self, + "default": { + "talent": talent, + "services": services, + }, }