提交
This commit is contained in:
1 parent
833544def3
commit
16be6fa22d
204 files changed
+455089
-46491
No files matched your search
@@ -2074,3 +2074,55 @@ def delete_menu_favorite(
|
||||
db, user_id=user_id, tenant_no=tenant_no, menu_path=body.path
|
||||
)
|
||||
return success_response({"path": body.path})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Demo 模板页:Mock 数据由前端组装行后走统一 xlsx 导出(无 Demo 业务表)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class DemoXlsxColumnSpec(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
title: str
|
||||
field: str
|
||||
|
||||
|
||||
class DemoXlsxExportBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
sheet_title: str = Field(default="导出", alias="sheetTitle")
|
||||
filename_stem: str = Field(default="export", alias="filenameStem")
|
||||
columns: List[DemoXlsxColumnSpec]
|
||||
rows: List[dict]
|
||||
|
||||
|
||||
@router.post("/demo/xlsx-export")
|
||||
def demo_xlsx_export(
|
||||
body: DemoXlsxExportBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Demo 列表导出:接收已筛选行与列定义,生成 xlsx。"""
|
||||
try:
|
||||
rows = body.rows or []
|
||||
if not rows:
|
||||
raise ExportValidationError("没有可导出的数据")
|
||||
if len(rows) > EXPORT_MAX_ROWS:
|
||||
raise ExportValidationError(f"导出超过 {EXPORT_MAX_ROWS} 条,请缩小筛选范围")
|
||||
if not body.columns:
|
||||
raise ExportValidationError("没有可导出的列")
|
||||
cols = [ExportColumn(title=c.title, field=c.field) for c in body.columns]
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
date_str = datetime.now().strftime("%Y%m%d")
|
||||
stem = (body.filename_stem or "export").strip() or "export"
|
||||
return export_rows_to_xlsx_response(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
sheet_title=body.sheet_title or "导出",
|
||||
columns=cols,
|
||||
rows=rows,
|
||||
filename_stem=f"{stem}_{date_str}",
|
||||
)
|
||||
except ExportValidationError as e:
|
||||
return error_response(400, str(e))
|
||||
Reference in new issue
Block a user