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)), "已下线该会话"); + }) ); }