Add content type rules, reply quotas, and multi-image templates. Verify published replies in the original comment thread and record automatic receipts. Document uninterrupted physical-device acceptance.
674 lines
29 KiB
HTML
674 lines
29 KiB
HTML
<!doctype html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<meta name="color-scheme" content="light">
|
||
<title>拾见 · 界面预览</title>
|
||
<style>
|
||
:root {
|
||
--ink: #172a24;
|
||
--muted: #4e6358;
|
||
--green: #076c53;
|
||
--screen: #f3f5f0;
|
||
--tint: #e5f0e8;
|
||
--line: #cbd7ce;
|
||
--alert: #863c15;
|
||
font: 16px/1.55 system-ui, "Microsoft YaHei", "PingFang SC", sans-serif;
|
||
color: var(--ink);
|
||
background: #e8ede6;
|
||
}
|
||
|
||
* { box-sizing: border-box; }
|
||
body { margin: 0; }
|
||
a { color: inherit; }
|
||
a:focus-visible, [tabindex]:focus-visible {
|
||
outline: 2px solid var(--green);
|
||
outline-offset: 3px;
|
||
}
|
||
|
||
.preview {
|
||
max-width: 1312px;
|
||
margin-inline: auto;
|
||
padding: 42px clamp(20px, 4vw, 56px) 48px;
|
||
}
|
||
|
||
.preview-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
margin-bottom: 32px;
|
||
}
|
||
|
||
.mark {
|
||
display: grid;
|
||
place-content: center;
|
||
justify-items: center;
|
||
flex: 0 0 52px;
|
||
height: 52px;
|
||
gap: 5px;
|
||
border-radius: 14px;
|
||
background: var(--green);
|
||
}
|
||
|
||
.mark i { height: 4px; background: var(--screen); }
|
||
.mark i:nth-child(1) { width: 28px; }
|
||
.mark i:nth-child(2) { width: 20px; }
|
||
.mark i:nth-child(3) { width: 12px; }
|
||
|
||
h1, h2, h3, p { margin: 0; }
|
||
h1 { font-size: clamp(26px, 4vw, 38px); font-weight: 740; line-height: 1.15; }
|
||
.preview-header p { margin-top: 7px; color: var(--muted); font-size: 14px; }
|
||
|
||
.screen-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||
gap: clamp(16px, 2.15vw, 30px);
|
||
align-items: start;
|
||
}
|
||
|
||
.screen-figure {
|
||
display: grid;
|
||
gap: 9px;
|
||
margin: 0;
|
||
min-width: 0;
|
||
scroll-margin-top: 18px;
|
||
}
|
||
|
||
.screen-figure figcaption { padding-inline: 8px; font-size: 16px; font-weight: 700; }
|
||
.screen-figure:target .phone { border-color: var(--green); }
|
||
|
||
.phone {
|
||
display: grid;
|
||
grid-template-rows: auto minmax(0, 1fr) auto;
|
||
min-width: 0;
|
||
height: 735px;
|
||
overflow: hidden;
|
||
border: 1px solid #aebfb2;
|
||
border-radius: 26px;
|
||
background: var(--screen);
|
||
box-shadow: 0 12px 28px #172a2411;
|
||
}
|
||
|
||
.app-name {
|
||
padding: 21px 20px 8px;
|
||
font-size: 30px;
|
||
font-weight: 740;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.phone-content {
|
||
overflow: auto;
|
||
padding: 6px 17px 8px;
|
||
scrollbar-color: #a9c2b2 transparent;
|
||
scrollbar-width: thin;
|
||
}
|
||
|
||
.card {
|
||
margin-bottom: 12px;
|
||
padding: 12px 16px 14px;
|
||
border-radius: 18px;
|
||
background: #fff;
|
||
}
|
||
|
||
.card h3 { margin-bottom: 4px; font-size: 19px; line-height: 1.45; }
|
||
.card p { margin-top: 6px; font-size: 14px; }
|
||
.card .mode { font-size: 15px; }
|
||
.hint, .summary { color: var(--muted); }
|
||
|
||
progress {
|
||
display: block;
|
||
width: 100%;
|
||
height: 4px;
|
||
margin: 12px 0 8px;
|
||
appearance: none;
|
||
overflow: hidden;
|
||
border: 0;
|
||
border-radius: 4px;
|
||
background: var(--tint);
|
||
}
|
||
progress::-webkit-progress-bar { background: var(--tint); }
|
||
progress::-webkit-progress-value { background: var(--green); }
|
||
progress::-moz-progress-bar { background: var(--green); }
|
||
|
||
.action, .app-nav a {
|
||
display: grid;
|
||
place-items: center;
|
||
min-height: 46px;
|
||
padding: 6px 10px;
|
||
border-radius: 12px;
|
||
background: var(--tint);
|
||
color: var(--green);
|
||
font-size: 15px;
|
||
font-weight: 650;
|
||
text-align: center;
|
||
text-decoration: none;
|
||
}
|
||
|
||
.action {
|
||
width: 100%;
|
||
margin-top: 7px;
|
||
}
|
||
|
||
[hidden] { display: none !important; }
|
||
button.action { border: 0; cursor: pointer; }
|
||
button.action:disabled { opacity: .48; cursor: default; }
|
||
#photo-items { display: grid; gap: 10px; margin-top: 8px; }
|
||
.photo-item img { display: block; width: 96px; height: 76px; object-fit: contain; }
|
||
.library-actions, .photo-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
|
||
.library-level { margin-top: 14px; }
|
||
.library-level label { display: block; margin-bottom: 4px; font-size: 14px; font-weight: 700; }
|
||
#photo-binding { margin-top: 14px; }
|
||
dialog {
|
||
width: min(390px, calc(100% - 32px));
|
||
padding: 20px;
|
||
border: 1px solid var(--line);
|
||
border-radius: 18px;
|
||
color: var(--ink);
|
||
}
|
||
dialog::backdrop { background: #172a2460; }
|
||
dialog h2 { margin-bottom: 12px; font-size: 20px; }
|
||
dialog .library-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; }
|
||
#library-status { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
|
||
#library-error, #library-status.error { color: var(--alert); font-size: 14px; }
|
||
|
||
.action.primary, .app-nav [aria-current="page"] {
|
||
color: #fff;
|
||
background: var(--green);
|
||
}
|
||
|
||
.action[aria-disabled="true"] {
|
||
color: #fff;
|
||
background: #668b7a;
|
||
}
|
||
|
||
.app-nav {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||
gap: 4px;
|
||
padding: 7px 16px 12px;
|
||
}
|
||
|
||
.app-nav a:hover { box-shadow: inset 0 0 0 1px var(--green); }
|
||
|
||
.fields {
|
||
display: grid;
|
||
gap: 10px;
|
||
margin: 7px 0 0;
|
||
}
|
||
|
||
.fields dt { margin-bottom: 3px; font-size: 14px; font-weight: 700; }
|
||
.fields dd { margin: 0; }
|
||
|
||
.control {
|
||
display: flex;
|
||
align-items: center;
|
||
min-height: 42px;
|
||
padding: 8px 11px;
|
||
border-radius: 9px;
|
||
background: var(--screen);
|
||
font-size: 15px;
|
||
overflow-wrap: anywhere;
|
||
}
|
||
|
||
.select { justify-content: space-between; gap: 9px; }
|
||
.select::after {
|
||
content: "";
|
||
width: 7px;
|
||
height: 7px;
|
||
flex: 0 0 7px;
|
||
margin: -4px 2px 0 0;
|
||
transform: rotate(45deg);
|
||
border-right: 1.5px solid currentColor;
|
||
border-bottom: 1.5px solid currentColor;
|
||
}
|
||
.multiline { min-height: 60px; align-items: start; }
|
||
.settings-input {
|
||
display: block;
|
||
width: 100%;
|
||
border: 0;
|
||
color: inherit;
|
||
font: inherit;
|
||
font-size: 15px;
|
||
}
|
||
.settings-input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
|
||
textarea.settings-input { resize: vertical; }
|
||
.range {
|
||
display: grid;
|
||
grid-template-columns: 1fr auto 1fr;
|
||
align-items: center;
|
||
gap: 8px;
|
||
font-size: 14px;
|
||
}
|
||
|
||
code { font-size: .92em; overflow-wrap: anywhere; }
|
||
|
||
.entries {
|
||
display: grid;
|
||
gap: 7px;
|
||
margin: 8px 0 0;
|
||
padding: 0;
|
||
list-style: none;
|
||
font-size: 14px;
|
||
overflow-wrap: anywhere;
|
||
}
|
||
.entries li { padding: 0 0 7px; border-bottom: 1px solid var(--line); }
|
||
.entries li:last-child { padding-bottom: 0; border-bottom: 0; }
|
||
.entries time { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
|
||
.entries .warning { color: var(--alert); }
|
||
|
||
@media (max-width: 970px) {
|
||
.screen-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||
}
|
||
|
||
@media (max-width: 610px) {
|
||
.preview { max-width: 442px; padding-top: 25px; }
|
||
.preview-header { gap: 12px; margin-bottom: 22px; }
|
||
.mark { flex-basis: 44px; height: 44px; border-radius: 12px; }
|
||
.screen-grid { grid-template-columns: 1fr; gap: 26px; }
|
||
.phone { height: min(735px, max(530px, 80svh)); }
|
||
}
|
||
|
||
@media print {
|
||
:root { background: #fff; }
|
||
.preview { padding: 0; }
|
||
.screen-grid { display: block; }
|
||
.screen-figure { margin-bottom: 20px; }
|
||
.phone { height: auto; overflow: visible; box-shadow: none; }
|
||
.phone-content { overflow: visible; }
|
||
.card { break-inside: avoid; border: 1px solid var(--line); }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<main class="preview">
|
||
<header class="preview-header">
|
||
<span class="mark" aria-hidden="true"><i></i><i></i><i></i></span>
|
||
<div>
|
||
<h1>拾见 · 界面预览</h1>
|
||
<p>离线预览,可编辑内容库并试用图片绑定。修改仅在本页保留。</p>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="screen-grid">
|
||
<figure class="screen-figure" id="task">
|
||
<figcaption>任务</figcaption>
|
||
<section class="phone" aria-label="拾见任务页">
|
||
<h2 class="app-name">拾见</h2>
|
||
<div class="phone-content">
|
||
<div class="card">
|
||
<h3>准备运行</h3>
|
||
<p class="mode">抖音 · 仅浏览</p>
|
||
<p>内容类型 1 个 · 单次 3 个视频</p>
|
||
<progress value="0" max="3" aria-label="已处理 0 个视频,共 3 个"></progress>
|
||
<p class="summary">已处理视频 0 / 3 · 已确认回复 0 条</p>
|
||
<p>内容类型 · 模型服务</p>
|
||
</div>
|
||
<div class="card">
|
||
<h3>无障碍服务未连接</h3>
|
||
<p>在系统设置中开启「拾见任务服务」,然后返回这里。</p>
|
||
<span class="action primary">打开无障碍设置</span>
|
||
</div>
|
||
<span class="action primary" aria-disabled="true">开始任务</span>
|
||
<span class="action">启用通知栏暂停按钮</span>
|
||
<details class="card" id="pending-receipt-preview">
|
||
<summary>等待核对状态</summary>
|
||
<p>到抖音核对这条评论</p>
|
||
<span class="action primary">自动核对回复</span>
|
||
<span class="action primary">确认已发送</span>
|
||
<span class="action">跳过此回复</span>
|
||
</details>
|
||
</div>
|
||
<nav class="app-nav" aria-label="任务页导航">
|
||
<a href="#task" aria-current="page">任务</a>
|
||
<a href="#settings">配置</a>
|
||
<a href="#logs">日志</a>
|
||
</nav>
|
||
</section>
|
||
</figure>
|
||
|
||
<figure class="screen-figure" id="settings">
|
||
<figcaption>配置</figcaption>
|
||
<section class="phone" aria-label="拾见配置页">
|
||
<h2 class="app-name">拾见</h2>
|
||
<div class="phone-content" tabindex="0" role="region" aria-label="可滚动的配置预览">
|
||
<div class="card">
|
||
<h3>任务范围</h3>
|
||
<dl class="fields">
|
||
<div><dt>平台</dt><dd class="control select">抖音</dd></div>
|
||
<div><dt><label for="search-scope">搜索范围</label></dt><dd><select id="search-scope" class="control settings-input"></select></dd></div>
|
||
<div><dt><label for="video-limit">单次任务视频上限</label></dt><dd><input id="video-limit" class="control settings-input" type="number" inputmode="numeric" min="1" max="100" value="3" required></dd></div>
|
||
</dl>
|
||
</div>
|
||
<div class="card">
|
||
<h3>动作节奏</h3>
|
||
<dl class="fields">
|
||
<div>
|
||
<dt>观看时长(秒)</dt>
|
||
<dd class="range"><span class="control">5</span><span>至</span><span class="control">12</span></dd>
|
||
</div>
|
||
<div>
|
||
<dt>动作间隔(毫秒)</dt>
|
||
<dd class="range"><span class="control">600</span><span>至</span><span class="control">1800</span></dd>
|
||
</div>
|
||
</dl>
|
||
</div>
|
||
<div class="card">
|
||
<h3>评论设置</h3>
|
||
<dl class="fields">
|
||
<div>
|
||
<dt><label for="reply-mode">处理方式</label></dt>
|
||
<dd><select id="reply-mode" class="control settings-input">
|
||
<option>仅浏览</option>
|
||
<option>匹配评论并回复</option>
|
||
</select></dd>
|
||
</div>
|
||
<div><dt><label for="replies-per-video">每条视频回复上限</label></dt><dd><input id="replies-per-video" class="control settings-input" type="number" inputmode="numeric" min="1" max="100" value="1" required></dd></div>
|
||
</dl>
|
||
<p class="hint">达到回复上限或找不到更多匹配评论时,进入下一个视频。</p>
|
||
</div>
|
||
<div class="card" id="content-library">
|
||
<h3>内容库</h3>
|
||
<p class="hint">按内容类型搜索视频,按关键词匹配评论。每个关键词可配置多条话术。</p>
|
||
<div class="library-level" id="type-level">
|
||
<label for="content-type">内容类型</label>
|
||
<select id="content-type" class="control settings-input"></select>
|
||
<div class="library-actions">
|
||
<button type="button" class="action" data-level="type" data-action="add" aria-label="新增内容类型">新增</button>
|
||
<button type="button" class="action" data-level="type" data-action="edit" aria-label="编辑内容类型">编辑</button>
|
||
<button type="button" class="action" data-level="type" data-action="delete" aria-label="删除内容类型">删除</button>
|
||
</div>
|
||
</div>
|
||
<div class="library-level" id="rule-level">
|
||
<label for="keyword-rule">关键词</label>
|
||
<select id="keyword-rule" class="control settings-input"></select>
|
||
<div class="library-actions">
|
||
<button type="button" class="action" data-level="rule" data-action="add" aria-label="新增关键词">新增</button>
|
||
<button type="button" class="action" data-level="rule" data-action="edit" aria-label="编辑关键词">编辑</button>
|
||
<button type="button" class="action" data-level="rule" data-action="delete" aria-label="删除关键词">删除</button>
|
||
</div>
|
||
</div>
|
||
<div class="library-level" id="phrase-level">
|
||
<label for="reply-phrase">回复话术</label>
|
||
<select id="reply-phrase" class="control settings-input"></select>
|
||
<div class="library-actions">
|
||
<button type="button" class="action" data-level="phrase" data-action="add" aria-label="新增话术">新增</button>
|
||
<button type="button" class="action" data-level="phrase" data-action="edit" aria-label="编辑话术">编辑</button>
|
||
<button type="button" class="action" data-level="phrase" data-action="delete" aria-label="删除话术">删除</button>
|
||
</div>
|
||
</div>
|
||
<div id="photo-binding" hidden>
|
||
<p id="photo-count" class="hint"></p>
|
||
<div id="photo-items"></div>
|
||
<input id="template-photo" type="file" accept="image/jpeg,image/png" multiple hidden>
|
||
<button id="photo-choose" type="button" class="action">添加本机图片</button>
|
||
<p id="photo-status" class="hint" role="status" hidden></p>
|
||
<p class="hint">支持 JPEG 和 PNG。修改名称、关键词或话术时,保留已绑定图片。</p>
|
||
</div>
|
||
</div>
|
||
<button type="button" class="action primary" id="save-preview">保存配置</button>
|
||
<p id="library-status" role="status" hidden></p>
|
||
</div>
|
||
<nav class="app-nav" aria-label="配置页导航">
|
||
<a href="#task">任务</a>
|
||
<a href="#settings" aria-current="page">配置</a>
|
||
<a href="#logs">日志</a>
|
||
</nav>
|
||
</section>
|
||
</figure>
|
||
|
||
<figure class="screen-figure" id="logs">
|
||
<figcaption>日志</figcaption>
|
||
<section class="phone" aria-label="拾见日志页">
|
||
<h2 class="app-name">拾见</h2>
|
||
<div class="phone-content">
|
||
<div class="card">
|
||
<h3>运行日志</h3>
|
||
<ul class="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>
|
||
<li><time datetime="2026-11-25T15:22:01+08:00">11-25 15:22:01</time> 运行 搜索内容类型 模型服务</li>
|
||
<li><time datetime="2026-11-25T15:22:00+08:00">11-25 15:22:00</time> 运行 开始任务 · 匹配评论并回复 · 上限 3 条</li>
|
||
<li><time datetime="2026-11-25T15:19:09+08:00">11-25 15:19:09</time> 运行 任务完成 · 处理 3 条 · 确认发送 0 条</li>
|
||
<li><time datetime="2026-11-25T15:19:02+08:00">11-25 15:19:02</time> 运行 观看第 3 条 · 7 秒</li>
|
||
<li><time datetime="2026-11-25T15:18:47+08:00">11-25 15:18:47</time> 运行 观看第 2 条 · 11 秒</li>
|
||
<li><time datetime="2026-11-25T15:18:37+08:00">11-25 15:18:37</time> 运行 观看第 1 条 · 8 秒</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<nav class="app-nav" aria-label="日志页导航">
|
||
<a href="#task">任务</a>
|
||
<a href="#settings">配置</a>
|
||
<a href="#logs" aria-current="page">日志</a>
|
||
</nav>
|
||
</section>
|
||
</figure>
|
||
</div>
|
||
</main>
|
||
<dialog id="library-editor" aria-labelledby="editor-title">
|
||
<form id="library-form">
|
||
<h2 id="editor-title"></h2>
|
||
<input id="library-value" class="control settings-input" autocomplete="off">
|
||
<textarea id="library-phrase-text" class="control multiline settings-input" rows="3" autocomplete="off" hidden></textarea>
|
||
<p id="library-error" role="alert" hidden></p>
|
||
<div class="library-actions">
|
||
<button type="button" class="action" id="edit-cancel">取消</button>
|
||
<button type="submit" class="action primary">完成</button>
|
||
</div>
|
||
</form>
|
||
</dialog>
|
||
<dialog id="library-delete" aria-labelledby="delete-message">
|
||
<p id="delete-message"></p>
|
||
<div class="library-actions">
|
||
<button type="button" class="action" id="delete-cancel">取消</button>
|
||
<button type="button" class="action primary" id="delete-confirm">删除</button>
|
||
</div>
|
||
</dialog>
|
||
<script>
|
||
const byId = id => document.getElementById(id);
|
||
const scope = byId("search-scope");
|
||
const typePicker = byId("content-type");
|
||
const rulePicker = byId("keyword-rule");
|
||
const phrasePicker = byId("reply-phrase");
|
||
const editDialog = byId("library-editor");
|
||
const deleteDialog = byId("library-delete");
|
||
const singleLine = byId("library-value");
|
||
const multiLine = byId("library-phrase-text");
|
||
const editError = byId("library-error");
|
||
const photoBinding = document.getElementById("photo-binding");
|
||
const photoCount = document.getElementById("photo-count");
|
||
const photoItems = document.getElementById("photo-items");
|
||
const fileInput = document.getElementById("template-photo");
|
||
const choosePhoto = document.getElementById("photo-choose");
|
||
const photoStatus = document.getElementById("photo-status");
|
||
const maxPhotos = 9;
|
||
const types = [{ id: "model-services", name: "模型服务", rules: [
|
||
{ id: "model-recharge", keyword: "国外大模型充值", phrases: [
|
||
{ id: "recharge-regions", text: "这条视频里提到的方式适用于哪些地区?", photos: [] },
|
||
] },
|
||
] }];
|
||
const pick = (list, picker) => list.find(item => item.id === picker.value);
|
||
const activeType = () => pick(types, typePicker);
|
||
const activeRule = () => pick(activeType()?.rules ?? [], rulePicker);
|
||
const activePhrase = () => pick(activeRule()?.phrases ?? [], phrasePicker);
|
||
const normalizeKeyword = keyword => keyword.normalize("NFKC").toLowerCase().trim().replace(/\s+/gu, " ");
|
||
const levels = {
|
||
type: { picker: typePicker, name: "内容类型", key: "name", entries: () => types, extra: () => ({ rules: [] }) },
|
||
rule: { picker: rulePicker, name: "关键词", key: "keyword", entries: () => activeType()?.rules ?? [], extra: () => ({ phrases: [] }) },
|
||
phrase: { picker: phrasePicker, name: "话术", key: "text", entries: () => activeRule()?.phrases ?? [], extra: () => ({ photos: [] }) },
|
||
};
|
||
let nextId = 0;
|
||
let editing;
|
||
let deleting;
|
||
let photoTarget;
|
||
|
||
const fillPicker = (picker, options, selected, placeholder) => {
|
||
picker.replaceChildren(...(options.length ? options.map(([id, title]) => new Option(title, id)) : [new Option(placeholder, "")]));
|
||
if (options.some(([id]) => id === selected)) picker.value = selected;
|
||
picker.disabled = !options.length;
|
||
};
|
||
const setStatus = (message = "") => {
|
||
photoStatus.textContent = message;
|
||
photoStatus.hidden = !message;
|
||
};
|
||
const photoItem = (phrase, entry, index) => {
|
||
const item = document.createElement("div");
|
||
item.className = "photo-item";
|
||
const name = document.createElement("p");
|
||
name.textContent = `图片 ${index + 1} · ${entry.name}`;
|
||
const thumbnail = document.createElement("img");
|
||
thumbnail.alt = `第 ${index + 1} 张图片预览`;
|
||
thumbnail.src = entry.url;
|
||
const actions = document.createElement("div");
|
||
actions.className = "photo-actions";
|
||
for (const [title, position, disabled] of [["上移", index - 1, index === 0], ["下移", index + 1, index === phrase.photos.length - 1], ["移除图片", null, false]]) {
|
||
const button = document.createElement("button");
|
||
button.type = "button";
|
||
button.className = "action";
|
||
button.textContent = title;
|
||
button.setAttribute("aria-label", `${title === "移除图片" ? "移除" : title}第 ${index + 1} 张图片`);
|
||
button.disabled = disabled;
|
||
button.addEventListener("click", () => {
|
||
const [selected] = phrase.photos.splice(index, 1);
|
||
if (position === null) URL.revokeObjectURL(selected.url);
|
||
else phrase.photos.splice(position, 0, selected);
|
||
setStatus();
|
||
redrawPhoto();
|
||
});
|
||
actions.append(button);
|
||
}
|
||
item.append(name, thumbnail, actions);
|
||
return item;
|
||
};
|
||
const redrawPhoto = () => {
|
||
const phrase = activePhrase();
|
||
const entries = phrase?.photos ?? [];
|
||
photoBinding.hidden = !phrase;
|
||
photoCount.textContent = `已绑定 ${entries.length} / ${maxPhotos} 张图片`;
|
||
photoItems.replaceChildren(...entries.map((entry, index) => photoItem(phrase, entry, index)));
|
||
choosePhoto.disabled = entries.length >= maxPhotos;
|
||
};
|
||
const redrawLibrary = (typeId = typePicker.value, ruleId = rulePicker.value, phraseId = phrasePicker.value) => {
|
||
const typeOptions = types.map(type => [type.id, type.name]);
|
||
fillPicker(scope, [["", "全部内容类型"], ...typeOptions], scope.value, "");
|
||
fillPicker(typePicker, typeOptions, typeId, "请先新增内容类型");
|
||
fillPicker(rulePicker, (activeType()?.rules ?? []).map(rule => [rule.id, rule.keyword]), ruleId, "请先新增关键词");
|
||
fillPicker(phrasePicker, (activeRule()?.phrases ?? []).map((phrase, index) => [phrase.id, `${index + 1}. ${phrase.text.replace(/\s+/gu, " ")}`]), phraseId, "请先新增话术");
|
||
byId("rule-level").hidden = !activeType();
|
||
byId("phrase-level").hidden = !activeRule();
|
||
for (const button of document.querySelectorAll("[data-level][data-action]")) {
|
||
button.disabled = button.dataset.action !== "add" && levels[button.dataset.level].picker.disabled;
|
||
}
|
||
redrawPhoto();
|
||
};
|
||
|
||
for (const button of document.querySelectorAll("[data-level][data-action]")) {
|
||
button.addEventListener("click", () => {
|
||
const level = button.dataset.level;
|
||
const config = levels[level];
|
||
const entries = config.entries();
|
||
const existing = pick(entries, config.picker);
|
||
if (button.dataset.action === "delete") {
|
||
if (!existing) return;
|
||
const messages = {
|
||
type: () => `删除「${existing.name}」及其中的关键词、话术和图片绑定?`,
|
||
rule: () => `删除关键词「${existing.keyword}」及其话术和图片绑定?`,
|
||
phrase: () => "删除这条话术及其图片绑定?",
|
||
};
|
||
deleting = { entries, existing };
|
||
byId("delete-message").textContent = messages[level]();
|
||
deleteDialog.showModal();
|
||
return;
|
||
}
|
||
const edit = button.dataset.action === "edit";
|
||
editing = { level, config, entries, item: edit ? existing : undefined };
|
||
byId("editor-title").textContent = `${edit ? "编辑" : "新增"}${config.name}`;
|
||
const isPhrase = level === "phrase";
|
||
singleLine.hidden = isPhrase;
|
||
multiLine.hidden = !isPhrase;
|
||
editError.hidden = true;
|
||
const field = isPhrase ? multiLine : singleLine;
|
||
field.value = editing.item?.[config.key] ?? "";
|
||
field.placeholder = isPhrase ? "输入回复文字" : level === "type" ? "内容类型名称" : "一个关键词";
|
||
field.setAttribute("aria-label", field.placeholder);
|
||
editDialog.showModal();
|
||
field.focus();
|
||
});
|
||
}
|
||
byId("edit-cancel").addEventListener("click", () => editDialog.close());
|
||
byId("delete-cancel").addEventListener("click", () => deleteDialog.close());
|
||
byId("library-form").addEventListener("submit", event => {
|
||
event.preventDefault();
|
||
const { level, config, entries, item } = editing;
|
||
const field = level === "phrase" ? multiLine : singleLine;
|
||
const value = field.value.trim();
|
||
const error = !value ? `请填写${field.placeholder}。`
|
||
: level === "type" && value.length > 120 ? "内容类型名称最多 120 个字符。"
|
||
: level === "rule" && (value.length > 120 || /[\r\n]/u.test(value)) ? "每个关键词最多 120 个字符,请填一行。"
|
||
: level === "rule" && entries.some(entry => entry !== item && normalizeKeyword(entry.keyword) === normalizeKeyword(value)) ? "这个内容类型已有相同的关键词。"
|
||
: level === "phrase" && [...value].length > 120 ? "每条话术最多 120 个字符。"
|
||
: level === "phrase" && !item && entries.length >= 100 ? "每个关键词最多 100 条话术。" : "";
|
||
if (error) {
|
||
editError.textContent = error;
|
||
editError.hidden = false;
|
||
return;
|
||
}
|
||
const updated = item ?? { id: `preview-${++nextId}`, ...config.extra() };
|
||
updated[config.key] = value;
|
||
if (!item) entries.push(updated);
|
||
editDialog.close();
|
||
setStatus();
|
||
redrawLibrary(level === "type" ? updated.id : typePicker.value,
|
||
level === "rule" ? updated.id : rulePicker.value, level === "phrase" ? updated.id : phrasePicker.value);
|
||
});
|
||
byId("delete-confirm").addEventListener("click", () => {
|
||
const { entries, existing } = deleting;
|
||
const affected = existing.rules ? existing.rules.flatMap(rule => rule.phrases) : existing.phrases ?? [existing];
|
||
for (const phrase of affected) phrase.photos.forEach(photo => URL.revokeObjectURL(photo.url));
|
||
entries.splice(entries.indexOf(existing), 1);
|
||
deleteDialog.close();
|
||
setStatus();
|
||
redrawLibrary();
|
||
});
|
||
|
||
choosePhoto.addEventListener("click", () => {
|
||
photoTarget = activePhrase();
|
||
fileInput.click();
|
||
});
|
||
fileInput.addEventListener("change", () => {
|
||
const stillPresent = types.some(type => type.rules.some(rule => rule.phrases.includes(photoTarget)));
|
||
if (stillPresent && fileInput.files.length) {
|
||
const current = photoTarget.photos;
|
||
const available = maxPhotos - current.length;
|
||
const selected = [...fileInput.files].slice(0, available);
|
||
const imported = selected.filter(file => ["image/jpeg", "image/png"].includes(file.type));
|
||
current.push(...imported.map(file => ({ name: file.name, url: URL.createObjectURL(file) })));
|
||
const issues = [];
|
||
if (selected.length > imported.length) issues.push(`${selected.length - imported.length} 张图片无法导入。`);
|
||
if (fileInput.files.length > available) issues.push(`超出数量上限的 ${fileInput.files.length - available} 张图片未导入。`);
|
||
setStatus(issues.join(" "));
|
||
}
|
||
photoTarget = undefined;
|
||
fileInput.value = "";
|
||
redrawPhoto();
|
||
});
|
||
for (const picker of [typePicker, rulePicker, phrasePicker]) {
|
||
picker.addEventListener("change", () => {
|
||
setStatus();
|
||
redrawLibrary();
|
||
});
|
||
}
|
||
byId("save-preview").addEventListener("click", () => {
|
||
const status = byId("library-status");
|
||
const invalid = [byId("video-limit"), byId("replies-per-video")].find(input => !input.validity.valid);
|
||
status.textContent = invalid ? `${invalid.labels[0].textContent}须为 1–100 的整数。` : "预览配置已更新。";
|
||
status.classList.toggle("error", Boolean(invalid));
|
||
status.hidden = false;
|
||
invalid?.focus();
|
||
});
|
||
redrawLibrary();
|
||
</script>
|
||
</body>
|
||
</html>
|