529 lines
26 KiB
HTML
529 lines
26 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>投递数据中心</title>
|
||
<style>
|
||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
body { font-family: "Microsoft YaHei", sans-serif; background: #f0f4f8; color: #333; }
|
||
.hidden { display: none !important; }
|
||
|
||
/* 登录页 */
|
||
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
|
||
.login-box { background: #fff; padding: 36px 40px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.08); width: 360px; }
|
||
.login-box h1 { font-size: 20px; text-align: center; margin-bottom: 24px; color: #1890ff; }
|
||
.login-box input { width: 100%; padding: 10px 12px; margin-bottom: 14px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; }
|
||
.login-box button { width: 100%; padding: 11px; background: #1890ff; color: #fff; border: none; border-radius: 6px; font-size: 15px; cursor: pointer; }
|
||
.login-box button:hover { background: #40a9ff; }
|
||
.login-err { color: #e64340; font-size: 13px; margin-bottom: 10px; min-height: 18px; }
|
||
|
||
/* 顶栏 */
|
||
header { background: #fff; padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
|
||
header h1 { font-size: 18px; color: #1890ff; }
|
||
header .ops { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #666; }
|
||
header button { padding: 6px 14px; border: 1px solid #d9d9d9; background: #fff; border-radius: 6px; cursor: pointer; font-size: 13px; }
|
||
header button:hover { border-color: #1890ff; color: #1890ff; }
|
||
|
||
/* 左菜单 + 右内容布局 */
|
||
.layout { display: flex; max-width: 1200px; margin: 24px auto; padding: 0 16px; gap: 16px; align-items: flex-start; }
|
||
aside { width: 170px; flex-shrink: 0; background: #fff; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.05); overflow: hidden; }
|
||
aside .menu-item { display: block; padding: 14px 20px; font-size: 14px; color: #555; cursor: pointer; border-left: 3px solid transparent; }
|
||
aside .menu-item:hover { background: #f7fbff; }
|
||
aside .menu-item.active { background: #e8f4ff; color: #1890ff; border-left-color: #1890ff; font-weight: 600; }
|
||
.content { flex: 1; min-width: 0; }
|
||
|
||
/* 筛选栏 */
|
||
.filters { background: #fff; border-radius: 10px; padding: 14px 18px; box-shadow: 0 2px 8px rgba(0,0,0,.05); margin-bottom: 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; font-size: 13px; }
|
||
.filters .grp { display: flex; align-items: center; gap: 8px; }
|
||
.filters .grp > label.t { color: #888; }
|
||
.chip { padding: 5px 14px; border: 1px solid #d9d9d9; border-radius: 16px; cursor: pointer; color: #555; background: #fff; font-size: 13px; }
|
||
.chip:hover { border-color: #1890ff; color: #1890ff; }
|
||
.chip.active { background: #1890ff; border-color: #1890ff; color: #fff; }
|
||
.filters input[type=date] { padding: 4px 8px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 13px; }
|
||
.filters .btn-query { padding: 5px 16px; background: #1890ff; border: none; color: #fff; border-radius: 6px; cursor: pointer; font-size: 13px; }
|
||
.filters select { padding: 4px 8px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 13px; }
|
||
|
||
/* 统计卡 */
|
||
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
|
||
.stat-card { background: #fff; border-radius: 10px; padding: 18px 22px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
|
||
.stat-card .num { font-size: 30px; font-weight: 700; }
|
||
.stat-card .label { font-size: 13px; color: #888; margin-top: 4px; }
|
||
.num.green { color: #52c41a; } .num.orange { color: #faad14; } .num.blue { color: #1890ff; }
|
||
|
||
table { width: 100%; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.05); border-collapse: collapse; font-size: 13px; }
|
||
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #f0f0f0; }
|
||
th { background: #fafafa; color: #666; font-weight: 600; }
|
||
tr:hover td { background: #f7fbff; }
|
||
.badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 12px; }
|
||
.badge.chat, .badge.deliver { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
|
||
.badge.skipped { background: #fff7e6; color: #faad14; border: 1px solid #ffd591; }
|
||
.score-high { color: #52c41a; font-weight: 700; } .score-mid { color: #faad14; font-weight: 700; } .score-low { color: #e64340; font-weight: 700; }
|
||
.remark { color: #999; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||
.empty { text-align: center; padding: 40px; color: #999; background: #fff; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
|
||
|
||
/* 分页 */
|
||
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; font-size: 13px; color: #666; }
|
||
.pager button { padding: 5px 14px; border: 1px solid #d9d9d9; background: #fff; border-radius: 6px; cursor: pointer; font-size: 13px; }
|
||
.pager button:hover:not(:disabled) { border-color: #1890ff; color: #1890ff; }
|
||
.pager button:disabled { color: #ccc; cursor: not-allowed; }
|
||
|
||
/* 快捷拉黑按钮 */
|
||
.bl-btn { border: 1px solid #ffd6d6; background: #fff; color: #e64340; border-radius: 4px; font-size: 12px; padding: 1px 8px; cursor: pointer; margin-left: 6px; }
|
||
.bl-btn:hover { background: #fff1f0; }
|
||
|
||
/* 黑名单页 */
|
||
.bl-add { display: flex; gap: 10px; background: #fff; border-radius: 10px; padding: 16px 18px; box-shadow: 0 2px 8px rgba(0,0,0,.05); margin-bottom: 16px; }
|
||
.bl-add input { flex: 1; padding: 9px 12px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; }
|
||
.bl-add button { padding: 9px 22px; background: #e64340; color: #fff; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; }
|
||
.bl-add button:hover { background: #f06e6b; }
|
||
.bl-tip { font-size: 12px; color: #999; margin: 0 4px 12px; }
|
||
.bl-remove { border: 1px solid #d9d9d9; background: #fff; border-radius: 4px; font-size: 12px; padding: 2px 10px; cursor: pointer; }
|
||
.bl-remove:hover { border-color: #e64340; color: #e64340; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<!-- 登录 -->
|
||
<div class="login-wrap" id="loginView">
|
||
<div class="login-box">
|
||
<h1>投递数据中心 · 登录</h1>
|
||
<div class="login-err" id="loginErr"></div>
|
||
<input type="text" id="username" placeholder="用户名" autocomplete="username">
|
||
<input type="password" id="password" placeholder="密码" autocomplete="current-password">
|
||
<button id="btnLogin">登 录</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 数据 -->
|
||
<div id="dataView" class="hidden">
|
||
<header>
|
||
<h1>投递数据中心</h1>
|
||
<div class="ops">
|
||
<span id="who"></span>
|
||
<span id="updatedAt"></span>
|
||
<button id="btnLogout">退出</button>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="layout">
|
||
<!-- 左侧菜单 -->
|
||
<aside>
|
||
<div class="menu-item active" data-page="data">投递数据</div>
|
||
<div class="menu-item" data-page="blacklist">公司黑名单</div>
|
||
<div class="menu-item" data-page="remote">远程控制</div>
|
||
</aside>
|
||
|
||
<!-- 右侧内容 -->
|
||
<div class="content">
|
||
<!-- 投递数据(筛选 + 分页) -->
|
||
<div id="pageData">
|
||
<div class="filters">
|
||
<div class="grp">
|
||
<label class="t">时间:</label>
|
||
<span class="chip active" data-range="today">今日</span>
|
||
<span class="chip" data-range="week">本周</span>
|
||
<span class="chip" data-range="month">本月</span>
|
||
<span class="chip" data-range="custom">自定义</span>
|
||
<span id="customRange" class="hidden">
|
||
<input type="date" id="dateStart"> ~ <input type="date" id="dateEnd">
|
||
<button class="btn-query" id="btnQuery">查询</button>
|
||
</span>
|
||
</div>
|
||
<div class="grp">
|
||
<label class="t">结果:</label>
|
||
<span class="chip active" data-type="">全部</span>
|
||
<span class="chip" data-type="chat">已沟通</span>
|
||
<span class="chip" data-type="deliver">已投递</span>
|
||
<span class="chip" data-type="skipped">已跳过</span>
|
||
</div>
|
||
<div class="grp">
|
||
<label class="t">每页:</label>
|
||
<select id="pageSize">
|
||
<option value="20" selected>20</option>
|
||
<option value="50">50</option>
|
||
<option value="100">100</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="stats">
|
||
<div class="stat-card"><div class="num green" id="stApplied">0</div><div class="label">已投递(筛选范围)</div></div>
|
||
<div class="stat-card"><div class="num orange" id="stSkipped">0</div><div class="label">已跳过(筛选范围)</div></div>
|
||
<div class="stat-card"><div class="num blue" id="stTotal">0</div><div class="label">处理总数(筛选范围)</div></div>
|
||
</div>
|
||
|
||
<table>
|
||
<thead><tr>
|
||
<th>时间</th><th>职位</th><th>公司</th><th>薪资</th><th>结果</th><th>AI评分</th><th>备注</th>
|
||
</tr></thead>
|
||
<tbody id="tbody"></tbody>
|
||
</table>
|
||
<div class="empty hidden" id="empty">该筛选条件下没有投递记录</div>
|
||
|
||
<div class="pager">
|
||
<span id="pageInfo"></span>
|
||
<button id="btnPrev">上一页</button>
|
||
<button id="btnNext">下一页</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 公司黑名单 -->
|
||
<div id="pageBlacklist" class="hidden">
|
||
<div class="bl-add">
|
||
<input type="text" id="blCompany" placeholder="输入公司名,如:某某科技有限公司" maxlength="128">
|
||
<button id="btnBlAdd">拉黑</button>
|
||
</div>
|
||
<div class="bl-tip">拉黑后,投递任务将自动跳过该公司的所有职位;在「投递数据」的公司列也可快捷拉黑。</div>
|
||
<table>
|
||
<thead><tr><th style="width:60px">#</th><th>公司名</th><th style="width:170px">拉黑时间</th><th style="width:90px">操作</th></tr></thead>
|
||
<tbody id="blTbody"></tbody>
|
||
</table>
|
||
<div class="empty hidden" id="blEmpty">黑名单为空</div>
|
||
|
||
<div class="pager">
|
||
<span id="blPageInfo"></span>
|
||
<button id="blPrev">上一页</button>
|
||
<button id="blNext">下一页</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 远程控制 -->
|
||
<div id="pageRemote" class="hidden">
|
||
<div class="stats" id="remoteStatus">
|
||
<div class="stat-card"><div class="num" id="rsOnline">-</div><div class="label">客户端在线</div></div>
|
||
<div class="stat-card"><div class="num" id="rsBoss">-</div><div class="label">Boss 登录</div></div>
|
||
<div class="stat-card"><div class="num" id="rsBrowser">-</div><div class="label">浏览器</div></div>
|
||
<div class="stat-card"><div class="num" id="rsApply">-</div><div class="label">投递状态</div></div>
|
||
</div>
|
||
<div class="bl-tip" id="rsDetail">进度:- | 更新:-</div>
|
||
|
||
<div class="bl-add" style="flex-wrap:wrap;">
|
||
<input type="text" id="rKeywords" placeholder="搜索关键词,多个用逗号分隔,如:java,后端" style="flex:2;min-width:220px;">
|
||
<input type="text" id="rCity" placeholder="城市码(如 101010100=北京)" style="flex:1;min-width:150px;">
|
||
<input type="number" id="rScore" placeholder="及格分" value="65" style="width:80px;">
|
||
<input type="number" id="rLimit" placeholder="每日上限(0不限)" value="0" style="width:130px;">
|
||
<label style="display:flex;align-items:center;gap:4px;font-size:13px;"><input type="checkbox" id="rOnlineOnly"> 只投在线Boss</label>
|
||
<label style="display:flex;align-items:center;gap:4px;font-size:13px;"><input type="checkbox" id="rHunter"> 考虑猎头</label>
|
||
<button id="btnStartRemote" style="background:#1890ff;">开始投递</button>
|
||
<button id="btnStopRemote">结束投递</button>
|
||
</div>
|
||
<div class="bl-tip">任务下发后客户端 5 秒内认领执行;同类型任务未结束前不能重复下发。</div>
|
||
|
||
<table>
|
||
<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>
|
||
<div class="empty hidden" id="taskEmpty">暂无远程任务</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
const TOKEN_KEY = 'view_token';
|
||
const token = () => localStorage.getItem(TOKEN_KEY);
|
||
let blSet = new Set(); // 当前黑名单公司名集合,用于表格快捷拉黑按钮状态
|
||
|
||
// 查询状态:时间范围 / 结果类型 / 分页
|
||
const state = { range: 'today', start: '', end: '', type: '', page: 1, pageSize: 20 };
|
||
const blState = { page: 1, pageSize: 20 }; // 黑名单分页
|
||
|
||
async function api(path, opts = {}) {
|
||
const resp = await fetch(path, {
|
||
...opts,
|
||
headers: { 'Content-Type': 'application/json',
|
||
...(token() ? { Authorization: 'Bearer ' + token() } : {}),
|
||
...(opts.headers || {}) },
|
||
});
|
||
if (resp.status === 401) { logout(); throw new Error('未登录'); }
|
||
if (!resp.ok) { const d = await resp.json().catch(() => ({})); throw new Error(d.detail || resp.status); }
|
||
return resp.json();
|
||
}
|
||
|
||
function showLogin() {
|
||
document.getElementById('loginView').classList.remove('hidden');
|
||
document.getElementById('dataView').classList.add('hidden');
|
||
}
|
||
function showData() {
|
||
document.getElementById('loginView').classList.add('hidden');
|
||
document.getElementById('dataView').classList.remove('hidden');
|
||
}
|
||
function logout() {
|
||
localStorage.removeItem(TOKEN_KEY);
|
||
showLogin();
|
||
}
|
||
|
||
async function login() {
|
||
const errEl = document.getElementById('loginErr');
|
||
errEl.textContent = '';
|
||
try {
|
||
const d = await api('/api/auth/login', {
|
||
method: 'POST',
|
||
body: JSON.stringify({
|
||
username: document.getElementById('username').value.trim(),
|
||
password: document.getElementById('password').value,
|
||
}),
|
||
});
|
||
localStorage.setItem(TOKEN_KEY, d.token);
|
||
enter();
|
||
} catch (e) { errEl.textContent = e.message || '登录失败'; }
|
||
}
|
||
|
||
function esc(s) {
|
||
const div = document.createElement('div');
|
||
div.textContent = s == null ? '' : String(s);
|
||
return div.innerHTML;
|
||
}
|
||
|
||
/* ---------- 日期工具(本地时区即北京时间) ---------- */
|
||
function fmt(d) {
|
||
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0')
|
||
+ '-' + String(d.getDate()).padStart(2, '0');
|
||
}
|
||
function rangeDates() {
|
||
const now = new Date(), today = fmt(now);
|
||
if (state.range === 'today') return [today, today];
|
||
if (state.range === 'week') {
|
||
const d = new Date(now); d.setDate(d.getDate() - ((d.getDay() + 6) % 7)); // 周一
|
||
return [fmt(d), today];
|
||
}
|
||
if (state.range === 'month') {
|
||
return [fmt(new Date(now.getFullYear(), now.getMonth(), 1)), today];
|
||
}
|
||
return [state.start, state.end]; // 自定义
|
||
}
|
||
|
||
/* ---------- 投递数据 ---------- */
|
||
async function load() {
|
||
try {
|
||
const [start, end] = rangeDates();
|
||
if (state.range === 'custom' && (!start || !end)) return;
|
||
const params = new URLSearchParams({ page: state.page, page_size: state.pageSize });
|
||
if (start) params.set('start', start);
|
||
if (end) params.set('end', end);
|
||
if (state.type) params.set('apply_type', state.type);
|
||
|
||
const [me, d] = await Promise.all([api('/api/auth/me'), api('/api/jobs/page?' + params)]);
|
||
document.getElementById('who').textContent = me.nickname || me.username;
|
||
document.getElementById('stApplied').textContent = d.applied;
|
||
document.getElementById('stSkipped').textContent = d.skipped;
|
||
document.getElementById('stTotal').textContent = d.total;
|
||
document.getElementById('updatedAt').textContent =
|
||
'更新于 ' + new Date().toLocaleTimeString('zh-CN', { hour12: false });
|
||
|
||
const tbody = document.getElementById('tbody');
|
||
tbody.innerHTML = (d.items || []).map(r => {
|
||
const type = r.apply_type === 'skipped'
|
||
? '<span class="badge skipped">跳过</span>'
|
||
: '<span class="badge ' + r.apply_type + '">' + (r.apply_type === 'chat' ? '已沟通' : '已投递') + '</span>';
|
||
const score = r.ai_score == null || r.ai_score < 0 ? '-'
|
||
: '<span class="' + (r.ai_score >= 80 ? 'score-high' : r.ai_score >= 60 ? 'score-mid' : 'score-low') + '">' + r.ai_score + '</span>';
|
||
const remark = r.apply_type === 'skipped' ? (r.skip_reason || '') : (r.ai_reason || '');
|
||
const company = r.company || '';
|
||
const blBtn = (company && !blSet.has(company))
|
||
? '<button class="bl-btn" data-company="' + esc(company) + '">拉黑</button>' : '';
|
||
return '<tr><td>' + esc(r.applied_at) + '</td><td>' + esc(r.job_title) + '</td><td>' + esc(company) + blBtn +
|
||
'</td><td>' + esc(r.salary) + '</td><td>' + type + '</td><td>' + score +
|
||
'</td><td class="remark" title="' + esc(remark) + '">' + esc(remark) + '</td></tr>';
|
||
}).join('');
|
||
document.getElementById('empty').classList.toggle('hidden', (d.items || []).length > 0);
|
||
|
||
// 分页状态
|
||
document.getElementById('pageInfo').textContent =
|
||
'共 ' + d.total + ' 条 · 第 ' + d.page + ' / ' + Math.max(d.pages, 1) + ' 页';
|
||
document.getElementById('btnPrev').disabled = d.page <= 1;
|
||
document.getElementById('btnNext').disabled = d.page >= d.pages;
|
||
} catch (e) { /* 401 已在 api 内处理 */ }
|
||
}
|
||
|
||
/* ---------- 公司黑名单 ---------- */
|
||
async function loadBlacklist() {
|
||
try {
|
||
const d = await api('/api/blacklist?page=' + blState.page + '&page_size=' + blState.pageSize);
|
||
const items = d.items || [];
|
||
blSet = new Set(items.map(i => i.company));
|
||
const tbody = document.getElementById('blTbody');
|
||
tbody.innerHTML = items.map((i, idx) =>
|
||
'<tr><td>' + ((d.page - 1) * d.page_size + idx + 1) + '</td><td>' + esc(i.company) + '</td><td>' + esc(i.created_at) +
|
||
'</td><td><button class="bl-remove" data-id="' + i.id + '">移除</button></td></tr>'
|
||
).join('');
|
||
document.getElementById('blEmpty').classList.toggle('hidden', items.length > 0);
|
||
document.getElementById('blPageInfo').textContent =
|
||
'共 ' + d.total + ' 条 · 第 ' + d.page + ' / ' + Math.max(d.pages, 1) + ' 页';
|
||
document.getElementById('blPrev').disabled = d.page <= 1;
|
||
document.getElementById('blNext').disabled = d.page >= d.pages;
|
||
return d;
|
||
} catch (e) { /* 401 已在 api 内处理 */ }
|
||
}
|
||
|
||
async function addBlacklist(company) {
|
||
company = (company || '').trim();
|
||
if (!company) return;
|
||
try {
|
||
await api('/api/blacklist', { method: 'POST', body: JSON.stringify({ company }) });
|
||
blState.page = 1; // 新拉黑按时间倒序排第一,回到首页才能看到
|
||
await loadBlacklist();
|
||
await load(); // 刷新快捷拉黑按钮状态
|
||
alert('已拉黑:' + company + ',后续不再投递该公司');
|
||
} catch (e) { alert('拉黑失败:' + (e.message || '')); }
|
||
}
|
||
|
||
async function removeBlacklist(id) {
|
||
try {
|
||
await api('/api/blacklist/' + id, { method: 'DELETE' });
|
||
const d = await loadBlacklist();
|
||
// 删掉末页最后一条时当前页会超出总页数,退回上一页
|
||
if (d && d.page > d.pages && d.pages >= 1) { blState.page = d.pages; await loadBlacklist(); }
|
||
} catch (e) { alert('移除失败:' + (e.message || '')); }
|
||
}
|
||
|
||
/* ---------- 远程控制 ---------- */
|
||
const TASK_TXT = { start_apply: '开始投递', stop_apply: '结束投递' };
|
||
const TASK_STATUS_TXT = { pending: '待认领', running: '执行中', done: '已完成', failed: '失败', expired: '已过期' };
|
||
|
||
async function loadRemote() {
|
||
try {
|
||
const st = await api('/api/rpa/status');
|
||
const put = (id, txt, cls) => {
|
||
const el = document.getElementById(id);
|
||
el.textContent = txt;
|
||
el.className = 'num ' + (cls || '');
|
||
};
|
||
put('rsOnline', st.online ? '在线' : '离线', st.online ? 'green' : 'orange');
|
||
put('rsBoss', st.boss_login === 'logged_in' ? '已登录' : (st.boss_login === 'logging_in' ? '登录中' : '未登录'),
|
||
st.boss_login === 'logged_in' ? 'green' : 'orange');
|
||
put('rsBrowser', st.browser === 'running' ? '运行中' : '已停止', st.browser === 'running' ? 'green' : 'orange');
|
||
put('rsApply', st.apply_status === 'running' ? '运行中' : '空闲', st.apply_status === 'running' ? 'blue' : 'green');
|
||
document.getElementById('rsDetail').textContent =
|
||
'进度:' + (st.apply_status === 'running' ? (st.current || '-') + ' 投' + st.applied + '/跳' + st.skipped : '-') +
|
||
' | 状态更新:' + (st.updated_at || '-');
|
||
} catch (e) { /* 401 已在 api 内处理 */ }
|
||
try {
|
||
const d = await api('/api/rpa/tasks?limit=15');
|
||
const items = d.items || [];
|
||
document.getElementById('taskTbody').innerHTML = items.map(t =>
|
||
'<tr><td>' + esc(t.created_at) + '</td><td>' + (TASK_TXT[t.task_type] || t.task_type) + '</td><td>' +
|
||
(TASK_STATUS_TXT[t.status] || t.status) + '</td><td>' + esc(t.result || '-') + '</td></tr>'
|
||
).join('');
|
||
document.getElementById('taskEmpty').classList.toggle('hidden', items.length > 0);
|
||
} catch (e) { /* ignore */ }
|
||
}
|
||
|
||
async function sendTask(taskType, params) {
|
||
try {
|
||
await api('/api/rpa/tasks', { method: 'POST', body: JSON.stringify({ task_type: taskType, params }) });
|
||
await loadRemote();
|
||
} catch (e) { alert('下发失败:' + (e.message || '')); }
|
||
}
|
||
|
||
/* ---------- 页面切换 ---------- */
|
||
function switchPage(page) {
|
||
document.querySelectorAll('aside .menu-item').forEach(el =>
|
||
el.classList.toggle('active', el.dataset.page === page));
|
||
document.getElementById('pageData').classList.toggle('hidden', page !== 'data');
|
||
document.getElementById('pageBlacklist').classList.toggle('hidden', page !== 'blacklist');
|
||
document.getElementById('pageRemote').classList.toggle('hidden', page !== 'remote');
|
||
if (page === 'data') load(); else if (page === 'blacklist') loadBlacklist(); else loadRemote();
|
||
}
|
||
|
||
/* ---------- 事件绑定 ---------- */
|
||
document.getElementById('btnLogin').onclick = login;
|
||
document.getElementById('password').addEventListener('keydown', e => { if (e.key === 'Enter') login(); });
|
||
document.getElementById('btnLogout').onclick = logout;
|
||
document.querySelectorAll('aside .menu-item').forEach(el =>
|
||
el.addEventListener('click', () => switchPage(el.dataset.page)));
|
||
|
||
// 时间范围切换
|
||
document.querySelectorAll('[data-range]').forEach(el => el.addEventListener('click', () => {
|
||
document.querySelectorAll('[data-range]').forEach(c => c.classList.toggle('active', c === el));
|
||
state.range = el.dataset.range;
|
||
document.getElementById('customRange').classList.toggle('hidden', state.range !== 'custom');
|
||
if (state.range !== 'custom') { state.page = 1; load(); }
|
||
}));
|
||
// 自定义范围查询
|
||
document.getElementById('btnQuery').onclick = () => {
|
||
state.start = document.getElementById('dateStart').value;
|
||
state.end = document.getElementById('dateEnd').value;
|
||
if (!state.start || !state.end) { alert('请选择起止日期'); return; }
|
||
if (state.start > state.end) { alert('起始日期不能晚于结束日期'); return; }
|
||
state.page = 1; load();
|
||
};
|
||
// 结果类型切换
|
||
document.querySelectorAll('[data-type]').forEach(el => el.addEventListener('click', () => {
|
||
document.querySelectorAll('[data-type]').forEach(c => c.classList.toggle('active', c === el));
|
||
state.type = el.dataset.type;
|
||
state.page = 1; load();
|
||
}));
|
||
// 每页条数
|
||
document.getElementById('pageSize').onchange = e => {
|
||
state.pageSize = parseInt(e.target.value, 10);
|
||
state.page = 1; load();
|
||
};
|
||
// 分页
|
||
document.getElementById('btnPrev').onclick = () => { if (state.page > 1) { state.page--; load(); } };
|
||
document.getElementById('btnNext').onclick = () => { state.page++; load(); };
|
||
|
||
// 黑名单操作
|
||
document.getElementById('btnBlAdd').onclick = () => {
|
||
const input = document.getElementById('blCompany');
|
||
addBlacklist(input.value);
|
||
input.value = '';
|
||
};
|
||
document.getElementById('blCompany').addEventListener('keydown', e => {
|
||
if (e.key === 'Enter') document.getElementById('btnBlAdd').click();
|
||
});
|
||
document.getElementById('blPrev').onclick = () => { if (blState.page > 1) { blState.page--; loadBlacklist(); } };
|
||
document.getElementById('blNext').onclick = () => { blState.page++; loadBlacklist(); };
|
||
|
||
// 远程控制
|
||
document.getElementById('btnStartRemote').onclick = () => {
|
||
const keywords = (document.getElementById('rKeywords').value || '').split(/[,,\s]+/).filter(Boolean);
|
||
const cityCode = (document.getElementById('rCity').value || '').trim();
|
||
if (!keywords.length) { alert('请填写搜索关键词'); return; }
|
||
if (!cityCode) { alert('请填写城市码'); return; }
|
||
if (!confirm('确认远程启动投递任务?')) return;
|
||
sendTask('start_apply', {
|
||
keywords, city_code: cityCode,
|
||
min_score: parseInt(document.getElementById('rScore').value, 10) || 65,
|
||
daily_limit: parseInt(document.getElementById('rLimit').value, 10) || 0,
|
||
boss_online_only: document.getElementById('rOnlineOnly').checked,
|
||
allow_headhunter: document.getElementById('rHunter').checked,
|
||
});
|
||
};
|
||
document.getElementById('btnStopRemote').onclick = () => {
|
||
if (!confirm('确认远程结束投递任务?')) return;
|
||
sendTask('stop_apply', null);
|
||
};
|
||
document.getElementById('blTbody').addEventListener('click', e => {
|
||
const btn = e.target.closest('.bl-remove');
|
||
if (btn) removeBlacklist(btn.dataset.id);
|
||
});
|
||
document.getElementById('tbody').addEventListener('click', e => {
|
||
const btn = e.target.closest('.bl-btn');
|
||
if (btn && confirm('确认拉黑公司「' + btn.dataset.company + '」?拉黑后将不再投递该公司。')) {
|
||
addBlacklist(btn.dataset.company);
|
||
}
|
||
});
|
||
|
||
async function enter() {
|
||
showData();
|
||
// 自定义日期默认填入今天
|
||
const today = fmt(new Date());
|
||
document.getElementById('dateStart').value = today;
|
||
document.getElementById('dateEnd').value = today;
|
||
await loadBlacklist();
|
||
await load();
|
||
}
|
||
|
||
if (token()) enter(); else showLogin();
|
||
setInterval(() => {
|
||
if (token() && !document.getElementById('dataView').classList.contains('hidden')) {
|
||
if (!document.getElementById('pageData').classList.contains('hidden')) load();
|
||
if (!document.getElementById('pageRemote').classList.contains('hidden')) loadRemote();
|
||
}
|
||
}, 5000);
|
||
</script>
|
||
</body>
|
||
</html>
|