新增配置页一键清除并保留 DeepSeek 密钥

This commit is contained in:
2026-11-27 16:36:31 +08:00
parent 6b9683dcf9
commit bc912141ea
8 changed files with 220 additions and 48 deletions
+74 -24
View File
@@ -14,6 +14,8 @@
--tint: #e5f0e8;
--line: #cbd7ce;
--alert: #863c15;
--danger: #9a342b;
--danger-tint: #f7e9e6;
font: 16px/1.55 system-ui, "Microsoft YaHei", "PingFang SC", sans-serif;
color: var(--ink);
background: #e8ede6;
@@ -177,6 +179,9 @@
background: var(--green);
}
.action.danger { color: var(--danger); background: var(--danger-tint); }
.action.primary.danger { color: #fff; background: var(--danger); }
.action[aria-disabled="true"] {
color: #fff;
background: #668b7a;
@@ -425,6 +430,10 @@
</div>
</div>
<button type="button" class="action primary" id="save-preview">保存配置</button>
<div class="card" style="margin-top: 12px">
<h3>本机数据</h3>
<button type="button" class="action danger" id="reset-preview">一键清除所有已保存数据</button>
</div>
<p id="library-status" role="status" hidden></p>
</div>
<nav class="app-nav" aria-label="配置页导航">
@@ -442,7 +451,8 @@
<div class="phone-content">
<div class="card">
<h3>运行日志</h3>
<ul class="entries">
<p id="empty-log" hidden>启动任务后会在这里显示运行步骤。</p>
<ul class="entries" id="log-entries">
<li><time datetime="2026-11-26T12:56:05+08:00">11-26 12:56:05</time> 运行 任务完成 · 处理 1 条 · 确认发送 1 条</li>
<li><time datetime="2026-11-26T12:56:05+08:00">11-26 12:56:05</time> 运行 第 1 条视频已确认 1/1 条回复</li>
<li class="warning"><time datetime="2026-11-25T15:22:14+08:00">11-25 15:22:14</time> 异常 抖音评论未回读到完整内容或未看到唯一发送按钮</li>
@@ -483,6 +493,14 @@
<button type="button" class="action primary" id="delete-confirm">删除</button>
</div>
</dialog>
<dialog id="reset-dialog" aria-labelledby="reset-title" aria-describedby="reset-message">
<h2 id="reset-title">清除所有已保存数据?</h2>
<p id="reset-message">将清除拾见本机保存的配置、内容库、绑定图片、任务检查点和运行日志。DeepSeek 密钥会保留。清除后恢复默认设置,此操作无法撤销。</p>
<div class="library-actions">
<button type="button" class="action" id="reset-cancel" autofocus>取消</button>
<button type="button" class="action primary danger" id="reset-confirm">清除数据</button>
</div>
</dialog>
<script>
const byId = id => document.getElementById(id);
const scope = byId("search-scope");
@@ -495,6 +513,7 @@
const phrasePicker = byId("reply-phrase");
const editDialog = byId("library-editor");
const deleteDialog = byId("library-delete");
const resetDialog = byId("reset-dialog");
const singleLine = byId("library-value");
const multiLine = byId("library-phrase-text");
const editError = byId("library-error");
@@ -700,33 +719,64 @@
for (const picker of [platformPicker, replyMode, bilibiliScope]) {
picker.addEventListener("change", updateCommentSettings);
}
byId("save-preview").addEventListener("click", () => {
function updateTaskPreview() {
const platform = platformPicker.selectedOptions[0];
const unit = platform.dataset.unit;
const limit = byId("video-limit").valueAsNumber;
const selectedType = pick(types, scope);
const searchTypes = selectedType ? [selectedType] : types;
const type = byId("task-content-type");
const progress = byId("task-progress");
const modeLabel = bilibiliScopeField.hidden ? replyMode.value : bilibiliScope.selectedOptions[0].text;
const confirmedLabel = !bilibiliScopeField.hidden && bilibiliScope.value === "VIDEO_COMMENT" ? "已确认发布评论" : "已确认回复";
byId("task-mode").textContent = `${platform.text} · ${modeLabel}`;
byId("task-scope").textContent = `内容类型 ${searchTypes.length} 个 · 单次 ${limit} 个${unit}`;
byId("task-summary").textContent = `已处理${unit} 0 / ${limit} · ${confirmedLabel} 0 条`;
progress.max = limit;
progress.value = 0;
progress.setAttribute("aria-label", `已处理 0 个${unit},共 ${limit} 个`);
type.hidden = searchTypes.length === 0;
type.textContent = searchTypes.length ? `内容类型 · ${searchTypes[0].name}` : "";
}
function showConfigStatus(message, invalid) {
const status = byId("library-status");
const invalid = [byId("video-limit"), byId("replies-per-video")].find(input => !input.validity.valid);
const error = invalid ? `${invalid.labels[0].textContent}须为 1–100 的整数。` : "";
if (!error) {
const platform = platformPicker.selectedOptions[0];
const unit = platform.dataset.unit;
const limit = byId("video-limit").valueAsNumber;
const selectedType = pick(types, scope);
const searchTypes = selectedType ? [selectedType] : types;
const type = byId("task-content-type");
const progress = byId("task-progress");
const modeLabel = bilibiliScopeField.hidden ? replyMode.value : bilibiliScope.selectedOptions[0].text;
const confirmedLabel = !bilibiliScopeField.hidden && bilibiliScope.value === "VIDEO_COMMENT" ? "已确认发布评论" : "已确认回复";
byId("task-mode").textContent = `${platform.text} · ${modeLabel}`;
byId("task-scope").textContent = `内容类型 ${searchTypes.length} 个 · 单次 ${limit} 个${unit}`;
byId("task-summary").textContent = `已处理${unit} 0 / ${limit} · ${confirmedLabel} 0 条`;
progress.max = limit;
progress.setAttribute("aria-label", `已处理 0 个${unit},共 ${limit} 个`);
type.hidden = searchTypes.length === 0;
type.textContent = searchTypes.length ? `内容类型 · ${searchTypes[0].name}` : "";
}
status.textContent = error || "预览配置已更新。";
status.classList.toggle("error", Boolean(error));
status.textContent = message;
status.classList.toggle("error", Boolean(invalid));
status.hidden = false;
invalid?.focus({ preventScroll: true });
status.scrollIntoView({ block: "nearest", inline: "nearest" });
}
byId("save-preview").addEventListener("click", () => {
const invalid = [byId("video-limit"), byId("replies-per-video")].find(input => !input.validity.valid);
if (!invalid) updateTaskPreview();
showConfigStatus(invalid ? `${invalid.labels[0].textContent}须为 1–100 的整数。` : "预览配置已更新。", invalid);
});
byId("reset-preview").addEventListener("click", () => resetDialog.showModal());
byId("reset-cancel").addEventListener("click", () => resetDialog.close());
byId("reset-confirm").addEventListener("click", () => {
for (const type of types) {
for (const rule of type.rules) {
for (const phrase of rule.phrases) phrase.photos.forEach(photo => URL.revokeObjectURL(photo.url));
}
}
types.length = 0;
nextId = 0;
editing = deleting = photoTarget = undefined;
singleLine.value = multiLine.value = fileInput.value = "";
for (const picker of [platformPicker, replyMode, bilibiliScope, scope]) picker.selectedIndex = 0;
for (const input of [byId("video-limit"), byId("replies-per-video")]) input.value = input.defaultValue;
const pending = byId("pending-receipt-preview");
pending.open = false;
pending.hidden = true;
byId("log-entries").replaceChildren();
byId("log-entries").hidden = true;
byId("empty-log").hidden = false;
resetDialog.close();
setStatus();
updateCommentSettings();
redrawLibrary();
updateTaskPreview();
showConfigStatus("已清除所有已保存数据。");
});
updateCommentSettings();
redrawLibrary();