feat(评论/账号): 自动评论导入 + 账号导出 + 切号参数全局化
- 新表 comment_item(schema v25):视频链接/账号/评论内容/状态 - 新步骤 foreach_comment / mark_comment;clipboard 支持评论变量;input_text 支持当前评论内容 - 计划调度页导入评论、查看/重置/裁决评论数据 - 资产管理导出账号列表 + 自动/人工/有效状态 CSV - 切号参数全局化:fleet.switch 统一选择器,计划默认 use_global=true,老计划也按全局 - 测试 19/19;API/DATA_MODEL/TASK_DEV/ACCOUNT_FOLDER/CHANGES 同步
This commit is contained in:
+291
-32
@@ -367,6 +367,7 @@ function afHtmlAsset() {
|
||||
'<button class="btn btn-primary" onclick="afOpenAssetImport()" data-perm="devices">⬆ 批量上传素材(配模板)</button>' +
|
||||
'<button class="btn" onclick="afOpenRoster()" data-perm="devices">导入/维护账号库</button>' +
|
||||
'<button class="btn" onclick="afShowPoolApi()" data-perm="devices">🔑 账号池 API</button>' +
|
||||
'<a class="btn" href="/api/af/accounts/export" data-perm="devices" title="导出账号列表 + 自动状态/人工标记/有效状态">⬇ 导出账号列表</a>' +
|
||||
'<button class="btn" onclick="afRefreshAll(true)">刷新</button>' +
|
||||
'<span class="text-muted" style="font-size:12px">账号表里点「入库 N」进素材库;' +
|
||||
'「所属手机」改了就**重新登记**(下次按新设备激活)。' +
|
||||
@@ -1815,7 +1816,7 @@ function afPlanSwitchBar() {
|
||||
const s = sw.switch || {};
|
||||
return '<div style="border:1px solid var(--border);border-radius:6px;padding:8px 10px;margin-bottom:10px">' +
|
||||
'<b>切号 / 发布前准备参数</b> <span class="text-muted" style="font-size:12px">' +
|
||||
'(所有计划共用;切号本身用的是「发布前准备」里的内置「切账号」)</span>' +
|
||||
'(所有计划共用;选择器点「编辑切号选择器」,改一次全部生效)</span>' +
|
||||
'<div style="display:flex;gap:10px;flex-wrap:wrap;margin-top:6px;align-items:center;font-size:12px">' +
|
||||
'<span>切完等 <input class="form-control" style="width:60px;display:inline-block" type="number" min="5" id="af-sw-wait" value="' +
|
||||
(s.wait_after === undefined ? 15 : s.wait_after) + '"> 秒</span>' +
|
||||
@@ -1826,6 +1827,7 @@ function afPlanSwitchBar() {
|
||||
'<option value="continue"' + (s.on_login === 'continue' ? ' selected' : '') + '>继续(只记一句)</option>' +
|
||||
'</select></span>' +
|
||||
'<button class="btn btn-xs btn-primary" onclick="afSaveSwitchParams()">保存</button>' +
|
||||
'<button class="btn btn-xs" onclick="afOpenReadyEditor(\'global\')">编辑切号选择器</button>' +
|
||||
'<button class="btn btn-xs" onclick="afOpenQuickRun()" data-perm="devices">⚡ 临时跑一轮(不建计划)</button>' +
|
||||
'</div></div>';
|
||||
}
|
||||
@@ -1841,6 +1843,7 @@ async function afSaveSwitchParams() {
|
||||
const r = await apiPost('/api/af/profile', {name: _af.profile.name, params: p});
|
||||
if (!r || !r.ok) { showToast((r && r.error) || '保存失败', 'error'); return; }
|
||||
showToast('已保存(下次跑生效)', 'success');
|
||||
await afReloadReadyDefaults();
|
||||
}
|
||||
|
||||
// 临时跑一轮:选账号 + 动作组 → 立刻跑(不走计划、不建记录之外的任何东西)
|
||||
@@ -1976,6 +1979,8 @@ function afHtmlPlan() {
|
||||
return afPlanSwitchBar() + '' +
|
||||
'<div class="toolbar" style="flex-wrap:wrap;align-items:center">' +
|
||||
'<button class="btn btn-primary" onclick="afOpenPlan(\'\')" data-perm="devices">+ 新建计划</button>' +
|
||||
'<button class="btn" onclick="afOpenCommentImport()" data-perm="devices">📥 导入评论</button>' +
|
||||
'<button class="btn" onclick="afShowComments()" data-perm="devices">评论数据</button>' +
|
||||
'<button class="btn" onclick="afRefreshAll(true)">刷新</button>' +
|
||||
'<span class="text-muted">一条计划 = <b>干什么</b>(App + 动作组)· <b>给谁干</b>(账号库里勾号)· ' +
|
||||
'<b>发什么</b>(每人几条)· <b>什么时候</b>(固定点 + 抖动)· <b>怎么跑</b>(并发/重试/失败处置);' +
|
||||
@@ -1999,6 +2004,180 @@ function afHtmlPlan() {
|
||||
'</div>';
|
||||
}
|
||||
|
||||
// ================== 评论数据:导入 / 列表 ==================
|
||||
function afOpenCommentImport() {
|
||||
if (document.getElementById('af-cm-imp')) return;
|
||||
const ov = document.createElement('div');
|
||||
ov.id = 'af-cm-imp';
|
||||
ov.className = 'modal-overlay show';
|
||||
ov.onclick = function (e) { if (e.target === ov) ov.remove(); };
|
||||
ov.innerHTML = '<div class="modal" style="max-width:860px">' +
|
||||
'<div class="modal-header"><h3>导入评论数据</h3>' +
|
||||
'<button class="close" onclick="document.getElementById(\'af-cm-imp\').remove()">×</button></div>' +
|
||||
'<div class="modal-body">' +
|
||||
'<div class="help" style="margin-bottom:8px">每行一条:<b>视频链接 账号 评论内容</b>(制表符/逗号都行)。' +
|
||||
'账号写账号库里的昵称或抖音号;同一个账号可以对多条视频各有一行。' +
|
||||
'重复导入按「视频链接 + 账号」去重:未执行的更新,已评论/结果未知的跳过。<br>' +
|
||||
'CSV 里评论内容带逗号/换行时要用引号包起来。</div>' +
|
||||
'<div class="toolbar" style="margin-bottom:6px">' +
|
||||
'<a class="btn btn-xs" href="/api/af/comments/template" target="_blank">⬇ 下载模板(CSV)</a>' +
|
||||
'<span class="text-muted" style="font-size:12px">可以从 Excel 直接复制三列粘贴到下面</span></div>' +
|
||||
'<div class="form-group"><label>粘贴表格(优先使用;有文件时以文件为准)</label>' +
|
||||
'<textarea id="af-cm-text" class="form-control" rows="8" style="font-family:monospace" ' +
|
||||
'placeholder="视频链接\t账号\t评论内容 https://v.douyin.com/xxxxxx/\t周周苏州寻宝藏小店\t这家店我去过"></textarea></div>' +
|
||||
'<div class="form-group"><label>或上传 CSV</label>' +
|
||||
'<input type="file" class="form-control" id="af-cm-file" accept=".csv,text/csv"></div>' +
|
||||
'<div id="af-cm-log" class="text-muted" style="font-size:12px;max-height:260px;overflow:auto"></div>' +
|
||||
'</div>' +
|
||||
'<div class="modal-footer">' +
|
||||
'<button class="btn" onclick="document.getElementById(\'af-cm-imp\').remove()">关闭</button>' +
|
||||
'<button class="btn" onclick="afDoCommentImport(1)">试导(只校验)</button>' +
|
||||
'<button class="btn btn-primary" onclick="afDoCommentImport(0)">导入</button>' +
|
||||
'</div></div>';
|
||||
document.body.appendChild(ov);
|
||||
}
|
||||
|
||||
async function afDoCommentImport(dry) {
|
||||
const textEl = document.getElementById('af-cm-text');
|
||||
const fileEl = document.getElementById('af-cm-file');
|
||||
const log = document.getElementById('af-cm-log');
|
||||
if (!textEl || !log) return;
|
||||
const text = (textEl.value || '').trim();
|
||||
const file = fileEl && fileEl.files ? fileEl.files[0] : null;
|
||||
if (!text && !file) { showToast('先粘贴表格或选一个 CSV', 'error'); return; }
|
||||
log.innerHTML = '⏳ ' + (dry ? '正在校验(不写库)…' : '正在导入…');
|
||||
let res = null;
|
||||
try {
|
||||
if (file) {
|
||||
const fd = new FormData();
|
||||
fd.append('file', file);
|
||||
if (dry) fd.append('dry_run', '1');
|
||||
const r = await fetch('/api/af/comments/import', {
|
||||
method: 'POST',
|
||||
headers: {'X-CSRF-Token': (typeof _csrfToken !== 'undefined' ? _csrfToken : '')},
|
||||
body: fd
|
||||
});
|
||||
res = await r.json();
|
||||
} else {
|
||||
res = await apiPost('/api/af/comments/import', {text: text, dry_run: !!dry});
|
||||
}
|
||||
} catch (e) {
|
||||
log.innerHTML = '<span style="color:#c0392b">❌ 请求失败:' + esc(String(e)) + '</span>';
|
||||
return;
|
||||
}
|
||||
if (!res || !res.ok) {
|
||||
log.innerHTML = '<span style="color:#c0392b">❌ ' + esc((res && (res.error || res.msg)) || '导入失败') + '</span>';
|
||||
return;
|
||||
}
|
||||
const rows = res.rows || [];
|
||||
const head = (dry ? '试导' : '导入') + '完成:新增 ' + (res.added || 0) +
|
||||
' / 更新 ' + (res.updated || 0) + ' / 跳过 ' + (res.skipped || 0) +
|
||||
' / 错误 ' + (res.errors || 0) + (dry ? '(没有写库)' : '');
|
||||
log.innerHTML = '<div style="color:' + ((res.errors || 0) ? '#b45309' : '#16a34a') +
|
||||
';margin-bottom:4px"><b>' + esc(head) + '</b></div>' +
|
||||
'<table class="table" style="font-size:12px"><thead><tr>' +
|
||||
'<th style="width:45px">行</th><th style="width:110px">账号</th><th>视频链接</th>' +
|
||||
'<th style="width:75px">结果</th><th>说明</th></tr></thead><tbody>' +
|
||||
rows.map(function (x) {
|
||||
const bad = x.action === 'error';
|
||||
return '<tr><td>' + (x.line || '') + '</td><td>' + esc(x.account || '') + '</td>' +
|
||||
'<td style="max-width:260px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">' +
|
||||
esc(x.url || x.video_url || '') + '</td>' +
|
||||
'<td style="' + (bad ? 'color:#c0392b' : '') + '">' + esc(x.action || '') + '</td>' +
|
||||
'<td style="' + (bad ? 'color:#c0392b' : '') + '">' + esc(x.msg || x.error || '') + '</td></tr>';
|
||||
}).join('') + '</tbody></table>';
|
||||
if (!dry) showToast('评论数据已导入', 'success');
|
||||
}
|
||||
|
||||
function _afCommentStatusLabel(st) {
|
||||
const m = {pending: ['待评论', 'label-default'], running: ['执行中', 'label-warning'],
|
||||
done: ['已评论', 'label-success'], failed: ['失败可重试', 'label-danger'],
|
||||
unknown: ['结果未知', 'label-warning']};
|
||||
const x = m[st] || [st || '—', 'label-default'];
|
||||
return '<span class="label ' + x[1] + '">' + esc(x[0]) + '</span>';
|
||||
}
|
||||
|
||||
async function afShowComments(account, status) {
|
||||
account = account || '';
|
||||
status = status || '';
|
||||
const qs = '/api/af/comments?limit=500' +
|
||||
(account ? ('&account=' + encodeURIComponent(account)) : '') +
|
||||
(status ? ('&status=' + encodeURIComponent(status)) : '');
|
||||
const r = await apiGet(qs);
|
||||
if (!r || !r.ok) { showToast((r && r.error) || '读取评论数据失败', 'error'); return; }
|
||||
const rows = r.rows || [];
|
||||
const st = r.stats || {};
|
||||
const counts = st.counts || {};
|
||||
const old = document.getElementById('af-cm-list');
|
||||
if (old) old.remove();
|
||||
const ov = document.createElement('div');
|
||||
ov.id = 'af-cm-list';
|
||||
ov.className = 'modal-overlay show';
|
||||
ov.onclick = function (e) { if (e.target === ov) ov.remove(); };
|
||||
const opts = [['', '全部账号']].concat((r.accounts || []).map(function (a) {
|
||||
return [a.account_name, a.account_name + '(' + a.pending + ' 条待评论)'];
|
||||
}));
|
||||
ov.innerHTML = '<div class="modal" style="max-width:1050px">' +
|
||||
'<div class="modal-header"><h3>评论数据</h3>' +
|
||||
'<button class="close" onclick="document.getElementById(\'af-cm-list\').remove()">×</button></div>' +
|
||||
'<div class="modal-body">' +
|
||||
'<div class="toolbar" style="flex-wrap:wrap;align-items:center;gap:8px">' +
|
||||
'<span class="text-muted" style="font-size:12px">待评论 <b>' + (st.pending || 0) + '</b> 条 · ' +
|
||||
'涉及 <b>' + (st.accounts || 0) + '</b> 个账号 · 已评论 ' + (counts.done || 0) +
|
||||
' · 结果未知 ' + (counts.unknown || 0) + ' · 失败 ' + (counts.failed || 0) + '</span>' +
|
||||
'<select class="form-control" style="width:210px" data-status="' + esc(status) + '" onchange="afShowComments(this.value, this.dataset.status||\'\')">' +
|
||||
opts.map(function (o) {
|
||||
return '<option value="' + esc(o[0]) + '"' + (o[0] === account ? ' selected' : '') + '>' + esc(o[1]) + '</option>';
|
||||
}).join('') + '</select>' +
|
||||
'<select class="form-control" style="width:130px" data-account="' + esc(account) + '" onchange="afShowComments(this.dataset.account||\'\', this.value)">' +
|
||||
[['', '全部状态'], ['pending', '待评论'], ['failed', '失败可重试'],
|
||||
['unknown', '结果未知'], ['done', '已评论'], ['running', '执行中']].map(function (o) {
|
||||
return '<option value="' + o[0] + '"' + (o[0] === status ? ' selected' : '') + '>' + o[1] + '</option>';
|
||||
}).join('') + '</select>' +
|
||||
'<button class="btn btn-xs" onclick="afOpenCommentImport()">📥 导入评论</button>' +
|
||||
'</div>' +
|
||||
'<table class="table" style="font-size:12px;margin-top:8px"><thead><tr>' +
|
||||
'<th style="width:120px">账号</th><th style="width:150px">视频链接</th><th>评论内容</th>' +
|
||||
'<th style="width:90px">状态</th><th style="width:70px">尝试</th><th style="width:190px">操作</th>' +
|
||||
'</tr></thead><tbody>' +
|
||||
(rows.map(function (x) {
|
||||
const url = x.video_url || '';
|
||||
return '<tr><td>' + esc(x.account_name || '') + '</td>' +
|
||||
'<td style="max-width:160px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="' + esc(url) + '">' +
|
||||
(url ? '<a href="' + esc(url) + '" target="_blank" rel="noopener">' + esc(url) + '</a>' : '—') + '</td>' +
|
||||
'<td title="' + esc(x.comment_text || '') + '">' + esc((x.comment_text || '').slice(0, 80)) +
|
||||
((x.comment_text || '').length > 80 ? '…' : '') + '</td>' +
|
||||
'<td>' + _afCommentStatusLabel(x.status) + '</td>' +
|
||||
'<td>' + (x.attempts || 0) + '</td>' +
|
||||
'<td style="white-space:nowrap">' +
|
||||
(x.status !== 'pending' ? '<button class="btn btn-xs" onclick="afCommentAction(\'' + esc(x.id) + '\',\'reset\')">重置</button>' : '') +
|
||||
(x.status !== 'done' ? '<button class="btn btn-xs" onclick="afCommentAction(\'' + esc(x.id) + '\',\'done\')">标已发</button>' : '') +
|
||||
'<button class="btn btn-xs" onclick="afCommentAction(\'' + esc(x.id) + '\',\'unknown\')">标未知</button>' +
|
||||
'<button class="btn btn-xs btn-danger" onclick="afCommentDelete(\'' + esc(x.id) + '\')">删除</button>' +
|
||||
'</td></tr>';
|
||||
}).join('') || '<tr><td colspan="6" class="empty">还没有评论数据 —— 点「导入评论」粘贴表格</td></tr>') +
|
||||
'</tbody></table></div>' +
|
||||
'<div class="modal-footer"><button class="btn" onclick="document.getElementById(\'af-cm-list\').remove()">关闭</button></div></div>';
|
||||
document.body.appendChild(ov);
|
||||
}
|
||||
|
||||
async function afCommentAction(id, action) {
|
||||
let r = null;
|
||||
if (action === 'reset') r = await apiPost('/api/af/comments/' + encodeURIComponent(id) + '/reset', {});
|
||||
else r = await apiPost('/api/af/comments/' + encodeURIComponent(id) + '/resolve', {result: action});
|
||||
if (!r || !r.ok) { showToast((r && r.error) || '操作失败', 'error'); return; }
|
||||
showToast(r.msg || '已更新', 'success');
|
||||
afShowComments();
|
||||
}
|
||||
|
||||
async function afCommentDelete(id) {
|
||||
if (!confirm('删除这条评论数据?')) return;
|
||||
const r = await apiDelete('/api/af/comments/' + encodeURIComponent(id));
|
||||
if (!r || !r.ok) { showToast((r && r.error) || '删除失败', 'error'); return; }
|
||||
showToast('已删除', 'success');
|
||||
afShowComments();
|
||||
}
|
||||
|
||||
function _afPlanStatus(s) {
|
||||
const m = {done: '<span class="label label-success">全部完成</span>',
|
||||
partial: '<span class="label label-warning">部分完成</span>',
|
||||
@@ -2028,21 +2207,28 @@ function _afPlanSegDefault() {
|
||||
// 它不是动作库里的条目,而是计划执行每个账号前的内置步骤;页面把它显示在编排列表上方,
|
||||
// 参数存在 plan.ready(空 = 用 /api/af/ready_defaults 的全局默认)。
|
||||
function afPlanReadyInit(saved) {
|
||||
const d = _af.readyDefaults || {};
|
||||
const s = saved || {};
|
||||
_afPlanReady = Object.assign({}, d, s);
|
||||
_afPlanReady.enabled = (s.enabled === undefined) ? true : !!s.enabled;
|
||||
// 只保留可编辑字段,避免把 probability/target 等内部字段带进保存体
|
||||
['switch_selector_type', 'switch_selector_value', 'me_selector_type', 'me_selector_value',
|
||||
'name_selector_type', 'name_selector_value', 'timeout', 'wait_after', 'max_attempts',
|
||||
'on_login_page', 'on_fail'].forEach(function (k) {
|
||||
if (_afPlanReady[k] === undefined && d[k] !== undefined) _afPlanReady[k] = d[k];
|
||||
});
|
||||
// 2026-10-31:默认用**全局切号参数**。老计划没有 use_global 字段也按全局走
|
||||
// (否则元素一变就要一个个计划改)。要单独覆盖才显式存 use_global=false。
|
||||
const useGlobal = s.use_global !== false;
|
||||
_afPlanReady = {enabled: s.enabled === undefined ? true : !!s.enabled,
|
||||
use_global: useGlobal};
|
||||
if (!useGlobal) Object.assign(_afPlanReady, s, {use_global: false});
|
||||
}
|
||||
|
||||
function afPlanReadySet(k, v) {
|
||||
if (!_afPlanReady) _afPlanReady = {};
|
||||
_afPlanReady[k] = v;
|
||||
if (!_afPlanReady) _afPlanReady = {enabled: true, use_global: true};
|
||||
if (k === 'use_global') {
|
||||
if (v) {
|
||||
_afPlanReady = {enabled: _afPlanReady.enabled !== false, use_global: true};
|
||||
} else {
|
||||
const d = _af.readyDefaults || {};
|
||||
_afPlanReady = Object.assign({}, d, {enabled: _afPlanReady.enabled !== false,
|
||||
use_global: false});
|
||||
}
|
||||
} else {
|
||||
_afPlanReady[k] = v;
|
||||
}
|
||||
afPlanReadyRender();
|
||||
}
|
||||
|
||||
@@ -2051,25 +2237,33 @@ function afPlanReadyRender() {
|
||||
if (!box) return;
|
||||
const r = _afPlanReady || {};
|
||||
const en = r.enabled !== false;
|
||||
const short = function (v) {
|
||||
v = v || '';
|
||||
return v.length > 44 ? (v.slice(0, 44) + '…') : (v || '(默认)');
|
||||
const useGlobal = r.use_global !== false;
|
||||
const d = _af.readyDefaults || {};
|
||||
const v = useGlobal ? Object.assign({}, d, {enabled: en}) : r;
|
||||
const short = function (val) {
|
||||
val = val || '';
|
||||
return val.length > 44 ? (val.slice(0, 44) + '…') : (val || '(默认)');
|
||||
};
|
||||
box.innerHTML = '<div style="border:1px solid var(--border);border-radius:6px;padding:8px;margin-bottom:8px;background:#fafafa">' +
|
||||
'<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">' +
|
||||
'<b>🔒 内置 · 账号就绪(切号)</b>' +
|
||||
'<label style="font-weight:400;font-size:12px"><input type="checkbox" ' + (en ? 'checked' : '') +
|
||||
' onchange="afPlanReadySet(\'enabled\', this.checked)"> 启用</label>' +
|
||||
'<button class="btn btn-xs" onclick="afOpenReadyEditor()">编辑参数</button>' +
|
||||
'<span class="text-muted" style="font-size:11px">每个账号在编排之前自动执行;切不过来默认跳过这个号</span>' +
|
||||
'<label style="font-weight:400;font-size:12px"><input type="checkbox" ' + (useGlobal ? 'checked' : '') +
|
||||
' onchange="afPlanReadySet(\'use_global\', this.checked)"> 使用全局切号参数</label>' +
|
||||
(useGlobal
|
||||
? '<button class="btn btn-xs" onclick="afOpenReadyEditor(\'global\')">编辑全局参数</button>'
|
||||
: '<button class="btn btn-xs" onclick="afOpenReadyEditor(\'plan\')">编辑本计划参数</button>') +
|
||||
'<span class="text-muted" style="font-size:11px">' +
|
||||
(useGlobal ? '全局改了所有计划一起生效' : '本计划单独覆盖,不受全局改动影响') + '</span>' +
|
||||
'</div>' +
|
||||
(en
|
||||
? ('<div class="text-muted" style="font-size:11px;margin-top:4px">' +
|
||||
'点「我」(' + esc(r.me_selector_type || 'xpath') + ': ' + esc(short(r.me_selector_value)) + ')' +
|
||||
'点「我」(' + esc(v.me_selector_type || 'xpath') + ': ' + esc(short(v.me_selector_value)) + ')' +
|
||||
' → 读名字 → 一样跳过 / 不一样才切;切后等 ' +
|
||||
(r.wait_after === undefined ? 15 : r.wait_after) + ' 秒,重试 ' +
|
||||
(r.max_attempts || 2) + ' 次;切不过去:' +
|
||||
(r.on_fail === 'stop' ? '停本设备' : '跳过这个号') +
|
||||
(v.wait_after === undefined ? 15 : v.wait_after) + ' 秒,重试 ' +
|
||||
(v.max_attempts || 2) + ' 次;切不过去:' +
|
||||
(v.on_fail === 'stop' ? '停本设备' : '跳过这个号') +
|
||||
'</div>')
|
||||
: '<div style="color:#c0392b;font-size:11px;margin-top:4px">' +
|
||||
'已关闭内置切号 —— 请在下面的编排里放一个切号动作组,否则可能发到错误的号</div>') +
|
||||
@@ -2090,8 +2284,33 @@ function _afReadySelOpts(cur, withAll) {
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function afOpenReadyEditor() {
|
||||
const r = _afPlanReady || {};
|
||||
var _afReadyEditMode = 'plan';
|
||||
|
||||
async function afReloadReadyDefaults() {
|
||||
const rd = await apiGet('/api/af/ready_defaults');
|
||||
if (rd && rd.ok) _af.readyDefaults = rd.params || {};
|
||||
if (document.getElementById('afp-ready')) afPlanReadyRender();
|
||||
afRender();
|
||||
}
|
||||
|
||||
function afOpenReadyEditor(mode) {
|
||||
_afReadyEditMode = mode || 'plan';
|
||||
const globalMode = _afReadyEditMode === 'global';
|
||||
const gsw = ((((_af.profile || {}).params || {}).fleet || {}).switch) || {};
|
||||
const d = _af.readyDefaults || {};
|
||||
const r = globalMode ? {
|
||||
switch_selector_type: gsw.entry_selector_type || gsw.switch_selector_type || d.switch_selector_type || '',
|
||||
switch_selector_value: gsw.entry_selector_value || gsw.switch_selector_value || d.switch_selector_value || '',
|
||||
name_selector_type: gsw.name_selector_type || d.name_selector_type || '',
|
||||
name_selector_value: gsw.name_selector_value || d.name_selector_value || '',
|
||||
me_selector_type: gsw.me_selector_type || d.me_selector_type || '',
|
||||
me_selector_value: gsw.me_selector_value || d.me_selector_value || '',
|
||||
timeout: gsw.timeout === undefined ? (d.timeout === undefined ? 8 : d.timeout) : gsw.timeout,
|
||||
wait_after: gsw.wait_after === undefined ? (d.wait_after === undefined ? 15 : d.wait_after) : gsw.wait_after,
|
||||
max_attempts: gsw.retries || d.max_attempts || 2,
|
||||
on_login_page: gsw.on_login || d.on_login_page || 'stop',
|
||||
on_fail: gsw.on_fail || d.on_fail || 'skip_account'
|
||||
} : Object.assign({}, d, _afPlanReady || {}, {use_global: false});
|
||||
const old = document.getElementById('af-ready-overlay');
|
||||
if (old) old.remove();
|
||||
const ov = document.createElement('div');
|
||||
@@ -2100,13 +2319,18 @@ function afOpenReadyEditor() {
|
||||
ov.style.zIndex = 1200;
|
||||
ov.onclick = function (e) { if (e.target === ov) ov.remove(); };
|
||||
ov.innerHTML = '<div class="modal" style="max-width:760px">' +
|
||||
'<div class="modal-header"><h3>内置步骤参数 · 账号就绪(切号)</h3>' +
|
||||
'<div class="modal-header"><h3>' +
|
||||
(globalMode ? '全局切号参数(所有计划共用)' : '内置步骤参数 · 账号就绪(切号)') + '</h3>' +
|
||||
'<button class="close" onclick="document.getElementById(\'af-ready-overlay\').remove()">×</button></div>' +
|
||||
'<div class="modal-body">' +
|
||||
'<div class="help" style="margin-bottom:8px">这里是**计划内置**的切号步骤:每个账号执行编排前先跑它。' +
|
||||
'空选择器 = 用全局默认(config/.env)。关闭后请自己在编排里放一个切号动作组。</div>' +
|
||||
'<div class="form-check" style="margin-bottom:8px"><input type="checkbox" id="afr-enabled" ' +
|
||||
(r.enabled !== false ? 'checked' : '') + '><label for="afr-enabled">启用内置切号</label></div>' +
|
||||
'<div class="help" style="margin-bottom:8px">' +
|
||||
(globalMode
|
||||
? '这里是<b>全局</b>切号选择器:所有「使用全局切号参数」的计划都读这一份,元素变了只改这里一次。'
|
||||
: '这里是<b>本计划</b>的切号覆盖:只影响这个计划。一般保持「使用全局切号参数」,除非本计划确实要不同选择器。') +
|
||||
'</div>' +
|
||||
(globalMode ? '' :
|
||||
'<div class="form-check" style="margin-bottom:8px"><input type="checkbox" id="afr-enabled" ' +
|
||||
(r.enabled !== false ? 'checked' : '') + '><label for="afr-enabled">启用内置切号</label></div>') +
|
||||
'<div class="form-group"><label>进「切换账号」列表的入口</label>' +
|
||||
'<div style="display:flex;gap:6px">' +
|
||||
'<select class="form-control" id="afr-sw-type" style="width:170px">' + _afReadySelOpts(r.switch_selector_type) + '</select>' +
|
||||
@@ -2153,8 +2377,7 @@ function afOpenReadyEditor() {
|
||||
function afSaveReadyEditor() {
|
||||
const g = function (id) { const e = document.getElementById(id); return e ? e.value : ''; };
|
||||
const c = function (id) { const e = document.getElementById(id); return !!(e && e.checked); };
|
||||
_afPlanReady = {
|
||||
enabled: c('afr-enabled'),
|
||||
const r = {
|
||||
switch_selector_type: g('afr-sw-type'), switch_selector_value: g('afr-sw-val'),
|
||||
me_selector_type: g('afr-me-type'), me_selector_value: g('afr-me-val'),
|
||||
name_selector_type: g('afr-name-type'), name_selector_value: g('afr-name-val'),
|
||||
@@ -2164,6 +2387,30 @@ function afSaveReadyEditor() {
|
||||
on_login_page: g('afr-login') || 'stop',
|
||||
on_fail: g('afr-fail') || 'skip_account'
|
||||
};
|
||||
if (_afReadyEditMode === 'global') {
|
||||
const p = _af.profile && _af.profile.params;
|
||||
if (!p) { showToast('配置还没加载', 'error'); return; }
|
||||
p.fleet = p.fleet || {};
|
||||
p.fleet.switch = Object.assign({}, p.fleet.switch || {}, {
|
||||
entry_selector_type: r.switch_selector_type,
|
||||
entry_selector_value: r.switch_selector_value,
|
||||
name_selector_type: r.name_selector_type,
|
||||
name_selector_value: r.name_selector_value,
|
||||
me_selector_type: r.me_selector_type,
|
||||
me_selector_value: r.me_selector_value,
|
||||
timeout: r.timeout, wait_after: r.wait_after, retries: r.max_attempts,
|
||||
on_login: r.on_login_page, on_fail: r.on_fail
|
||||
});
|
||||
apiPost('/api/af/profile', {name: _af.profile.name, params: p}).then(async function (res) {
|
||||
const ov = document.getElementById('af-ready-overlay');
|
||||
if (ov) ov.remove();
|
||||
if (!res || !res.ok) { showToast((res && res.error) || '保存失败', 'error'); return; }
|
||||
showToast('全局切号参数已保存(所有使用全局的计划生效)', 'success');
|
||||
await afReloadReadyDefaults();
|
||||
});
|
||||
return;
|
||||
}
|
||||
_afPlanReady = Object.assign({}, r, {enabled: c('afr-enabled'), use_global: false});
|
||||
const ov = document.getElementById('af-ready-overlay');
|
||||
if (ov) ov.remove();
|
||||
afPlanReadyRender();
|
||||
@@ -2255,7 +2502,13 @@ function afPlanSegRow(s, i) {
|
||||
'type="number" min="0" value="' + (s.per_account === undefined ? 1 : s.per_account) +
|
||||
'" onchange="afPlanSegSet(' + i + ',\'per_account\',this.value)"> 条(0=全部)</span>') : '') +
|
||||
(s.source === 'task'
|
||||
? '<span class="text-muted" style="font-size:11px">任务只做发布动作;推送/标记由计划补(任务里已有就不重复)</span>'
|
||||
? (function () {
|
||||
const tj = (_af.jobs || []).find(function (x) { return x.id === s.task_id; }) || {};
|
||||
const isComment = (tj.name || '').indexOf('评论') >= 0;
|
||||
return isComment
|
||||
? '<span style="color:#b45309;font-size:11px">评论任务:<b>不要勾「发布素材」</b>,评论数据由任务里的「循环评论」取</span>'
|
||||
: '<span class="text-muted" style="font-size:11px">任务只做发布动作;推送/标记由计划补(任务里已有就不重复)</span>';
|
||||
})()
|
||||
: '') +
|
||||
'<label style="font-weight:400;font-size:12px">循环 ' +
|
||||
'<select class="form-control" style="width:86px;display:inline-block" onchange="afPlanSegSet(' + i + ',\'loop.mode\',this.value)">' +
|
||||
@@ -2585,7 +2838,13 @@ async function afSavePlan(planId) {
|
||||
app_id: first.app_id || '',
|
||||
action_id: first.action_id,
|
||||
segments: segs,
|
||||
ready: _afPlanReady || {},
|
||||
ready: (function () {
|
||||
const r = _afPlanReady || {};
|
||||
if (r.use_global !== false) {
|
||||
return {enabled: r.enabled !== false, use_global: true};
|
||||
}
|
||||
return Object.assign({}, r, {use_global: false});
|
||||
})(),
|
||||
account_ids: ids, accounts: names,
|
||||
material: (function () {
|
||||
const mode = (document.querySelector('input[name="afp-matmode"]:checked') || {}).value || 'pool';
|
||||
|
||||
+33
-10
@@ -21,6 +21,8 @@ var STEP_LIB=[
|
||||
{type:'group',label:'动作组',icon:'📦',cat:'flow',params:{children:[]}},
|
||||
{type:'if_el',label:'条件判断',icon:'❓',cat:'flow',params:{selector_type:'xpath',selector_value:'',timeout:3,ocr_click:false,cmp_op:'',cmp_value:'',cmp_source:'',cmp_group:'',ident_type:'text',ident_value:'',then:[],else:[]}},
|
||||
{type:'mark_done',label:'记为已做',icon:'✅',cat:'flow',params:{selector_type:'text',selector_value:''}},
|
||||
{type:'mark_comment',label:'标记评论完成',icon:'💬',cat:'flow',params:{result:'done',why:''}},
|
||||
{type:'foreach_comment',label:'循环当前账号的待评论',icon:'💬',cat:'flow',params:{retry_failed:true,max_items:0,stop_on_miss:true,children:[]}},
|
||||
{type:'read_account_name',label:'读取本机账号名字',icon:'🏷',cat:'flow',params:{selector_type:'xpath',selector_value:'',timeout:8,on_missing:'fail'}},
|
||||
{type:'expect_el',label:'校验页面',icon:'🔎',cat:'flow',params:{selector_type:'xpath',selector_value:'',timeout:10,on_missing:'skip_rest',what:''}},
|
||||
{type:'read_text',label:'读取文字',icon:'📖',cat:'flow',params:{selector_type:'xpath',selector_value:'',timeout:8,var:'account_name',clean:'account',on_missing:'skip'}},
|
||||
@@ -301,7 +303,7 @@ var _stepEditor={
|
||||
var self=this;
|
||||
var lib=_findLib(step.type)||{icon:'?',label:step.type};
|
||||
var card=document.createElement('div');
|
||||
card.className='step-card'+(step.type==='loop'?' loop-block':'')+(step.type==='group'?' group-block':'')+(step.type==='if_el'?' if-block':'')+(step.type==='foreach_account'?' loop-block':'');
|
||||
card.className='step-card'+(step.type==='loop'?' loop-block':'')+(step.type==='group'?' group-block':'')+(step.type==='if_el'?' if-block':'')+((step.type==='foreach_account'||step.type==='foreach_comment')?' loop-block':'');
|
||||
card.draggable=true;
|
||||
card.dataset.idx=idx;
|
||||
card.dataset.stepId=step.id||'';
|
||||
@@ -351,7 +353,7 @@ var _stepEditor={
|
||||
});
|
||||
// loop/group/foreach_account 子步骤(**容器不列进来就看不到里面** —— 加新容器类型时
|
||||
// 记得同时改这里、card.className 和 _renderParams 三处)
|
||||
if(step.type==='loop'||step.type==='group'||step.type==='foreach_account'){
|
||||
if(step.type==='loop'||step.type==='group'||step.type==='foreach_account'||step.type==='foreach_comment'){
|
||||
if(step.params&&step.params.children){
|
||||
var childWrap=document.createElement('div');
|
||||
childWrap.className='step-children';
|
||||
@@ -493,30 +495,37 @@ var _stepEditor={
|
||||
h+='<div class="form-group form-check"><input type="checkbox" data-key="vary_pace" '+(p.vary_pace?'checked':'')+'><label>按设备节奏微调(0.8~1.35 倍)</label></div>';
|
||||
h+='<div class="help">勾上后每台设备按自己的节奏缩放这个等待:批量跑时设备之间会逐渐错开,不再整齐划一。代价是实际时长不再严格等于上面填的值</div>';
|
||||
}else if(step.type==='clipboard'){
|
||||
h+='<div class="form-group"><label>注入内容</label><textarea class="form-control" data-key="text" rows="3" style="font-family:monospace;min-height:70px">'+esc(p.text||'')+'</textarea></div>';
|
||||
h+='<div class="form-group"><label>注入内容</label><textarea class="form-control" data-key="text" rows="3" style="font-family:monospace;min-height:70px">'+esc(p.text||'')+'</textarea>'+
|
||||
'<div style="margin-top:4px"><button class="btn btn-xs" onclick="_stepEditor.insertVar(this)">插入变量</button>'+
|
||||
'<span class="help" style="display:inline;margin-left:6px">可用 <code>{comment_url}</code> / <code>{comment_share_text}</code> / <code>{comment_text}</code></span></div></div>';
|
||||
h+='<div class="form-group form-check"><input type="checkbox" data-key="paste" '+(p.paste!==false?'checked':'')+'><label>注入后立即粘贴(需输入框已聚焦)</label></div>';
|
||||
h+='<div class="help">批量发链接场景:先"点击元素"聚焦评论区输入框,再执行本步骤注入+粘贴;循环里依次更换注入内容即可逐个发</div>';
|
||||
h+='<div class="help">批量发链接/评论场景:剪贴板文字支持运行期变量。评论任务里链接用 <code>{comment_share_text}</code>,评论内容用 <code>{comment_text}</code>。评论内容也可以改用「输入文字 → 取值来源=当前评论内容」,带回读校验更稳。</div>';
|
||||
}else if(step.type==='input_text'){
|
||||
const im=p.mode==='fixed'?'fixed':'random';
|
||||
const tsrc=p.text_source||'manual';
|
||||
const fromPlan=(tsrc!=='manual');
|
||||
const fromPlan=(tsrc!=='manual' && tsrc!=='comment');
|
||||
const autoSource=(tsrc!=='manual');
|
||||
// 取值来源:默认手填(行为与以前一致);也可以直接吃「发布计划」里那一条的标题
|
||||
h+='<div class="form-group"><label>取值来源</label><select class="form-control" data-key="text_source" onchange="_stepEditor._inputSourceChanged(this)">'+
|
||||
[['manual','手填 / 随机候选(默认)'],['release_title','发布计划这一条的标题'],
|
||||
['release_title_topics','发布计划标题 + 话题'],['release_body','发布计划这一条的正文'],
|
||||
['release_body_topics','发布计划正文 + 话题'],['release_title_body','标题 + 正文(一个框时用)']]
|
||||
['release_body_topics','发布计划正文 + 话题'],['release_title_body','标题 + 正文(一个框时用)'],
|
||||
['comment','当前评论内容(循环评论给的)']]
|
||||
.map(function(o){return '<option value="'+o[0]+'"'+(tsrc===o[0]?' selected':'')+'>'+o[1]+'</option>';}).join('')+
|
||||
'</select><div class="help">选"发布计划"时,标题由前面的「推送发布视频」那一步取出来(同一次运行里传递;没取到会跳过并告警)—— 你就不用把同一句文案再抄一遍了</div></div>';
|
||||
if(fromPlan){
|
||||
h+='<div class="form-group" data-key-wrap="release_topics" style="display:'+(/topics$/.test(tsrc)?'block':'none')+'"><label>话题(逗号分隔,不带 # 会自动补)</label><input type="text" class="form-control" data-key="release_topics" value="'+esc(p.release_topics||'')+'" placeholder="如 苏州,日常"></div>';
|
||||
h+='<div class="help" style="color:#f59e0b">取计划标题时<b>会回读输入框校验</b>:抖音的输入框有时不吃键盘输入,不校验就可能发出一篇空文案;校验不过会自动改走剪贴板粘贴再验一次</div>';
|
||||
}
|
||||
if(tsrc==='comment'){
|
||||
h+='<div class="help" style="color:#f59e0b">从「循环评论」当前领取的那条取评论内容,并带<b>回读校验</b>;校验不过自动改走剪贴板粘贴。</div>';
|
||||
}
|
||||
// 手填那两块:**只隐藏不删**(_syncParams 按 DOM 存在与否收集,删了会把用户填的值抹掉)
|
||||
h+='<div class="form-group" style="display:'+(fromPlan?'none':'block')+'"><label>输入模式</label><select class="form-control" data-key="mode" onchange="_stepEditor._toggleInputMode(this)">'+
|
||||
h+='<div class="form-group" style="display:'+(autoSource?'none':'block')+'"><label>输入模式</label><select class="form-control" data-key="mode" onchange="_stepEditor._toggleInputMode(this)">'+
|
||||
'<option value="random"'+(im==='random'?' selected':'')+'>随机候选</option>'+
|
||||
'<option value="fixed"'+(im==='fixed'?' selected':'')+'>指定文字</option></select></div>';
|
||||
h+='<div class="form-group" data-mode="random" style="display:'+((!fromPlan&&im==='random')?'block':'none')+'"><label>候选文字(每行一个,随机选一条)</label><textarea class="form-control" data-key="texts" rows="4" style="font-family:monospace;min-height:80px">'+esc(p.texts||'你好\n有趣\n支持')+'</textarea></div>';
|
||||
h+='<div class="form-group" data-mode="fixed" style="display:'+((!fromPlan&&im==='fixed')?'block':'none')+'"><label>指定文字</label><input type="text" class="form-control" data-key="fixed_text" value="'+esc(p.fixed_text||'')+'"></div>';
|
||||
h+='<div class="form-group" data-mode="random" style="display:'+((!autoSource&&im==='random')?'block':'none')+'"><label>候选文字(每行一个,随机选一条)</label><textarea class="form-control" data-key="texts" rows="4" style="font-family:monospace;min-height:80px">'+esc(p.texts||'你好\n有趣\n支持')+'</textarea></div>';
|
||||
h+='<div class="form-group" data-mode="fixed" style="display:'+((!autoSource&&im==='fixed')?'block':'none')+'"><label>指定文字</label><input type="text" class="form-control" data-key="fixed_text" value="'+esc(p.fixed_text||'')+'"></div>';
|
||||
h+='<div class="form-group form-check"><input type="checkbox" data-key="clear_first" '+(p.clear_first!==false?'checked':'')+'><label>输入前先清空</label></div>';
|
||||
h+='<div class="help">需先用"点击元素"步骤定位到输入框,本步骤只负责输入文字</div>';
|
||||
}else if(step.type==='loop'){
|
||||
@@ -582,6 +591,11 @@ var _stepEditor={
|
||||
h+='<div class="form-row"><div class="form-group"><label>最多跑几个号(0=不限)</label><input type="number" class="form-control" data-key="max_accounts" value="'+(p.max_accounts||0)+'" min="0"></div>'+
|
||||
'<div class="form-group form-check" style="align-self:end"><input type="checkbox" data-key="retry_failed" '+(p.retry_failed!==false?'checked':'')+'><label>失败过的也再试</label></div></div>';
|
||||
h+='<div class="help">一轮把本机<b>待发的号</b>跑完:逐个把名字写进"本次要发的名字",执行下方子步骤(切号 → 读名字 → 校验 → 推送 → 发布 → 标记);<b>试过的不回头</b>,跑完/被停/超时/到上限就收工。数据源是<b>计划表</b>(谁还有待发内容谁就在里面),不需要任何账号维护。</div>';
|
||||
}else if(step.type==='foreach_comment'){
|
||||
h+='<div class="form-row"><div class="form-group"><label>最多评论几条(0=不限)</label><input type="number" class="form-control" data-key="max_items" value="'+(p.max_items||0)+'" min="0"></div>'+
|
||||
'<div class="form-group form-check" style="align-self:end"><input type="checkbox" data-key="retry_failed" '+(p.retry_failed!==false?'checked':'')+'><label>失败过的也再试</label></div></div>';
|
||||
h+='<div class="form-group form-check"><input type="checkbox" data-key="stop_on_miss" '+(p.stop_on_miss!==false?'checked':'')+'><label>子步骤未命中就停止本账号</label></div>';
|
||||
h+='<div class="help">按<b>当前账号</b>从「计划调度 → 评论数据」里取一条待评论,把链接/评论内容写进 <code>{comment_url}</code> / <code>{comment_text}</code>,然后跑子步骤。子步骤末尾要放「标记评论完成」;没标记会按 <b>unknown</b>(可能已发)处理,不自动重试。</div>';
|
||||
}else if(step.type==='group'){
|
||||
h+='<div class="help">动作组:按顺序执行下方子步骤一次。把多个步骤打包成一个可复用的整体。</div>';
|
||||
h+='<div class="form-group"><button class="btn btn-xs btn-primary" onclick="_stepEditor.saveAsCustomAction(\''+esc(step.id||'')+'\')">存为自定义动作</button> <span class="help" style="display:inline">把本组步骤保存到左侧自定义动作库,方便复用</span></div>';
|
||||
@@ -668,6 +682,12 @@ var _stepEditor={
|
||||
+'两处各配一遍的话,一边填了另一边忘了去重就会失效。'
|
||||
+'<br>没有前置去重检查、又留空时,退回用<b>本设备</b>当身份(一号一机场景)。'
|
||||
+'<br>有效期在上方任务级的<b>「去重有效期」</b>里设。</div>');
|
||||
}else if(step.type==='mark_comment'){
|
||||
h+='<div class="form-row"><div class="form-group"><label>结果</label><select class="form-control" data-key="result">'+
|
||||
[['done','done(确认发出)'],['failed','failed(确定没发,可重试)'],['unknown','unknown(可能已发,人工裁决)']]
|
||||
.map(function(o){return '<option value="'+o[0]+'"'+((p.result||'done')===o[0]?' selected':'')+'>'+esc(o[1])+'</option>';}).join('')+
|
||||
'</select></div><div class="form-group"><label>原因(可选)</label><input type="text" class="form-control" data-key="why" value="'+esc(p.why||'')+'"></div></div>';
|
||||
h+='<div class="help">放在评论流程末尾:确认发出选 done;确定没走到发送(例如视频没打开)选 failed;点了发送但拿不准选 unknown。unknown 不会被下一次计划自动重试。</div>';
|
||||
}
|
||||
// 共享:触发概率(所有步骤通用,0~100)
|
||||
h+='<div class="form-row" style="margin-top:8px"><div class="form-group"><label>触发概率(%)</label><input type="number" class="form-control" data-key="probability" value="'+(p.probability!=null?p.probability:100)+'" min="0" max="100"><div class="help">0~100,<100 表示按概率执行(如 30=隔几次才触发一次,适合"偶尔点赞")</div></div></div>';
|
||||
@@ -1002,7 +1022,10 @@ var _stepEditor={
|
||||
var input=box.querySelector('input[data-key],textarea[data-key]')||box.querySelector('input,textarea');
|
||||
if(!input){return;}
|
||||
var items=[['{本次要发的名字}','本轮要发的那个号(循环块给的)'],
|
||||
['{本机账号名字}','读到的本机账号(读取文字/读取本机账号名字)']];
|
||||
['{本机账号名字}','读到的本机账号(读取文字/读取本机账号名字)'],
|
||||
['{comment_url}','当前这条评论的视频链接(循环评论给的)'],
|
||||
['{comment_share_text}','当前评论的原始分享文本(给抖音识别用)'],
|
||||
['{comment_text}','当前账号要发的评论内容(循环评论给的)']];
|
||||
var menu=document.createElement('div');
|
||||
menu.id='_varMenu';
|
||||
menu.style.cssText='position:fixed;z-index:9999;background:#fff;border:1px solid #d0d5dd;'
|
||||
|
||||
Reference in New Issue
Block a user