修复前端

This commit is contained in:
dekun
2026-05-22 11:29:34 +08:00
parent 371dec6999
commit 427f94e0e8
4 changed files with 246 additions and 114 deletions
+22 -3
View File
@@ -294,15 +294,34 @@
}
}
async function parseJsonResponse(r) {
const text = await r.text();
if (!text) return {};
try {
return JSON.parse(text);
} catch (e) {
const snippet = text.slice(0, 200);
throw new Error(
`HTTP ${r.status} 响应不是 JSON${snippet}${text.length > 200 ? "…" : ""}`
);
}
}
async function submitForm(path, formEl) {
const id = document.getElementById("trade-account").value;
const fd = new FormData(formEl);
try {
const r = await fetch(path + encodeURIComponent(id), { method: "POST", body: fd });
const j = await r.json();
const j = await parseJsonResponse(r);
const res = j.result || {};
const msgs = (res.messages || []).join("\n") || JSON.stringify(res, null, 2);
showToast(msgs, !res.ok);
const msgs =
(res.messages || []).join("\n") ||
res.error ||
res.msg ||
res.text ||
JSON.stringify(res, null, 2);
const failed = res.ok === false || r.status >= 400 || !!res.error || !!res.text;
showToast(msgs || (failed ? "操作失败" : "已提交"), failed);
if (res.ok && res.preview) {
showTrendPreview(res);
}