完善文档审核页:模式标签、签名下载、自检产物清理

- 顶栏操作按钮在移动端带文字(切换/旋转/重置/设置),视图按钮固定叫「切换」;
  图片左上角常驻当前模式(手动定位/校正预览),右上角浮页码 1/n,不再占顶栏。
- 下载改走 files/download-token 的签名直链:APK/系统下载器不携带 cookie,
  原先直连 /files/download 会 401 且只能落成 download.pdf。
- 全局设置去掉「N 页已生成」摘要行,右上角加关闭 X;底部保留完成按钮。
- 重新生成 PDF 仅在有未保存修改时出现,成功后消失;新增左右滑动翻页。
- 自检渲染图(.tmp/pdfcheck 下的 PPM)在 inspect_pdf 结束时删除,不再残留在会话目录。
This commit is contained in:
2026-10-24 01:12:44 +08:00
parent fe1c6d106f
commit fbe78d362f
5 changed files with 245 additions and 144 deletions
+21 -2
View File
@@ -95,17 +95,36 @@ requested_at TEXT, started_at TEXT, finished_at TEXT
1. 页面从 `/app/<task_id>/doc-review/` 加载;无 `?b=` 时查 `doc_review_batch` 最新一行。 1. 页面从 `/app/<task_id>/doc-review/` 加载;无 `?b=` 时查 `doc_review_batch` 最新一行。
2. 通过 `POST /api/db/<task_id>/query` 读 `doc_review_batch` / `doc_review_page`。 2. 通过 `POST /api/db/<task_id>/query` 读 `doc_review_batch` / `doc_review_page`。
3. 用户拖角/旋转/删页/排序/改四项参数,只改浏览器内状态并写 localStorage 草稿。 3. 用户拖角/旋转/删页/排序/改四项参数,只改浏览器内状态并写 localStorage 草稿。
4. 点「生成 PDF」: 4. 点「重新生成 PDF」:
- `INSERT ... ON CONFLICT` 写 `doc_review_job`(`status=queued`,`edits` 是完整快照); - `INSERT ... ON CONFLICT` 写 `doc_review_job`(`status=queued`,`edits` 是完整快照);
- 调通用执行接口 - 调通用执行接口
`POST /api/sessions/<task_id>/skills/document-photo-to-pdf/run`,body `{args:{batch_id}}`; `POST /api/sessions/<task_id>/skills/document-photo-to-pdf/run`,body `{args:{batch_id}}`;
- 技能读 job → 应用 edits → 覆盖同名 PDF → 更新 batch/page/job; - 技能读 job → 应用 edits → 覆盖同名 PDF → 更新 batch/page/job;
- 页面重新读 data.db,刷新摘要、状态、PDF 链接。 - 页面重新读 data.db,刷新警告、状态、PDF 链接。
5. 全程不经过模型,也不需要用户复制 JSON。 5. 全程不经过模型,也不需要用户复制 JSON。
通用接口实现在 `app/server/routes/skill-run.js`:core 只做会话/并发/错误映射,执行仍走 通用接口实现在 `app/server/routes/skill-run.js`:core 只做会话/并发/错误映射,执行仍走
`tools/skills.runSkill`,不感知技能名或参数语义。 `tools/skills.runSkill`,不感知技能名或参数语义。
## 页面交互约定
- 顶部标题条(白底,参考 H5 全屏预览):左侧 PDF 名,右侧下载 PDF,最右 X 返回会话。
- 重新生成 PDF 不在顶栏:放在照片区底部(stage 与预览各一个,按当前视图显示;桌面只用
stage),仅在存在未保存修改时出现。
- 底部只保留翻页和当前页名,不再放操作按钮。
- 页码不占顶栏:`1/n` 浮在图片右上角(裁切区、预览区各一个,按当前视图显示);
左上角常驻当前模式标签(裁切区「手动定位」、预览区「校正预览」)。
移动端一次只显示一个面板,看到哪个标签就是当前模式;视图按钮固定叫「切换」。
移动端顶栏按钮带文字而非只靠图标:视图按钮写“点下去会去哪”(当前在预览→手动定位,
在当前裁切→校正预览),另三个是旋转 / 重置 / 设置。
- 裁切区/预览区支持左右滑动翻页:左滑下一页、右滑上一页;仅触摸/笔生效,拖角优先,
按钮点击不触发。
- 是否 dirty 用 `collect()` 与加载时的基线 `S.savedEdits` 比较;拖角、旋转、删页/排序、
改四项参数都会触发。
- 重新生成成功后重读 DB、清本地草稿、把新状态设为基线,按钮自动消失;失败则保留以便重试。
- X 返回 `/?s=<task_id>`;独立页面里也适用。
- 手机默认进校正预览,点左上角切到裁切。
## edits / 旋转语义 ## edits / 旋转语义
```json ```json
+1 -1
View File
@@ -34,7 +34,7 @@ input_schema:
访问地址:https://agent.ai.foresh.com/app/task-20261023-001/doc-review/ 访问地址:https://agent.ai.foresh.com/app/task-20261023-001/doc-review/
``` ```
审核页可拖角、旋转、删页/排序、改纸张与清晰度;点「生成 PDF」覆盖同名文件。 审核页可拖角、旋转、删页/排序、改纸张与清晰度;改动后点「重新生成 PDF」覆盖同名文件。
## 失败与拍摄 ## 失败与拍摄
@@ -203,6 +203,7 @@ def inspect_pdf(pdf, expect_pages=None, dpi=None, params=None):
# 折算,否则选 300dpi 会白白放宽、选 72dpi 会误报“分辨率不足”。 # 折算,否则选 300dpi 会白白放宽、选 72dpi 会误报“分辨率不足”。
render_dpi = float(p["render"]["dpi"]) render_dpi = float(p["render"]["dpi"])
min_short = c["min_short"] * dpi / render_dpi min_short = c["min_short"] * dpi / render_dpi
try:
for i, path in enumerate(files, 1): for i, path in enumerate(files, 1):
with Image.open(path) as im: with Image.open(path) as im:
r = analyse(im, p) r = analyse(im, p)
@@ -237,6 +238,10 @@ def inspect_pdf(pdf, expect_pages=None, dpi=None, params=None):
out["pages"].append(item) out["pages"].append(item)
if not (short_ok and border_ok and cut_ok): if not (short_ok and border_ok and cut_ok):
out["ok"] = False out["ok"] = False
finally:
# 渲染图只是自检的中间产物:PPM 未压缩,100dpi 的 A4 一页约 3MB,
# 检验完立刻删(量已经记录在返回值里),不要留在会话目录占空间。
shutil.rmtree(outdir, ignore_errors=True)
return out return out
@@ -108,7 +108,7 @@ P = {
"flat_pct": 99.5, # 页面纯白分位 "flat_pct": 99.5, # 页面纯白分位
"nonwhite_delta": 8.0, # 低于纯白该值视为非白(用于找纸面框) "nonwhite_delta": 8.0, # 低于纯白该值视为非白(用于找纸面框)
"paper_row_frac": 0.05, # 行列非白占比阈值 "paper_row_frac": 0.05, # 行列非白占比阈值
"tmp_dir": ".tmp/pdfcheck", # 检验渲染临时目录(相对输出目录) "tmp_dir": ".tmp/pdfcheck", # 检验渲染临时目录(相对输出目录,检验完即删)
}, },
# ---------------------------------------------------------------- 输出 # ---------------------------------------------------------------- 输出
+183 -106
View File
@@ -13,20 +13,39 @@ html,body{margin:0;height:100%;background:#0b0f17;color:#e8edf5;
body{display:flex;flex-direction:column;height:100%;height:100dvh} body{display:flex;flex-direction:column;height:100%;height:100dvh}
.top{display:flex;align-items:center;gap:6px;flex:none;z-index:5; .top{display:flex;align-items:center;gap:6px;flex:none;z-index:5;
padding:6px 10px;padding-top:calc(6px + env(safe-area-inset-top)); padding:6px 10px;border-bottom:1px solid #1b2434;background:#0b0f17}
border-bottom:1px solid #1b2434;background:#0b0f17}
/* 顶部标题条:白色,和深色编辑区区分(参考 H5 全屏预览的 fs-bar) */
.actbar{display:flex;align-items:center;gap:6px;flex:none;z-index:7;
height:calc(40px + env(safe-area-inset-top));
padding:env(safe-area-inset-top) 10px 0 12px;
background:#fff;border-bottom:1px solid #e5e7eb;color:#111827}
.abtn{height:32px;min-width:32px;padding:0 8px;border:0;border-radius:8px;
background:transparent;color:#111827;font-size:13px;line-height:1;
display:flex;align-items:center;justify-content:center;gap:6px;flex:none}
.abtn:active{background:#eef1f6}
.abtn:disabled{opacity:.4}
.abtn svg{width:18px;height:18px;display:block}
#back{font-size:16px}
.aname{flex:1;min-width:0;text-align:left;font-size:13px;font-weight:600;color:#111827;
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.top .nav{width:36px;height:40px;font-size:20px;line-height:1;border:0;border-radius:9px; .top .nav{width:36px;height:40px;font-size:20px;line-height:1;border:0;border-radius:9px;
background:#161f2e;color:#e8edf5;flex:none;padding:0} background:#161f2e;color:#e8edf5;flex:none;padding:0}
.top .nav:disabled{opacity:.25} .top .nav:disabled{opacity:.25}
.pager{min-width:48px;text-align:center;color:#9fb0c8; /* 页码浮在图片右上角(裁切区 / 预览区共用),不占顶栏 */
font-variant-numeric:tabular-nums;flex:none} .pbadge{position:absolute;right:10px;top:10px;z-index:7;padding:2px 8px;border-radius:99px;
.pager b{color:#e8edf5;font-size:15px} background:rgba(4,7,12,.58);color:#c3d0e2;font-size:11px;line-height:1.5;
font-variant-numeric:tabular-nums;pointer-events:none}
/* 当前模式标签:左上角,与右上角页码对称 */
.pbadge.mtag{left:10px;right:auto;color:#e8edf5}
.acts{margin-left:auto;display:flex;gap:4px;flex:none} .acts{margin-left:auto;display:flex;gap:4px;flex:none}
.ico{height:40px;width:40px;padding:0;border:0;border-radius:9px;background:#161f2e; .ico{height:40px;width:40px;padding:0;border:0;border-radius:9px;background:#161f2e;
color:#c3d0e2;display:flex;align-items:center;justify-content:center;flex:none;gap:7px} color:#c3d0e2;display:flex;align-items:center;justify-content:center;flex:none;gap:7px}
.ico:active{background:#22304a} .ico:active{background:#22304a}
.ico:disabled{opacity:.4}
.ico.pri{background:#1f6feb;color:#fff} .ico.pri{background:#1f6feb;color:#fff}
.ico svg{width:20px;height:20px;display:block;flex:none} .ico svg{width:20px;height:20px;display:block;flex:none}
.vi{display:flex;align-items:center;justify-content:center;flex:none}
.lbl{display:none;font-size:13px;white-space:nowrap} .lbl{display:none;font-size:13px;white-space:nowrap}
/* 移动端翻页按钮:浮在图片左右两侧 */ /* 移动端翻页按钮:浮在图片左右两侧 */
@@ -59,17 +78,28 @@ body{display:flex;flex-direction:column;height:100%;height:100dvh}
/* 移动端只显示一个窗口:默认原图,点左上角切到预览 */ /* 移动端只显示一个窗口:默认原图,点左上角切到预览 */
#prevwrap{display:none;flex:1 1 auto;min-height:0;flex-direction:column; #prevwrap{display:none;flex:1 1 auto;min-height:0;flex-direction:column;
background:#0a0e16} position:relative;touch-action:none;background:#0a0e16}
.pv-hd{display:flex;align-items:center;gap:8px;padding:8px 12px 0;flex:none;
font-size:12px;color:#7d8ea6}
#prevwrap .box{flex:1;min-height:0;display:flex;align-items:center;justify-content:center; #prevwrap .box{flex:1;min-height:0;display:flex;align-items:center;justify-content:center;
padding:8px 12px 10px;overflow:hidden} padding:8px 12px 10px;overflow:hidden}
#preview{display:block;max-width:100%;max-height:100%} #preview{display:block;max-width:100%;max-height:100%}
/* 重新生成:放在照片区底部,避开顶部工具栏;sticky 预览模式下用 prevwrap 里的那个 */
.regen{position:absolute;left:50%;bottom:14px;transform:translateX(-50%);z-index:8;
display:inline-flex;align-items:center;justify-content:center;line-height:1;
height:38px;padding:0 18px;border:0;border-radius:19px;background:#1f6feb;color:#fff;
font-size:13px;font-weight:600;white-space:nowrap;
box-shadow:0 4px 14px rgba(0,0,0,.35)}
.regen:active{background:#1a5fd0}
.regen:disabled{opacity:.55}
@media (max-width:899.98px){ @media (max-width:899.98px){
.top .nav{display:none} .top .nav{display:none}
body.view-prev .stage{display:none} body.view-prev .stage{display:none}
body.view-prev #prevwrap{display:flex} body.view-prev #prevwrap{display:flex}
/* 移动端只靠图标猜不出功能:图标在上、两字标签在下 */
.ico{flex-direction:column;width:54px;height:48px;gap:2px;padding:0}
.ico svg{width:18px;height:18px}
.ico .lbl{display:block;font-size:10px;line-height:1}
} }
.sheet{position:fixed;inset:0;background:rgba(4,7,12,.74);display:none; .sheet{position:fixed;inset:0;background:rgba(4,7,12,.74);display:none;
@@ -78,6 +108,10 @@ body{display:flex;flex-direction:column;height:100%;height:100dvh}
.sheet .card{background:#111826;width:100%;max-width:520px;border-radius:16px 16px 0 0; .sheet .card{background:#111826;width:100%;max-width:520px;border-radius:16px 16px 0 0;
padding:16px 16px calc(14px + env(safe-area-inset-bottom));max-height:86vh;overflow:auto} padding:16px 16px calc(14px + env(safe-area-inset-bottom));max-height:86vh;overflow:auto}
.sheet .card h3{margin:0 0 6px;font-size:15px;font-weight:600} .sheet .card h3{margin:0 0 6px;font-size:15px;font-weight:600}
.sheet .shd{display:flex;align-items:center;justify-content:space-between;margin:0 0 6px}
.sheet .shd h3{margin:0}
.sheet .shd .x{width:28px;height:28px;border:0;border-radius:50%;background:#1b2536;color:#c3d0e2;
font-size:14px;line-height:1;display:inline-flex;align-items:center;justify-content:center}
.sheet .card p{margin:0 0 10px;color:#8ea1ba;font-size:12px;line-height:1.5} .sheet .card p{margin:0 0 10px;color:#8ea1ba;font-size:12px;line-height:1.5}
.grp{margin:14px 0 0} .grp{margin:14px 0 0}
.gl{font-size:12px;color:#8ea1ba;margin-bottom:6px} .gl{font-size:12px;color:#8ea1ba;margin-bottom:6px}
@@ -101,12 +135,14 @@ body{display:flex;flex-direction:column;height:100%;height:100dvh}
/* 桌面:左原图、右预览,顶栏按钮带文字 */ /* 桌面:左原图、右预览,顶栏按钮带文字 */
@media (min-width:900px){ @media (min-width:900px){
body{display:grid;grid-template-columns:minmax(0,1fr) 432px; body{display:grid;grid-template-columns:minmax(0,1fr) 432px;
grid-template-rows:auto minmax(0,1fr) auto;height:100dvh} grid-template-rows:auto auto minmax(0,1fr) auto;height:100dvh}
.top{grid-column:1/-1;grid-row:1} .actbar{grid-column:1/-1;grid-row:1}
.stage{grid-row:2;grid-column:1} .top{grid-column:1/-1;grid-row:2}
#prevwrap{grid-row:2/4;grid-column:2;border-left:1px solid #1b2434} .stage{grid-row:3;grid-column:1}
#prevwrap{grid-row:3/5;grid-column:2;border-left:1px solid #1b2434}
#view{display:none} #view{display:none}
.footbar{grid-row:3;grid-column:1;border-top:1px solid #1b2434;padding-bottom:6px} #prevwrap .regen{display:none!important}
.footbar{grid-row:4;grid-column:1;border-top:1px solid #1b2434;padding-bottom:6px}
.footbar .pnav{display:none} .footbar .pnav{display:none}
/* 桌面端顶栏已有翻页,底栏两侧占位保持文件名真正居中 */ /* 桌面端顶栏已有翻页,底栏两侧占位保持文件名真正居中 */
.ico{width:auto;padding:0 14px} .ico{width:auto;padding:0 14px}
@@ -114,43 +150,45 @@ body{display:flex;flex-direction:column;height:100%;height:100dvh}
/* 桌面端翻页在顶栏,底栏只留居中的文件名 */ /* 桌面端翻页在顶栏,底栏只留居中的文件名 */
.footname{font-size:13px;color:#b9c8dd} .footname{font-size:13px;color:#b9c8dd}
} }
/* 一键重生成:浮动主按钮。手机放在底栏上方,桌面放在预览区左侧,避免挤顶栏。 */
.fab{position:fixed;right:14px;bottom:calc(64px + env(safe-area-inset-bottom));z-index:15;
height:48px;padding:0 18px;border:0;border-radius:24px;background:#1f6feb;color:#fff;
font-size:15px;font-weight:600;box-shadow:0 6px 20px rgba(0,0,0,.45);
display:flex;align-items:center;justify-content:center}
.fab:active{background:#1a5fd0}
.fab:disabled{opacity:.55}
.fab .lbl{display:inline}
@media (min-width:900px){.fab{right:456px;bottom:76px}}
</style> </style>
</head> </head>
<body> <body>
<div class="actbar">
<div class="aname" id="btitle">文档审核</div>
<button id="pdf" class="abtn" title="下载 PDF" aria-label="下载 PDF">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
</button>
<button id="back" class="abtn" title="返回会话" aria-label="返回会话">✕</button>
</div>
<div class="top"> <div class="top">
<button class="ico" id="view" title="切换原图 / 预览" aria-label="切换视图"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1.5 12S5.5 4.5 12 4.5 22.5 12 22.5 12 18.5 19.5 12 19.5 1.5 12 1.5 12z"/><circle cx="12" cy="12" r="3"/></svg></button> <button class="ico" id="view" title="切换视图" aria-label="切换视图"><span class="vi" id="viewIcon"></span><span class="lbl">切换</span></button>
<button class="nav" id="navPrev" aria-label="上一页">&#8249;</button> <button class="nav" id="navPrev" aria-label="上一页">&#8249;</button>
<div class="pager"><b id="cur">1</b> / <span id="total">1</span></div>
<button class="nav" id="navNext" aria-label="下一页">&#8250;</button> <button class="nav" id="navNext" aria-label="下一页">&#8250;</button>
<div class="acts"> <div class="acts">
<button class="ico" id="rot" title="旋转 90%" aria-label="旋转"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-2.64-6.36"/><path d="M21 3v6h-6"/></svg><span class="lbl">旋转 90&#176;</span></button> <button class="ico" id="rot" title="旋转 90°" aria-label="旋转 90 度"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-2.64-6.36"/><path d="M21 3v6h-6"/></svg><span class="lbl">旋转</span></button>
<button class="ico" id="reset" title="重置本页" aria-label="重置"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14L4 9l5-5"/><path d="M4 9h10a6 6 0 0 1 0 12h-4"/></svg><span class="lbl">重置本页</span></button> <button class="ico" id="reset" title="恢复自动角点" aria-label="重置本页"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14L4 9l5-5"/><path d="M4 9h10a6 6 0 0 1 0 12h-4"/></svg><span class="lbl">重置</span></button>
<button class="ico" id="gear" title="全局设置" aria-label="全局设置"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 7h16M4 12h16M4 17h16"/><circle cx="9" cy="7" r="2.1" fill="currentColor" stroke="none"/><circle cx="15" cy="12" r="2.1" fill="currentColor" stroke="none"/><circle cx="9" cy="17" r="2.1" fill="currentColor" stroke="none"/></svg><span class="lbl">全局设置</span></button> <button class="ico" id="gear" title="全局设置" aria-label="全局设置"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 7h16M4 12h16M4 17h16"/><circle cx="9" cy="7" r="2.1" fill="currentColor" stroke="none"/><circle cx="15" cy="12" r="2.1" fill="currentColor" stroke="none"/><circle cx="9" cy="17" r="2.1" fill="currentColor" stroke="none"/></svg><span class="lbl">设置</span></button>
</div> </div>
</div> </div>
<div class="stage" id="stage"> <div class="stage" id="stage">
<div class="pbadge mtag">手动定位</div>
<div class="pbadge" id="stagePage">1/1</div>
<canvas id="photo"></canvas> <canvas id="photo"></canvas>
<div class="h" id="h0"></div> <div class="h" id="h0"></div>
<div class="h" id="h1"></div> <div class="h" id="h1"></div>
<div class="h" id="h2"></div> <div class="h" id="h2"></div>
<div class="h" id="h3"></div> <div class="h" id="h3"></div>
<canvas id="loupe"></canvas> <canvas id="loupe"></canvas>
<button class="regen" type="button" style="display:none">重新生成 PDF</button>
</div> </div>
<div id="prevwrap"> <div id="prevwrap">
<div class="pv-hd"><span>校正预览</span></div> <div class="pbadge mtag">校正预览</div>
<div class="pbadge" id="pvPage">1/1</div>
<div class="box" id="pbox"><canvas id="preview"></canvas></div> <div class="box" id="pbox"><canvas id="preview"></canvas></div>
<button class="regen" type="button" style="display:none">重新生成 PDF</button>
</div> </div>
<div class="footbar" id="footbar"> <div class="footbar" id="footbar">
@@ -161,7 +199,10 @@ body{display:flex;flex-direction:column;height:100%;height:100dvh}
<div id="setSheet" class="sheet"> <div id="setSheet" class="sheet">
<div class="card"> <div class="card">
<div class="shd">
<h3>全局设置</h3> <h3>全局设置</h3>
<button id="setCloseX" class="x" type="button" aria-label="关闭">✕</button>
</div>
<p>这四项对整批生效,不影响单页角点。</p> <p>这四项对整批生效,不影响单页角点。</p>
<div class="grp"><div class="gl">纸张</div> <div class="grp"><div class="gl">纸张</div>
<div class="seg" id="seg-paper"> <div class="seg" id="seg-paper">
@@ -192,24 +233,13 @@ body{display:flex;flex-direction:column;height:100%;height:100dvh}
<button data-v="landscape">全部横</button> <button data-v="landscape">全部横</button>
</div> </div>
</div> </div>
<div class="grp"><div class="gl">本页</div>
<div class="seg" id="seg-page">
<button id="moveUp">上移</button>
<button id="moveDown">下移</button>
<button id="delPage">删除/恢复</button>
</div>
</div>
<p id="summary" class="hint"></p>
<div id="warnings" class="hint"></div> <div id="warnings" class="hint"></div>
<div class="row"><button id="pdf" class="pri">下载当前 PDF</button></div>
<div class="row"><button id="setClose" class="pri">完成</button></div> <div class="row"><button id="setClose" class="pri">完成</button></div>
</div> </div>
</div> </div>
<div id="toast"></div> <div id="toast"></div>
<button id="apply" class="fab" title="应用修改并重新生成"><span class="lbl">生成 PDF</span></button>
<script> <script>
"use strict"; "use strict";
var TASK = (location.pathname.split("/").filter(Boolean)[1] || ""); var TASK = (location.pathname.split("/").filter(Boolean)[1] || "");
@@ -229,7 +259,7 @@ var ICON_EYE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strok
var ICON_CROP = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 2v14a2 2 0 0 0 2 2h14"/><path d="M18 22V8a2 2 0 0 0-2-2H2"/></svg>'; var ICON_CROP = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 2v14a2 2 0 0 0 2 2h14"/><path d="M18 22V8a2 2 0 0 0-2-2H2"/></svg>';
/* ---------------------------------------------------------------- 数据 */ /* ---------------------------------------------------------------- 数据 */
var S = {cur: 0, pages: [], batch: null, busy: false}; var S = {cur: 0, pages: [], batch: null, busy: false, savedEdits: null};
function parseJSON(s, d) { function parseJSON(s, d) {
if (!s) return d; if (!s) return d;
@@ -251,8 +281,8 @@ function apiDb(sql, params) {
function paintSummary() { function paintSummary() {
var b = S.batch || {}; var b = S.batch || {};
var el = document.getElementById("summary"); var t = document.getElementById("btitle");
if (el) el.textContent = b.summary || ""; if (t) t.textContent = b.output ? String(b.output).split("/").pop() : "文档审核";
var w = parseJSON(b.warnings, []); var w = parseJSON(b.warnings, []);
var we = document.getElementById("warnings"); var we = document.getElementById("warnings");
if (we) { if (we) {
@@ -269,17 +299,7 @@ function paintSummary() {
} }
} }
var pdf = document.getElementById("pdf"); var pdf = document.getElementById("pdf");
if (pdf) { if (pdf) pdf.disabled = !b.output;
if (b.output) {
pdf.disabled = false;
pdf.dataset.url = "/api/sessions/" + encodeURIComponent(TASK) +
"/files/download?path=" + encodeURIComponent(b.output) +
"&v=" + encodeURIComponent(b.updated_at || Date.now());
} else {
pdf.disabled = true;
pdf.dataset.url = "";
}
}
} }
function loadBatch() { function loadBatch() {
@@ -323,6 +343,7 @@ function loadBatch() {
S.cur = 0; S.cur = 0;
while (S.cur < S.pages.length && S.pages[S.cur].deleted) S.cur++; while (S.cur < S.pages.length && S.pages[S.cur].deleted) S.cur++;
if (S.cur >= S.pages.length) S.cur = 0; if (S.cur >= S.pages.length) S.cur = 0;
S.savedEdits = collect();
paintSummary(); paintSummary();
return S.pages; return S.pages;
}); });
@@ -377,6 +398,7 @@ function save() {
g: G g: G
})); }));
} catch (e) {} } catch (e) {}
updateActions();
} }
/* ---------------------------------------------------------------- 几何 */ /* ---------------------------------------------------------------- 几何 */
@@ -622,7 +644,7 @@ function bindDrag() {
/* 角点优先于翻页按钮:两者可能撞在同一块屏幕上,角点是主操作 */ /* 角点优先于翻页按钮:两者可能撞在同一块屏幕上,角点是主操作 */
function hitHandle(ev) { function hitHandle(ev) {
var p = S.pages[S.cur]; var p = S.pages[S.cur];
if (!p || p.deleted || !p.w || !p.h) return -1; if (S.busy || !p || p.deleted || !p.w || !p.h) return -1;
var r = cvEl.getBoundingClientRect(); var r = cvEl.getBoundingClientRect();
var px = ev.clientX - r.left, py = ev.clientY - r.top; var px = ev.clientX - r.left, py = ev.clientY - r.top;
var best = -1, bestD = HIT_R; var best = -1, bestD = HIT_R;
@@ -636,7 +658,7 @@ function bindDrag() {
function begin(i, ev) { function begin(i, ev) {
var p = S.pages[S.cur]; var p = S.pages[S.cur];
if (!p || p.deleted || !p.w || !p.h) return; if (S.busy || !p || p.deleted || !p.w || !p.h) return;
drag = {i: i, id: ev.pointerId}; drag = {i: i, id: ev.pointerId};
HANDLES[i].classList.add("on"); HANDLES[i].classList.add("on");
showLoupe(i, ev); showLoupe(i, ev);
@@ -645,7 +667,7 @@ function bindDrag() {
function move(ev) { function move(ev) {
if (!drag) return; if (!drag) return;
var p = S.pages[S.cur]; var p = S.pages[S.cur];
if (!p || p.deleted || !p.w || !p.h) return; if (S.busy || !p || p.deleted || !p.w || !p.h) return;
var n = toNorm(ev); var n = toNorm(ev);
/* 允许拖出画面:纸被切掉一块时角点必须在画面外,服务端会外推填白 */ /* 允许拖出画面:纸被切掉一块时角点必须在画面外,服务端会外推填白 */
p.c[drag.i] = [clamp(n[0],-0.35,1.35), clamp(n[1],-0.35,1.35)]; p.c[drag.i] = [clamp(n[0],-0.35,1.35), clamp(n[1],-0.35,1.35)];
@@ -693,6 +715,35 @@ function bindDrag() {
}); });
} }
function bindSwipe() {
var sw = null;
function onDown(ev) {
if (!ev.isPrimary) return;
sw = null;
if (S.busy || drag || ev.pointerType === 'mouse') return;
if (ev.target && ev.target.closest && ev.target.closest('button')) return;
sw = {x: ev.clientX, y: ev.clientY, t: Date.now(), id: ev.pointerId};
}
function onUp(ev) {
if (!sw || sw.id !== ev.pointerId) return;
var dx = ev.clientX - sw.x, dy = ev.clientY - sw.y, dt = Date.now() - sw.t;
sw = null;
if (S.busy || drag) return;
if (dt > 800 || Math.abs(dx) < 45 || Math.abs(dx) < Math.abs(dy) * 1.2) return;
if (dx < 0) step(1); else step(-1);
}
function onCancel() { sw = null; }
['stage', 'prevwrap'].forEach(function(id){
var el = document.getElementById(id);
if (!el) return;
el.addEventListener('pointerdown', onDown, {passive: true});
el.addEventListener('pointerup', onUp, {passive: true});
el.addEventListener('pointercancel', onCancel, {passive: true});
});
document.addEventListener('pointerup', onUp, {passive: true});
document.addEventListener('pointercancel', onCancel, {passive: true});
}
function paintChrome() { function paintChrome() {
if (!S.pages.length) return; if (!S.pages.length) return;
var p = S.pages[S.cur]; var p = S.pages[S.cur];
@@ -705,8 +756,9 @@ function paintChrome() {
else if (p.status === "render_failed") badge = "出页失败"; else if (p.status === "render_failed") badge = "出页失败";
else if (p.status === "failed") badge = "图片不可读"; else if (p.status === "failed") badge = "图片不可读";
if (!badge && !p.img) badge = "图片不可读"; if (!badge && !p.img) badge = "图片不可读";
document.getElementById("cur").textContent = S.cur + 1; var pos = (S.cur + 1) + "/" + S.pages.length;
document.getElementById("total").textContent = S.pages.length; document.getElementById("stagePage").textContent = pos;
document.getElementById("pvPage").textContent = pos;
document.getElementById("name").textContent = p.name + document.getElementById("name").textContent = p.name +
(badge ? "(" + badge + ")" : ""); (badge ? "(" + badge + ")" : "");
document.getElementById("prev").disabled = (S.cur === 0); document.getElementById("prev").disabled = (S.cur === 0);
@@ -722,7 +774,9 @@ function goto(idx) {
} }
function step(delta) { function step(delta) {
goto(S.cur + delta); var i = S.cur;
do { i += delta; } while (i >= 0 && i < S.pages.length && S.pages[i].deleted);
if (i >= 0 && i < S.pages.length) goto(i);
} }
/* ---------------------------------------------------------------- 导出 */ /* ---------------------------------------------------------------- 导出 */
@@ -758,11 +812,27 @@ function collect() {
function setBusy(on) { function setBusy(on) {
S.busy = on; S.busy = on;
var b = document.getElementById("apply"); var st = document.getElementById("stage");
if (!b) return; if (st) st.style.pointerEvents = on ? "none" : "";
b.disabled = on; var gear = document.getElementById("gear");
var l = b.querySelector(".lbl"); if (gear) gear.disabled = on;
if (l) l.textContent = on ? "生成中…" : "生成"; var bs = document.querySelectorAll(".regen");
for (var i = 0; i < bs.length; i++) {
bs[i].disabled = on;
bs[i].textContent = on ? "生成中…" : "重新生成 PDF";
}
}
function updateActions() {
var dirty = false;
if (S.savedEdits) {
try { dirty = JSON.stringify(collect()) !== JSON.stringify(S.savedEdits); } catch (e) {}
}
var bs = document.querySelectorAll(".regen");
for (var i = 0; i < bs.length; i++) {
bs[i].style.display = dirty ? "inline-flex" : "none";
if (!S.busy) bs[i].textContent = "重新生成 PDF";
}
} }
function loadImages() { function loadImages() {
@@ -798,9 +868,35 @@ function reloadAfterApply() {
paintChrome(); paintChrome();
paintSeg(); paintSeg();
layout(); layout();
updateActions();
}); });
} }
// 下载走与文件面板同一条链路:先换签名的 download-name 直链再导航。
// 不要直接导航 /files/download:APK/系统下载器不携带登录 cookie,会拿 401;
// 且 URL 末段是固定的 download,解析不了 Content-Disposition 的下载器只能存成 download.pdf。
function downloadPdf() {
var b = S.batch || {};
if (!b.output) return;
var btn = document.getElementById("pdf");
if (btn.disabled) return;
btn.disabled = true;
fetch("/api/sessions/" + encodeURIComponent(TASK) +
"/files/download-token?path=" + encodeURIComponent(b.output))
.then(function(r){
return r.json().then(function(j){ return {ok: r.ok, body: j}; });
})
.then(function(x){
var j = x.body || {};
if (!x.ok || !j.url) throw new Error(j.error || ("HTTP " + x.status));
window.location.href = j.url;
})
.catch(function(e){
toast("下载失败:" + (e && e.message || e));
})
.then(function(){ btn.disabled = false; });
}
function applyChanges() { function applyChanges() {
if (S.busy) return; if (S.busy) return;
var edits = collect(); var edits = collect();
@@ -841,32 +937,6 @@ function applyChanges() {
}); });
} }
function movePage(delta) {
if (S.busy) return;
var p = S.pages[S.cur];
if (!p) return;
var j = S.cur + delta;
while (j >= 0 && j < S.pages.length && S.pages[j].deleted) j += delta;
if (j < 0 || j >= S.pages.length) return;
S.pages[S.cur] = S.pages[j];
S.pages[j] = p;
S.cur = j;
save();
paintChrome();
toast(delta < 0 ? "已上移" : "已下移");
}
function deletePage() {
if (S.busy) return;
var p = S.pages[S.cur];
if (!p) return;
p.deleted = !p.deleted;
save();
paintChrome();
layout();
toast(p.deleted ? "已标记删除(生成时跳过);再点一次可恢复" : "已恢复本页");
}
function toast(msg) { function toast(msg) {
var t = document.getElementById("toast"); var t = document.getElementById("toast");
t.textContent = msg; t.textContent = msg;
@@ -875,16 +945,21 @@ function toast(msg) {
} }
function closeSheet() {
document.getElementById("setSheet").classList.remove("on");
drawPreview();
}
/* ---------------------------------------------------------------- 启动 */ /* ---------------------------------------------------------------- 启动 */
function boot() { function boot() {
/* 手机上先看校正预览:打开链接第一眼就是成品效果;点左上角再切到裁切。 */ /* 手机上先看校正预览:打开链接第一眼就是成品效果;点左上角再切到裁切。 */
var mobile = window.matchMedia("(max-width:899.98px)").matches; var mobile = window.matchMedia("(max-width:899.98px)").matches;
if (mobile) document.body.classList.add("view-prev"); if (mobile) document.body.classList.add("view-prev");
document.getElementById("total").textContent = S.pages.length;
loadImages(); loadImages();
cv = document.getElementById("photo"); cv = document.getElementById("photo");
bindDrag(); bindDrag();
bindSwipe();
paintChrome(); paintChrome();
paintSeg(); paintSeg();
layout(); layout();
@@ -894,10 +969,8 @@ function boot() {
paintSeg(); paintSeg();
document.getElementById("setSheet").classList.add("on"); document.getElementById("setSheet").classList.add("on");
}; };
document.getElementById("setClose").onclick = function(){ document.getElementById("setClose").onclick = closeSheet;
document.getElementById("setSheet").classList.remove("on"); document.getElementById("setCloseX").onclick = closeSheet;
drawPreview();
};
document.getElementById("setSheet").onclick = function(e){ document.getElementById("setSheet").onclick = function(e){
if (e.target === this) this.classList.remove("on"); if (e.target === this) this.classList.remove("on");
}; };
@@ -915,11 +988,14 @@ function boot() {
}); });
/* --- 移动端:原图 / 预览 二选一,按钮在左上角。桌面端两个都显示,按钮隐藏 --- */ /* --- 移动端:原图 / 预览 二选一,按钮在左上角。桌面端两个都显示,按钮隐藏 --- */
/* 当前模式不做成按钮状态:两个面板各自的左上角常驻标签(手动定位 / 校正预览),
移动端一次只显示一个,看到哪个就是当前模式。 */
var viewBtn = document.getElementById("view"); var viewBtn = document.getElementById("view");
if (mobile) viewBtn.innerHTML = ICON_CROP; var viewIcon = document.getElementById("viewIcon");
viewIcon.innerHTML = mobile ? ICON_CROP : ICON_EYE;
viewBtn.onclick = function(){ viewBtn.onclick = function(){
var on = document.body.classList.toggle("view-prev"); var prev = document.body.classList.toggle("view-prev");
viewBtn.innerHTML = on ? ICON_CROP : ICON_EYE; viewIcon.innerHTML = prev ? ICON_CROP : ICON_EYE;
setTimeout(function(){ layout(); drawPreview(); }, 40); setTimeout(function(){ layout(); drawPreview(); }, 40);
}; };
@@ -928,16 +1004,15 @@ function boot() {
document.getElementById("navPrev").onclick = function(){ step(-1); }; document.getElementById("navPrev").onclick = function(){ step(-1); };
document.getElementById("navNext").onclick = function(){ step(1); }; document.getElementById("navNext").onclick = function(){ step(1); };
document.getElementById("apply").onclick = applyChanges; var regens = document.querySelectorAll(".regen");
document.getElementById("moveUp").onclick = function(){ movePage(-1); }; for (var i = 0; i < regens.length; i++) regens[i].onclick = applyChanges;
document.getElementById("moveDown").onclick = function(){ movePage(1); }; document.getElementById("back").onclick = function(){
document.getElementById("delPage").onclick = deletePage; location.href = TASK ? ("/?s=" + encodeURIComponent(TASK)) : "/";
document.getElementById("pdf").onclick = function(){
var u = this.dataset.url;
if (u) window.location.href = u;
}; };
document.getElementById("pdf").onclick = downloadPdf;
document.getElementById("rot").onclick = function(){ document.getElementById("rot").onclick = function(){
if (S.busy) return;
var p = S.pages[S.cur]; var p = S.pages[S.cur];
if (!p || p.deleted) return; if (!p || p.deleted) return;
p.r = (p.r + 90) % 360; p.r = (p.r + 90) % 360;
@@ -947,6 +1022,7 @@ function boot() {
}; };
document.getElementById("reset").onclick = function(){ document.getElementById("reset").onclick = function(){
if (S.busy) return;
var p = S.pages[S.cur]; var p = S.pages[S.cur];
if (!p || p.deleted) return; if (!p || p.deleted) return;
p.c = p.base.map(function(v){ return [v[0], v[1]]; }); p.c = p.base.map(function(v){ return [v[0], v[1]]; });
@@ -962,6 +1038,7 @@ function boot() {
/* 兜底:首帧 stage 量到 0 时 layout 会直接返回,稍后再来一次 */ /* 兜底:首帧 stage 量到 0 时 layout 会直接返回,稍后再来一次 */
setTimeout(layout, 80); setTimeout(layout, 80);
if (document.fonts && document.fonts.ready) document.fonts.ready.then(layout); if (document.fonts && document.fonts.ready) document.fonts.ready.then(layout);
updateActions();
} }
function start() { function start() {