sync update from LAN repo (source dhk-1 @ fc974e93)

This commit is contained in:
gozeros committed 2026-11-17 11:28:44 +08:00
1 parent a1fa13a238
commit e2fea6a801
432 files changed
+68707 -2270

No files matched your search

@@ -74,6 +74,21 @@ class CustomModuleListUpdateRequest(BaseModel):
modules: list[dict[str, Any]] = Field(..., description="自定义模块全量列表(整体替换)")
class PagesUpdateRequest(BaseModel):
pages: list[dict[str, Any]] = Field(..., description="页面清单(编号集合不可增删;可改名称/隐藏)")
class FieldAddRequest(BaseModel):
label: str = Field(..., min_length=1, description="字段显示名(同名拒绝)")
branch: str = Field(..., description="所属数据分支(分类对应的 DATA 顶层键)")
description: str = Field(default="", description="字段说明(可选)")
default_value: str = Field(default="待补充", description="写入各条目的初始值")
class FieldRemoveRequest(BaseModel):
label: str = Field(..., min_length=1, description="要删除的自定义字段显示名")
class CustomModuleGenerateRequest(BaseModel):
page: str = Field(..., description="挂载的页面编号(manifest.页面 的 编号)")
title: str = Field(default="", description="模块标题(留空由模型起名)")
@@ -195,11 +210,16 @@ async def get_html_template_fields(template_id: str, request: Request) -> dict[s
# 是否接受定时任务抽取数据更新(默认 True);布局分区无独立数据键,恒为 True 且前端禁用开关。
"extract": locks.get(str(f.get("label"))) is not True,
"has_key": bool(f.get("keys")),
"custom": bool(f.get("custom")),
}
for f in catalog
]
pages = [
{"key": str(p.get("编号") or ""), "label": str(p.get("名称") or p.get("编号") or "")}
{
"key": str(p.get("编号") or ""),
"label": str(p.get("名称") or p.get("编号") or ""),
"hidden": p.get("隐藏") is True,
}
for p in manifest.get("页面") or []
if isinstance(p, dict)
]
@@ -231,6 +251,57 @@ async def update_html_template_fields(
return meta
@router.post("/{template_id}/fields/add")
async def add_html_template_field(
template_id: str, body: FieldAddRequest, request: Request
) -> dict[str, Any]:
"""向分类(数据分支)添加自定义字段:fields.json 目录 + data.json 各条目同步补键(仅管理员)。"""
await _require_admin(request)
try:
meta = template_store.add_template_field(
template_id,
label=body.label,
branch=body.branch,
description=body.description,
default_value=body.default_value,
)
except template_store.TemplateStoreError as exc:
status = 404 if "不存在" in str(exc) else 400
raise HTTPException(status_code=status, detail=str(exc))
await invalidate_catalog(request, "html_templates")
return meta
@router.post("/{template_id}/fields/remove")
async def remove_html_template_field(
template_id: str, body: FieldRemoveRequest, request: Request
) -> dict[str, Any]:
"""删除自定义字段:目录项与 data.json 各条目的键一并移除(仅管理员;内置字段拒绝)。"""
await _require_admin(request)
try:
meta = template_store.remove_template_field(template_id, body.label)
except template_store.TemplateStoreError as exc:
status = 404 if "不存在" in str(exc) else 400
raise HTTPException(status_code=status, detail=str(exc))
await invalidate_catalog(request, "html_templates")
return meta
@router.put("/{template_id}/pages")
async def update_html_template_pages(
template_id: str, body: PagesUpdateRequest, request: Request
) -> dict[str, Any]:
"""更新页面清单(名称/隐藏标记;编号集合不可增删;仅管理员)。隐藏页面在产物导航整体下线。"""
await _require_admin(request)
try:
meta = template_store.write_template_pages(template_id, body.pages)
except template_store.TemplateStoreError as exc:
status = 404 if "不存在" in str(exc) else 400
raise HTTPException(status_code=status, detail=str(exc))
await invalidate_catalog(request, "html_templates")
return meta
@router.put("/{template_id}/custom-modules")
async def update_html_template_custom_modules(
template_id: str, body: CustomModuleListUpdateRequest, request: Request