fix:优化工作面板,支持动态字数

This commit is contained in:
Daniel
2026-04-21 13:14:53 +08:00
parent e69666dbb3
commit d76c7fa25a
6 changed files with 159 additions and 26 deletions

View File

@@ -17,6 +17,15 @@ const wechatBtn = $("wechatBtn");
const imBtn = $("imBtn");
const coverUploadBtn = $("coverUploadBtn");
const logoutBtn = $("logoutBtn");
const targetBodyCharsInput = $("targetBodyChars");
function syncTargetCharChips() {
const val = Number((targetBodyCharsInput && targetBodyCharsInput.value) || 0);
document.querySelectorAll(".target-char-chip").forEach((btn) => {
const n = Number(btn.getAttribute("data-target-chars") || 0);
btn.classList.toggle("is-active", Number.isFinite(val) && val === n);
});
}
function countText(v) {
return (v || "").trim().length;
@@ -183,12 +192,30 @@ if (logoutBtn) {
});
}
document.querySelectorAll(".target-char-chip").forEach((btn) => {
btn.addEventListener("click", () => {
const n = Number(btn.getAttribute("data-target-chars") || 0);
if (!targetBodyCharsInput || !Number.isFinite(n) || n < 1) return;
targetBodyCharsInput.value = String(n);
syncTargetCharChips();
});
});
if (targetBodyCharsInput) {
targetBodyCharsInput.addEventListener("input", syncTargetCharChips);
}
$("rewriteBtn").addEventListener("click", async () => {
const sourceText = $("sourceText").value.trim();
const targetBodyChars = Number(($("targetBodyChars") && $("targetBodyChars").value) || 500);
if (sourceText.length < 20) {
setStatus("原始内容太短,至少 20 个字符", true);
return;
}
if (!Number.isFinite(targetBodyChars) || targetBodyChars < 180 || targetBodyChars > 2200) {
setStatus("改写目标字数需在 180~2200 之间", true);
return;
}
setStatus("正在改写...");
setLoading(rewriteBtn, true, "改写并排版", "改写中...");
@@ -202,6 +229,7 @@ $("rewriteBtn").addEventListener("click", async () => {
audience,
keep_points: $("keepPoints").value,
avoid_words: $("avoidWords").value,
target_body_chars: Math.round(targetBodyChars),
});
$("title").value = data.title || "";
$("summary").value = data.summary || "";
@@ -307,3 +335,4 @@ $("imBtn").addEventListener("click", async () => {
updateCounters();
initMultiDropdowns();
initWechatAccountSwitch();
syncTargetCharChips();