move export options to results
This commit is contained in:
97
app/main.py
97
app/main.py
@@ -62,11 +62,6 @@ def index() -> str:
|
||||
<input id="preview_rows" name="preview_rows" type="number" min="5" max="200" value="20">
|
||||
</div>
|
||||
</div>
|
||||
<div class="checks">
|
||||
<label><input type="checkbox" name="include_basic_sheets" value="true" checked> \u57fa\u672c\u5de5\u4f5c\u8868</label>
|
||||
<label><input type="checkbox" name="include_unmatched_items" value="true" checked> \u672a\u5339\u914d\u68c0\u6d4b\u5185\u5bb9\u9879</label>
|
||||
<label><input type="checkbox" name="include_summary_sheet" value="true" checked> \u672a\u68c0\u6d4b\u5230\u5185\u5bb9\u6c47\u603b\u8868</label>
|
||||
</div>
|
||||
<button type="submit">\u5f00\u59cb\u5904\u7406</button>
|
||||
</form>
|
||||
<div class="note">\u9ed8\u8ba4\u8f93\u51fa\u5168\u90e8\u68c0\u6d4b\u8bb0\u5f55\uff0c\u5e76\u4fdd\u7559\u201c{UNMATCHED}\u201d\u5217\uff1b\u8be5\u5217\u4e3a\u989d\u5916\u8f85\u52a9\u4fe1\u606f\uff0c\u4fbf\u4e8e\u6838\u5bf9\u672a\u5f52\u7c7b\u9879\u76ee\u3002</div>
|
||||
@@ -82,9 +77,6 @@ async def process(
|
||||
data_type: str = Form("auto"),
|
||||
result_name: str = Form("Result"),
|
||||
preview_rows: int = Form(20),
|
||||
include_basic_sheets: str | None = Form(None),
|
||||
include_unmatched_items: str | None = Form(None),
|
||||
include_summary_sheet: str | None = Form(None),
|
||||
) -> str:
|
||||
if not file.filename or not file.filename.lower().endswith(".zip"):
|
||||
raise HTTPException(status_code=400, detail="\u8bf7\u4e0a\u4f20 zip \u6587\u4ef6\u3002")
|
||||
@@ -106,9 +98,9 @@ async def process(
|
||||
show_not_match=True,
|
||||
show_all_infos=True,
|
||||
preview_rows=rows,
|
||||
include_basic_sheets=include_basic_sheets == "true",
|
||||
include_unmatched_items=include_unmatched_items == "true",
|
||||
include_summary_sheet=include_summary_sheet == "true",
|
||||
include_basic_sheets=True,
|
||||
include_unmatched_items=True,
|
||||
include_summary_sheet=True,
|
||||
)
|
||||
except ProcessingError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
@@ -130,20 +122,42 @@ def result_page(job_id: str, preview_rows: int = Query(20, ge=5, le=200)) -> str
|
||||
|
||||
|
||||
@app.get("/download/all/{job_id}")
|
||||
def download_all(job_id: str) -> FileResponse:
|
||||
def download_all(
|
||||
job_id: str,
|
||||
include_basic_sheets: bool = Query(True),
|
||||
include_unmatched_items: bool = Query(True),
|
||||
include_summary_sheet: bool = Query(True),
|
||||
) -> FileResponse:
|
||||
job_dir = _get_job_dir(job_id)
|
||||
try:
|
||||
result_zip = create_result_zip(job_dir)
|
||||
result_zip = create_result_zip(
|
||||
job_dir,
|
||||
include_basic_sheets=include_basic_sheets,
|
||||
include_unmatched_items=include_unmatched_items,
|
||||
include_summary_sheet=include_summary_sheet,
|
||||
)
|
||||
except ProcessingError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
return FileResponse(result_zip, media_type="application/zip", filename="result.zip")
|
||||
|
||||
|
||||
@app.get("/download/file/{job_id}")
|
||||
def download_file(job_id: str, path: str = Query(...)) -> FileResponse:
|
||||
def download_file(
|
||||
job_id: str,
|
||||
path: str = Query(...),
|
||||
include_basic_sheets: bool = Query(True),
|
||||
include_unmatched_items: bool = Query(True),
|
||||
include_summary_sheet: bool = Query(True),
|
||||
) -> FileResponse:
|
||||
job_dir = _get_job_dir(job_id)
|
||||
try:
|
||||
target = find_output_file(job_dir, path)
|
||||
target = find_output_file(
|
||||
job_dir,
|
||||
path,
|
||||
include_basic_sheets=include_basic_sheets,
|
||||
include_unmatched_items=include_unmatched_items,
|
||||
include_summary_sheet=include_summary_sheet,
|
||||
)
|
||||
except ProcessingError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
return FileResponse(
|
||||
@@ -184,9 +198,15 @@ def _render_result(result: ProcessingResult, preview_rows: int = 20) -> str:
|
||||
<div class="metric"><span>\u6570\u636e\u884c</span><strong>{total_rows}</strong></div>
|
||||
</section>
|
||||
<section class="actions">
|
||||
<a class="button" href="/download/all/{html.escape(result.job_id)}">\u5bfc\u51fa\u5168\u90e8 Excel</a>
|
||||
<a class="button export-link" data-base="/download/all/{html.escape(result.job_id)}" href="/download/all/{html.escape(result.job_id)}">\u5bfc\u51fa\u5168\u90e8 Excel</a>
|
||||
<a class="ghost" href="/">\u7ee7\u7eed\u5904\u7406\u65b0\u6587\u4ef6</a>
|
||||
</section>
|
||||
<section class="export-options">
|
||||
<strong>\u5bfc\u51fa\u5185\u5bb9\u9009\u62e9</strong>
|
||||
<label><input class="export-option" type="checkbox" data-param="include_basic_sheets" checked> \u57fa\u672c\u5de5\u4f5c\u8868</label>
|
||||
<label><input class="export-option" type="checkbox" data-param="include_unmatched_items" checked> \u672a\u5339\u914d\u68c0\u6d4b\u5185\u5bb9\u9879</label>
|
||||
<label><input class="export-option" type="checkbox" data-param="include_summary_sheet" checked> \u672a\u68c0\u6d4b\u5230\u5185\u5bb9\u6c47\u603b\u8868</label>
|
||||
</section>
|
||||
<form class="row-control" method="get" action="/result/{html.escape(result.job_id)}">
|
||||
<label for="preview_rows">\u6bcf\u4e2a\u5de5\u4f5c\u8868\u9884\u89c8\u884c\u6570</label>
|
||||
<input id="preview_rows" name="preview_rows" type="number" min="5" max="200" value="{preview_rows}">
|
||||
@@ -210,7 +230,7 @@ def _render_file(file, job_id: str) -> str:
|
||||
<h2>{html.escape(file.filename)}</h2>
|
||||
<p>{len(file.sheets)} \u4e2a\u5de5\u4f5c\u8868</p>
|
||||
</div>
|
||||
<a class="small-button" href="{file_url}">\u5bfc\u51fa\u6b64 Excel</a>
|
||||
<a class="small-button export-link" data-base="{file_url}" href="{file_url}">\u5bfc\u51fa\u6b64 Excel</a>
|
||||
</div>
|
||||
{sheet_items}
|
||||
</article>
|
||||
@@ -227,12 +247,13 @@ def _render_sheet(sheet) -> str:
|
||||
unmatched_start = preview[0].index(UNMATCHED)
|
||||
rows = []
|
||||
for index, row in enumerate(preview):
|
||||
row_class = ' class="group-header"' if _is_summary_group_header(row) else ""
|
||||
cells = []
|
||||
for col_index, value in enumerate((row + [""] * max_cols)[:max_cols]):
|
||||
tag = "th" if index == 0 else "td"
|
||||
css_class = ' class="extra-col"' if unmatched_start is not None and col_index >= unmatched_start else ""
|
||||
cells.append(f"<{tag}{css_class}>{html.escape(value)}</{tag}>")
|
||||
rows.append("<tr>" + "".join(cells) + "</tr>")
|
||||
rows.append(f"<tr{row_class}>" + "".join(cells) + "</tr>")
|
||||
table = f'<div class="table-wrap"><table>{"".join(rows)}</table></div>'
|
||||
return f"""
|
||||
<details class="sheet" open>
|
||||
@@ -330,6 +351,25 @@ def _page_shell(body: str, subtitle: str = "\u4e0a\u4f20\u201c\u5f85\u5904\u7406
|
||||
color: var(--text);
|
||||
font-size: 14px;
|
||||
}}
|
||||
.export-options {{
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 14px;
|
||||
font-size: 14px;
|
||||
}}
|
||||
.export-options label {{
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
font-weight: 500;
|
||||
}}
|
||||
.checks label {{
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -463,6 +503,7 @@ def _page_shell(body: str, subtitle: str = "\u4e0a\u4f20\u201c\u5f85\u5904\u7406
|
||||
white-space: nowrap;
|
||||
}}
|
||||
th {{ background: #fbfcfd; font-weight: 700; }}
|
||||
tr.group-header td {{ font-weight: 700; background: #fbfcfd; }}
|
||||
th.extra-col, td.extra-col {{ background: var(--extra); }}
|
||||
.empty {{
|
||||
color: var(--muted);
|
||||
@@ -471,7 +512,7 @@ def _page_shell(body: str, subtitle: str = "\u4e0a\u4f20\u201c\u5f85\u5904\u7406
|
||||
}}
|
||||
@media (max-width: 760px) {{
|
||||
.grid, .summary {{ grid-template-columns: 1fr; }}
|
||||
.actions, .file-head, .row-control {{ align-items: stretch; flex-direction: column; }}
|
||||
.actions, .file-head, .row-control, .export-options {{ align-items: stretch; flex-direction: column; }}
|
||||
.row-control input {{ width: 100%; }}
|
||||
button, .button, .small-button, .ghost {{ width: 100%; }}
|
||||
}}
|
||||
@@ -485,6 +526,24 @@ def _page_shell(body: str, subtitle: str = "\u4e0a\u4f20\u201c\u5f85\u5904\u7406
|
||||
</header>
|
||||
{body}
|
||||
</main>
|
||||
<script>
|
||||
function updateExportLinks() {{
|
||||
const options = Array.from(document.querySelectorAll('.export-option'));
|
||||
const params = new URLSearchParams();
|
||||
options.forEach((option) => params.set(option.dataset.param, option.checked ? 'true' : 'false'));
|
||||
document.querySelectorAll('.export-link').forEach((link) => {{
|
||||
const base = link.dataset.base;
|
||||
const sep = base.includes('?') ? '&' : '?';
|
||||
link.href = base + sep + params.toString();
|
||||
}});
|
||||
}}
|
||||
document.querySelectorAll('.export-option').forEach((option) => option.addEventListener('change', updateExportLinks));
|
||||
updateExportLinks();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
def _is_summary_group_header(row: list[str]) -> bool:
|
||||
return len(row) >= 4 and row[0] == "\u59d3\u540d" and row[1] == "\u4f4f\u9662\u53f7" and row[2] == "\u91c7\u6837\u65f6\u95f4" and row[3].startswith("\u68c0\u6d4b\u539f\u56e0")
|
||||
|
||||
Reference in New Issue
Block a user