新增定时任务
This commit is contained in:
+124
-1
@@ -243,7 +243,46 @@
|
||||
</div>
|
||||
<div class="bl-tip">任务下发后客户端 5 秒内认领执行;同类型任务未结束前不能重复下发。</div>
|
||||
|
||||
<!-- 定时任务(每日自动:到点下发开始,到结束时间自动停止) -->
|
||||
<div style="font-size:14px;font-weight:600;color:#1890ff;margin:18px 4px 10px;">定时任务(每日自动)</div>
|
||||
<div class="bl-add" style="flex-wrap:wrap;align-items:flex-end;">
|
||||
<div style="min-width:130px;"><label style="font-size:12px;color:#666;">任务类型</label>
|
||||
<select id="schKind" style="width:100%;padding:9px 10px;border:1px solid #d9d9d9;border-radius:6px;">
|
||||
<option value="apply">自动投递</option>
|
||||
<option value="activate">Boss 激活</option>
|
||||
</select></div>
|
||||
<div style="min-width:120px;"><label style="font-size:12px;color:#666;">每日开始时间</label>
|
||||
<input type="time" id="schStart" value="09:00" style="width:100%;padding:8px 10px;border:1px solid #d9d9d9;border-radius:6px;"></div>
|
||||
<div style="min-width:120px;"><label style="font-size:12px;color:#666;">每日结束时间</label>
|
||||
<input type="time" id="schEnd" value="18:00" style="width:100%;padding:8px 10px;border:1px solid #d9d9d9;border-radius:6px;"></div>
|
||||
<button id="btnSchAdd" style="background:#1890ff;">添加排程</button>
|
||||
</div>
|
||||
<!-- Boss 激活专属参数(任务类型=激活时显示;自动投递使用上方投递表单的条件) -->
|
||||
<div class="bl-add hidden" id="schActParams" style="flex-wrap:wrap;align-items:flex-end;">
|
||||
<div style="flex:2;min-width:220px;"><label style="font-size:12px;color:#666;">匹配条件文本</label>
|
||||
<input type="text" id="schMatch" placeholder="与对方最后一条消息比对,如:Python开发" style="width:100%;padding:9px 10px;border:1px solid #d9d9d9;border-radius:6px;"></div>
|
||||
<div style="min-width:110px;"><label style="font-size:12px;color:#666;">消息状态</label>
|
||||
<select id="schStatus" style="width:100%;padding:9px 10px;border:1px solid #d9d9d9;border-radius:6px;">
|
||||
<option value="unread" selected>仅未读</option>
|
||||
<option value="read">仅已读</option>
|
||||
<option value="all">不限</option>
|
||||
</select></div>
|
||||
<div style="width:100px;"><label style="font-size:12px;color:#666;">匹配阈值</label>
|
||||
<input type="number" id="schThreshold" value="80" min="0" max="100" style="width:100%;padding:9px 10px;border:1px solid #d9d9d9;border-radius:6px;"></div>
|
||||
<div style="flex:2;min-width:220px;"><label style="font-size:12px;color:#666;">激活消息</label>
|
||||
<input type="text" id="schReply" placeholder="命中后发送的消息内容" style="width:100%;padding:9px 10px;border:1px solid #d9d9d9;border-radius:6px;"></div>
|
||||
<div style="width:130px;"><label style="font-size:12px;color:#666;">发送上限(0=不限)</label>
|
||||
<input type="number" id="schMax" value="20" min="0" style="width:100%;padding:9px 10px;border:1px solid #d9d9d9;border-radius:6px;"></div>
|
||||
<label style="display:flex;align-items:center;gap:4px;font-size:13px;padding-bottom:10px;"><input type="checkbox" id="schDry"> 试跑(只识别不发送)</label>
|
||||
</div>
|
||||
<div class="bl-tip">自动投递使用上方投递表单的条件;结束时间到点自动下发停止任务;客户端离线时任务 10 分钟未认领自动过期;每条排程每天各触发一次开始/结束。</div>
|
||||
<table>
|
||||
<thead><tr><th style="width:50px">#</th><th style="width:90px">类型</th><th style="width:90px">每日开始</th><th style="width:90px">每日结束</th><th style="width:70px">状态</th><th>最近调度</th><th style="width:130px">操作</th></tr></thead>
|
||||
<tbody id="schTbody"></tbody>
|
||||
</table>
|
||||
<div class="empty hidden" id="schEmpty">暂无定时任务</div>
|
||||
|
||||
<table style="margin-top:18px;">
|
||||
<thead><tr><th style="width:150px">时间</th><th style="width:100px">类型</th><th style="width:90px">状态</th><th>结果</th></tr></thead>
|
||||
<tbody id="taskTbody"></tbody>
|
||||
</table>
|
||||
@@ -434,7 +473,7 @@ async function removeBlacklist(id) {
|
||||
}
|
||||
|
||||
/* ---------- 远程控制 ---------- */
|
||||
const TASK_TXT = { start_apply: '开始投递', stop_apply: '结束投递' };
|
||||
const TASK_TXT = { start_apply: '开始投递', stop_apply: '结束投递', start_activate: '开始激活', stop_activate: '停止激活' };
|
||||
const TASK_STATUS_TXT = { pending: '待认领', running: '执行中', done: '已完成', failed: '失败', expired: '已过期' };
|
||||
|
||||
async function loadRemote() {
|
||||
@@ -463,6 +502,67 @@ async function loadRemote() {
|
||||
).join('');
|
||||
document.getElementById('taskEmpty').classList.toggle('hidden', items.length > 0);
|
||||
} catch (e) { /* ignore */ }
|
||||
loadSchedules();
|
||||
}
|
||||
|
||||
/* ---------- 定时任务排程 ---------- */
|
||||
const SCH_KIND_TXT = { apply: '自动投递', activate: 'Boss 激活' };
|
||||
|
||||
async function loadSchedules() {
|
||||
try {
|
||||
const d = await api('/api/rpa/schedules');
|
||||
const items = d.items || [];
|
||||
document.getElementById('schTbody').innerHTML = items.map(s =>
|
||||
'<tr><td>' + s.id + '</td><td>' + (SCH_KIND_TXT[s.kind] || esc(s.kind)) + '</td><td>' + esc(s.start_time) +
|
||||
'</td><td>' + esc(s.end_time) + '</td><td>' +
|
||||
(s.enabled ? '<span style="color:#52c41a;">启用</span>' : '<span style="color:#999;">停用</span>') +
|
||||
'</td><td class="remark" title="' + esc(s.last_result || '') + '">' + esc(s.last_result || '-') +
|
||||
'</td><td><button class="bl-remove sch-toggle" data-id="' + s.id + '" data-enabled="' + (s.enabled ? 0 : 1) + '">' +
|
||||
(s.enabled ? '停用' : '启用') + '</button> <button class="bl-remove sch-del" data-id="' + s.id + '" style="color:#e64340;">删除</button></td></tr>'
|
||||
).join('');
|
||||
document.getElementById('schEmpty').classList.toggle('hidden', items.length > 0);
|
||||
} catch (e) { /* 401 已在 api 内处理 */ }
|
||||
}
|
||||
|
||||
async function addSchedule() {
|
||||
const kind = document.getElementById('schKind').value;
|
||||
const startTime = document.getElementById('schStart').value;
|
||||
const endTime = document.getElementById('schEnd').value;
|
||||
if (!startTime || !endTime) { alert('请选择开始/结束时间'); return; }
|
||||
let params;
|
||||
if (kind === 'apply') {
|
||||
// 复用页面上方投递表单的条件(与手动开始投递同一套参数)
|
||||
const keywords = (document.getElementById('rKeywords').value || '').split(/[,,\s]+/).filter(Boolean);
|
||||
if (!keywords.length) { alert('自动投递需先在上方表单填写搜索关键词'); return; }
|
||||
params = {
|
||||
keywords,
|
||||
city: document.getElementById('rCity').value,
|
||||
min_score: parseInt(document.getElementById('rScore').value, 10) || 65,
|
||||
salary_min: parseInt(document.getElementById('rSalaryMin').value, 10) || 0,
|
||||
salary_max: parseInt(document.getElementById('rSalaryMax').value, 10) || 0,
|
||||
daily_limit: parseInt(document.getElementById('rLimit').value, 10) || 0,
|
||||
boss_online_only: document.getElementById('rOnlineOnly').checked,
|
||||
allow_headhunter: document.getElementById('rHunter').checked,
|
||||
prompt: document.getElementById('rPrompt').value.trim() || null,
|
||||
};
|
||||
} else {
|
||||
params = {
|
||||
match_text: document.getElementById('schMatch').value.trim(),
|
||||
status_filter: document.getElementById('schStatus').value,
|
||||
threshold: parseInt(document.getElementById('schThreshold').value, 10) || 80,
|
||||
reply_message: document.getElementById('schReply').value.trim(),
|
||||
max_count: parseInt(document.getElementById('schMax').value, 10) || 0,
|
||||
dry_run: document.getElementById('schDry').checked,
|
||||
};
|
||||
if (!params.match_text) { alert('Boss 激活需填写匹配条件文本'); return; }
|
||||
if (!params.reply_message) { alert('Boss 激活需填写激活消息'); return; }
|
||||
}
|
||||
try {
|
||||
await api('/api/rpa/schedules', { method: 'POST', body: JSON.stringify({
|
||||
kind, start_time: startTime, end_time: endTime, params,
|
||||
})});
|
||||
await loadSchedules();
|
||||
} catch (e) { alert('添加失败:' + (e.message || '')); }
|
||||
}
|
||||
|
||||
async function sendTask(taskType, params) {
|
||||
@@ -612,6 +712,29 @@ document.getElementById('btnStopRemote').onclick = () => {
|
||||
};
|
||||
document.getElementById('btnAiSave').onclick = saveAiConfig;
|
||||
document.getElementById('btnAiTest').onclick = testAiConfig;
|
||||
// 定时任务:类型切换显隐激活参数区 + 添加/启停/删除
|
||||
document.getElementById('schKind').addEventListener('change', () => {
|
||||
document.getElementById('schActParams').classList.toggle('hidden',
|
||||
document.getElementById('schKind').value !== 'activate');
|
||||
});
|
||||
document.getElementById('btnSchAdd').onclick = addSchedule;
|
||||
document.getElementById('schTbody').addEventListener('click', async e => {
|
||||
const tog = e.target.closest('.sch-toggle');
|
||||
if (tog) {
|
||||
try {
|
||||
await api('/api/rpa/schedules/' + tog.dataset.id + '?enabled=' + tog.dataset.enabled, { method: 'PUT' });
|
||||
await loadSchedules();
|
||||
} catch (err) { alert('操作失败:' + (err.message || '')); }
|
||||
return;
|
||||
}
|
||||
const del = e.target.closest('.sch-del');
|
||||
if (del && confirm('确定删除该定时任务?删除后不再自动调度。')) {
|
||||
try {
|
||||
await api('/api/rpa/schedules/' + del.dataset.id, { method: 'DELETE' });
|
||||
await loadSchedules();
|
||||
} catch (err) { alert('删除失败:' + (err.message || '')); }
|
||||
}
|
||||
});
|
||||
document.getElementById('blTbody').addEventListener('click', e => {
|
||||
const btn = e.target.closest('.bl-remove');
|
||||
if (btn) removeBlacklist(btn.dataset.id);
|
||||
|
||||
Reference in New Issue
Block a user