From 898974bcfe80b036b0f3bbcc95a141c196c0864a Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Wed, 4 Nov 2026 01:59:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E5=A4=8D=E5=AE=A1=20P1=20=E5=9B=9B?= =?UTF-8?q?=E8=BF=9E=E4=BF=AE=E2=80=94=E2=80=94=E7=9C=8B=E6=9D=BF=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E9=97=A8=E9=94=99=E4=BD=8D/=E5=BD=95=E5=85=A5?= =?UTF-8?q?=E9=A1=B5=E6=9D=83=E9=99=90=E6=AD=BB=E8=B7=AF/=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=E5=8A=A0=E8=BD=BD=E5=8D=A1=E6=AD=BB/=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E4=B8=8B=E7=BA=BF=E7=BC=BA=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ① 看板「导出 Excel」按钮原来挂 canR("board"),但 /export/updates 权限归「自研产品」 (EXPORT_MENU),只有看板权限的账号点了必 403。门改 canR("projects") + title 说明。 ② download() 重写为 fetch+blob:403/500/401 的 JSON 错误改 toast 报出(401 直接弹回登录), 不再用同标签页 跳转把整个 SPA 顶成 JSON 错误页;文件名解析 Content-Disposition 的 UTF-8'' 段。 ③ 只有「更新录入」权限的账号录入页死路修复:无自研读权限时 intakeType 强制走定制 tab, seg 的自研按钮渲染为 disabled+原因 title(intakeTypeSegHtml 助手,两处 seg 模板合并为一个); 定制抽屉「添加交付记录」按 canW(custom)||canW(intake)(POST /custom/updates 走 assist max 口径)、 「AI 录入」按 can(intake)(没菜单跳了也白跳)。 ④ 在线会话「下线这个会话」补 confirmDialog({danger:true}),与用户页强制下线同款; 此前 commit message 宣称的一致其实没做(cf0f3a1 只改了用户页)。 ⑤ openCustomDrawer / openDrawer 初始加载包 try/catch → 抽屉体内渲染「加载失败」, 不再永久卡在「加载中…+遮罩关不掉」;与 openFocusDrawer 1520-1545 同模板。 node --check 通过;pytest 93 passed 不受影响(纯前端)。 --- web/app.js | 82 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/web/app.js b/web/app.js index 492040e..b54519b 100644 --- a/web/app.js +++ b/web/app.js @@ -592,14 +592,29 @@ } /** 触发浏览器下载(导出 Excel) */ - function download(url) { - const a = document.createElement("a"); - a.href = url; - a.style.display = "none"; - document.body.appendChild(a); - a.click(); - setTimeout(() => a.remove(), 1000); + /** + * 导出下载统一走 fetch+blob:403/500/会话过期的 JSON 错误用 toast 报出, + * 不再用 同标签跳转把整个 SPA 顶成错误页(看板导出按钮曾因此丢界面)。 + */ + async function download(url) { toast("正在生成 Excel,请稍候…"); + try { + const res = await fetch(url, { credentials: "same-origin" }); + if (!res.ok) { + let msg = "导出失败(HTTP " + res.status + ")"; + try { const d = (await res.json()).detail; if (d) msg = "导出失败:" + d; } catch (e) { /* 非 JSON 错误体 */ } + if (res.status === 401) showAuthGate(msg); + return toast(msg); + } + const cd = res.headers.get("Content-Disposition") || ""; + const m = /filename\*=UTF-8''([^;]+)/i.exec(cd); + const a = document.createElement("a"); + a.href = URL.createObjectURL(await res.blob()); + a.download = m ? decodeURIComponent(m[1]) : "export.xlsx"; + document.body.appendChild(a); + a.click(); + setTimeout(() => { URL.revokeObjectURL(a.href); a.remove(); }, 2000); + } catch (e) { toast("导出失败:" + e.message); } } /** @@ -1251,7 +1266,7 @@ ${state.staff.map((s) => ``).join("")} - ${canR("board") ? `` : ""} + ${canR("projects") ? `` : ""} `; host.innerHTML = kpi + toolbar + ` @@ -2448,7 +2463,13 @@ $("#drawer").classList.add("open"); $("#drawerBody").innerHTML = `
加载中…
`; drawerActions(""); - const d = await api("/custom/projects/" + cid); + let d; + try { // 取不到数据必须落回可关闭的抽屉,不能永远停在「加载中…」(与重点抽屉同款) + d = await api("/custom/projects/" + cid); + } catch (e) { + $("#drawerBody").innerHTML = `
加载失败:${esc(e.message)}
`; + return; + } const p = d.project; $("#drawerTitle").innerHTML = `${p.is_key ? starMark(true) : ""}${esc(p.name)}${p.archived ? ` 已归档` : ""}`; const progPct = (p.project_status === "进行中" || Number(p.progress || 0) > 0) ? Math.round(p.progress || 0) + "%" : null; @@ -2543,8 +2564,8 @@
交付记录(${d.updates.length})
- - + ${(canW("custom") || canW("intake")) ? `` : ""} + ${can("intake") ? `` : ""}
${d.updates.length ? d.updates.map((u) => updateItem(u, "custom")).join("") : `
暂无交付记录
`}
@@ -2649,10 +2670,7 @@ const projects = await api("/custom/projects"); host.innerHTML = ` -
- - -
+ ${intakeTypeSegHtml()}
${cardHead({ title: "定制项目 · 交付记录录入", tools: canW("custom") ? `` : "" })}
@@ -2831,6 +2849,18 @@ /* ---------------------------------------------------------------- 更新录入 */ let intakeProjectId = null; + /** 自研/定制 tab:无「自研产品」读权限的账号(如仅「更新录入」)不给可点的自研按钮, + * 否则点一次 403 会把整页刷成加载失败,连定制录入都到不了 */ + function intakeTypeSegHtml() { + const general = canR("projects") + ? `` + : ``; + return `
+ ${general} + +
`; + } + async function renderIntake() { saveUI(); // 自研/定制 tab、写入模式等页内选择也要跨刷新记忆(与其他视图同套路) const host = $("#view-intake"); @@ -2840,15 +2870,14 @@ return; } if (!state.customMeta) state.customMeta = await api("/custom/meta"); + // 无自研读权限时强制走定制 tab(跨菜单放行只覆盖定制三接口) + if (state.intakeType !== "custom" && !canR("projects")) state.intakeType = "custom"; if (state.intakeType === "custom") return renderCustomIntake(host); const projects = await api("/projects?archived=false"); host.innerHTML = ` -
- - -
+ ${intakeTypeSegHtml()}
${cardHead({ title: "自研产品 · 执行记录录入" })}
@@ -3129,7 +3158,13 @@ $("#drawer").classList.add("open"); $("#drawerBody").innerHTML = `
加载中…
`; drawerActions(""); - let d = await api("/projects/" + pid); + let d; + try { // 同上:加载失败给可见错误态,不留永动「加载中…」 + d = await api("/projects/" + pid); + } catch (e) { + $("#drawerBody").innerHTML = `
加载失败:${esc(e.message)}
`; + return; + } // 弹窗里改完记录,只重画下面的周期反馈,抽屉不关闭、滚动位置不丢 const reloadFeed = async () => { d = await api("/projects/" + pid); @@ -3761,7 +3796,12 @@ function bindRbacSessions(host, rw, save) { if (!rw) return; host.querySelectorAll("[data-kick]").forEach((b) => - b.addEventListener("click", () => save(() => del("/rbac/sessions/" + encodeURIComponent(b.dataset.kick)), "已下线该会话")) + b.addEventListener("click", async () => { + // 与用户页「强制下线」同款确认(危险动作一律先确认) + const ok = await confirmDialog({ title: "强制下线", danger: true, okText: "确认下线", + body: `

只下线这一个登录会话,对应设备需要重新登录;该账号的其他登录不受影响。

` }); + if (ok) save(() => del("/rbac/sessions/" + encodeURIComponent(b.dataset.kick)), "已下线该会话"); + }) ); }