init
This commit is contained in:
@@ -0,0 +1,310 @@
|
||||
// ==========================================================
|
||||
// Boss直聘 AI 投递 - 控制面板前端逻辑
|
||||
// ==========================================================
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
let currentStep = 1;
|
||||
let loginPollTimer = null;
|
||||
let applyPollTimer = null;
|
||||
|
||||
// ---------- Toast ----------
|
||||
function toast(msg, ms = 3000) {
|
||||
const t = $('toast');
|
||||
t.textContent = msg;
|
||||
t.classList.add('show');
|
||||
setTimeout(() => t.classList.remove('show'), ms);
|
||||
}
|
||||
|
||||
// ---------- 步骤切换 ----------
|
||||
function goToStep(step) {
|
||||
currentStep = step;
|
||||
document.querySelectorAll('.step').forEach(el => {
|
||||
el.classList.toggle('active', parseInt(el.dataset.step) === step);
|
||||
});
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
$(`panel-${i}`).classList.toggle('hidden', i !== step);
|
||||
}
|
||||
if (step === 5) loadHistory();
|
||||
if (step === 3) loadResumes();
|
||||
}
|
||||
document.querySelectorAll('.step').forEach(el => {
|
||||
el.addEventListener('click', () => goToStep(parseInt(el.dataset.step)));
|
||||
});
|
||||
|
||||
// ---------- 通用请求 ----------
|
||||
async function api(path, options = {}) {
|
||||
const res = await fetch(path, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
...options,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({}));
|
||||
throw new Error(err.detail || `请求失败 ${res.status}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
// ---------- 徽章工具 ----------
|
||||
function badge(text, cls) {
|
||||
return `<span class="badge ${cls || ''}">${text}</span>`;
|
||||
}
|
||||
|
||||
// ---------- 初始化状态 ----------
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const s = await api('/api/status');
|
||||
$('clientCode').textContent = s.client_code;
|
||||
$('serverReachable').innerHTML = badge(
|
||||
s.server_reachable ? '可连接' : '无法连接',
|
||||
s.server_reachable ? 'ok' : 'err'
|
||||
);
|
||||
$('adspowerStatus').innerHTML = badge(
|
||||
s.adspower_running ? '运行中' : '未运行',
|
||||
s.adspower_running ? 'ok' : 'warn'
|
||||
);
|
||||
// 顶部徽章
|
||||
$('statusBadges').innerHTML =
|
||||
badge(s.server_connected ? '已连接' : '未连接', s.server_connected ? 'ok' : '') +
|
||||
badge(s.ai_configured ? 'AI已配置' : 'AI未配置', s.ai_configured ? 'ok' : 'warn');
|
||||
|
||||
if (s.server_connected) {
|
||||
updateLoginBadge(s.login_status, s.boss_account);
|
||||
}
|
||||
return s;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function updateLoginBadge(status, account) {
|
||||
const el = $('loginStatus');
|
||||
if (status === 'logged_in') {
|
||||
el.innerHTML = badge(`已登录 ${escapeHtml(account || '')}`, 'ok');
|
||||
} else if (status === 'logging_in') {
|
||||
el.innerHTML = badge('登录中...', 'warn');
|
||||
} else {
|
||||
el.innerHTML = badge('未登录', '');
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
// Step 1: 连接服务端
|
||||
// ==========================================================
|
||||
$('btnConnect').addEventListener('click', async () => {
|
||||
const btn = $('btnConnect');
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const data = await api('/api/connect', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ nickname: $('nickname').value || null }),
|
||||
});
|
||||
toast(data.is_new ? '注册成功!' : '登录成功!');
|
||||
await refreshStatus();
|
||||
goToStep(2);
|
||||
} catch (e) {
|
||||
toast('连接失败:' + e.message, 5000);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// ==========================================================
|
||||
// Step 2: 登录 Boss直聘
|
||||
// ==========================================================
|
||||
$('btnStartLogin').addEventListener('click', async () => {
|
||||
const btn = $('btnStartLogin');
|
||||
btn.disabled = true;
|
||||
try {
|
||||
await api('/api/start-login', { method: 'POST' });
|
||||
toast('浏览器已打开,请在 AdsPower 浏览器中完成登录');
|
||||
$('loginSpinner').classList.remove('hidden');
|
||||
startLoginPoll();
|
||||
} catch (e) {
|
||||
toast('打开浏览器失败:' + e.message, 5000);
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
function startLoginPoll() {
|
||||
if (loginPollTimer) clearInterval(loginPollTimer);
|
||||
loginPollTimer = setInterval(async () => {
|
||||
try {
|
||||
const r = await api('/api/login-status');
|
||||
updateLoginBadge(r.status, r.boss_account);
|
||||
if (r.status === 'logged_in') {
|
||||
clearInterval(loginPollTimer);
|
||||
$('loginSpinner').classList.add('hidden');
|
||||
$('btnStartLogin').disabled = false;
|
||||
toast('登录成功!即将进入简历步骤');
|
||||
setTimeout(() => goToStep(3), 1200);
|
||||
}
|
||||
} catch (e) { /* 忽略 */ }
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
// Step 3: 抓取简历
|
||||
// ==========================================================
|
||||
$('btnScrape').addEventListener('click', async () => {
|
||||
const btn = $('btnScrape');
|
||||
btn.disabled = true;
|
||||
btn.textContent = '正在抓取...';
|
||||
try {
|
||||
const data = await api('/api/scrape-resumes', { method: 'POST' });
|
||||
toast(`抓取到 ${data.count} 份简历`);
|
||||
loadResumes();
|
||||
} catch (e) {
|
||||
toast('抓取失败:' + e.message, 5000);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = '开始抓取简历';
|
||||
}
|
||||
});
|
||||
|
||||
async function loadResumes() {
|
||||
try {
|
||||
const resumes = await api('/api/resumes');
|
||||
const list = $('resumeList');
|
||||
if (!resumes.length) {
|
||||
list.innerHTML = '<p class="hint">暂无简历,请先抓取。</p>';
|
||||
return;
|
||||
}
|
||||
list.innerHTML = resumes.map(r => `
|
||||
<div class="resume-item ${r.is_primary ? 'primary' : ''}" data-id="${r.id}">
|
||||
<div class="radio"></div>
|
||||
<div>
|
||||
<div class="r-title">${escapeHtml(r.title)}</div>
|
||||
<div class="r-pos">${escapeHtml(r.position || '未设置求职意向')}</div>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
list.querySelectorAll('.resume-item').forEach(el => {
|
||||
el.addEventListener('click', () => setPrimary(parseInt(el.dataset.id)));
|
||||
});
|
||||
} catch (e) { console.error(e); }
|
||||
}
|
||||
|
||||
async function setPrimary(id) {
|
||||
try {
|
||||
await api(`/api/resumes/${id}/primary`, { method: 'POST' });
|
||||
toast('已设为主简历');
|
||||
loadResumes();
|
||||
// 允许进入下一步
|
||||
setTimeout(() => { if (currentStep === 3) goToStep(4); }, 600);
|
||||
} catch (e) {
|
||||
toast('设置失败:' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
// Step 4: 开始 / 结束投递
|
||||
// ==========================================================
|
||||
$('btnStartApply').addEventListener('click', async () => {
|
||||
const keywords = $('keywords').value.split(',').map(k => k.trim()).filter(Boolean);
|
||||
if (!keywords.length) { toast('请填写搜索关键词'); return; }
|
||||
|
||||
const btn = $('btnStartApply');
|
||||
btn.disabled = true;
|
||||
try {
|
||||
await api('/api/start-apply', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
keywords,
|
||||
city_code: $('cityCode').value,
|
||||
salary_min: parseInt($('salaryMin').value) || null,
|
||||
salary_max: parseInt($('salaryMax').value) || null,
|
||||
greeting: $('greeting').value,
|
||||
min_score: parseInt($('minScore').value) || 65,
|
||||
}),
|
||||
});
|
||||
toast('投递任务已启动');
|
||||
toggleApplyUI(true);
|
||||
startApplyPoll();
|
||||
} catch (e) {
|
||||
toast('启动失败:' + e.message, 5000);
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
$('btnStopApply').addEventListener('click', async () => {
|
||||
try {
|
||||
const r = await api('/api/stop-apply', { method: 'POST' });
|
||||
toast(r.msg);
|
||||
} catch (e) { toast('停止失败:' + e.message); }
|
||||
});
|
||||
|
||||
function toggleApplyUI(running) {
|
||||
$('btnStartApply').classList.toggle('hidden', running);
|
||||
$('btnStopApply').classList.toggle('hidden', !running);
|
||||
$('progressBox').classList.toggle('hidden', !running);
|
||||
$('btnStartApply').disabled = false;
|
||||
}
|
||||
|
||||
function startApplyPoll() {
|
||||
if (applyPollTimer) clearInterval(applyPollTimer);
|
||||
applyPollTimer = setInterval(async () => {
|
||||
try {
|
||||
const r = await api('/api/apply-status');
|
||||
if (r.stats) {
|
||||
$('progressCurrent').textContent = r.stats.current || '';
|
||||
$('statApplied').textContent = r.stats.applied || 0;
|
||||
$('statSkipped').textContent = r.stats.skipped || 0;
|
||||
}
|
||||
if (!r.running) {
|
||||
clearInterval(applyPollTimer);
|
||||
toggleApplyUI(false);
|
||||
toast('投递任务已结束');
|
||||
}
|
||||
} catch (e) { /* 忽略 */ }
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
// Step 5: 历史与统计
|
||||
// ==========================================================
|
||||
async function loadHistory() {
|
||||
try {
|
||||
const [stats, history] = await Promise.all([
|
||||
api('/api/stats'),
|
||||
api('/api/history?limit=50'),
|
||||
]);
|
||||
$('statsGrid').innerHTML = `
|
||||
<div class="stat-card"><div class="num">${stats.total_applied || 0}</div><div class="label">累计投递</div></div>
|
||||
<div class="stat-card"><div class="num">${stats.total_chat || 0}</div><div class="label">立即沟通</div></div>
|
||||
<div class="stat-card"><div class="num">${stats.total_deliver || 0}</div><div class="label">投递简历</div></div>
|
||||
<div class="stat-card"><div class="num">${stats.today_applied || 0}</div><div class="label">今日投递</div></div>
|
||||
`;
|
||||
$('historyBody').innerHTML = history.map(h => `
|
||||
<tr>
|
||||
<td>${escapeHtml(h.job_title || '-')}</td>
|
||||
<td>${escapeHtml(h.company || '-')}</td>
|
||||
<td>${escapeHtml(h.salary || '-')}</td>
|
||||
<td><span class="tag ${safeType(h.apply_type)}">${typeLabel(h.apply_type)}</span></td>
|
||||
<td>${h.ai_score >= 0 ? h.ai_score : '-'}</td>
|
||||
<td>${formatTime(h.applied_at)}</td>
|
||||
</tr>
|
||||
`).join('') || '<tr><td colspan="6" style="text-align:center;color:#999">暂无记录</td></tr>';
|
||||
} catch (e) { console.error(e); }
|
||||
}
|
||||
|
||||
function typeLabel(t) {
|
||||
return { chat: '沟通', deliver: '投递', skipped: '跳过' }[t] || t;
|
||||
}
|
||||
// apply_type 仅允许白名单值用作 CSS class,防止注入
|
||||
function safeType(t) {
|
||||
return ['chat', 'deliver', 'skipped'].includes(t) ? t : 'skipped';
|
||||
}
|
||||
function formatTime(s) {
|
||||
if (!s) return '-';
|
||||
return s.replace('T', ' ').substring(0, 16);
|
||||
}
|
||||
function escapeHtml(s) {
|
||||
if (!s) return '';
|
||||
return s.replace(/[&<>"']/g, c => ({
|
||||
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
||||
}[c]));
|
||||
}
|
||||
|
||||
// ---------- 启动 ----------
|
||||
refreshStatus();
|
||||
setInterval(refreshStatus, 8000);
|
||||
@@ -0,0 +1,259 @@
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
:root {
|
||||
--primary: #2f6fed;
|
||||
--primary-dark: #1e56c8;
|
||||
--success: #16a34a;
|
||||
--danger: #dc2626;
|
||||
--warning: #d97706;
|
||||
--bg: #f4f6fa;
|
||||
--card: #ffffff;
|
||||
--text: #1f2937;
|
||||
--text-light: #6b7280;
|
||||
--border: #e5e7eb;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 860px;
|
||||
margin: 0 auto;
|
||||
padding: 24px 16px 60px;
|
||||
}
|
||||
|
||||
/* ===== 顶部 ===== */
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.header h1 { font-size: 22px; }
|
||||
.status-badges { display: flex; gap: 8px; }
|
||||
|
||||
/* ===== 步骤导航 ===== */
|
||||
.steps {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-bottom: 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.step {
|
||||
flex: 1;
|
||||
min-width: 100px;
|
||||
text-align: center;
|
||||
padding: 10px 8px;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: var(--text-light);
|
||||
transition: all .2s;
|
||||
}
|
||||
.step.active {
|
||||
background: var(--primary);
|
||||
color: #fff;
|
||||
border-color: var(--primary);
|
||||
}
|
||||
.step-num {
|
||||
display: inline-block;
|
||||
width: 20px; height: 20px;
|
||||
line-height: 20px;
|
||||
border-radius: 50%;
|
||||
background: rgba(0,0,0,.08);
|
||||
margin-right: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.step.active .step-num { background: rgba(255,255,255,.25); }
|
||||
|
||||
/* ===== 面板 ===== */
|
||||
.panel {
|
||||
background: var(--card);
|
||||
border-radius: 12px;
|
||||
padding: 28px;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,.06);
|
||||
}
|
||||
.panel h2 { font-size: 19px; margin-bottom: 8px; }
|
||||
.panel .hint { color: var(--text-light); font-size: 14px; margin-bottom: 18px; }
|
||||
.hidden { display: none !important; }
|
||||
|
||||
.info-box {
|
||||
background: var(--bg);
|
||||
border-radius: 8px;
|
||||
padding: 14px 16px;
|
||||
margin-bottom: 18px;
|
||||
font-size: 14px;
|
||||
line-height: 2;
|
||||
}
|
||||
.info-box code {
|
||||
background: #eef2ff;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* ===== 徽章 ===== */
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 3px 10px;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
background: var(--border);
|
||||
color: var(--text-light);
|
||||
}
|
||||
.badge.ok { background: #dcfce7; color: var(--success); }
|
||||
.badge.warn { background: #fef3c7; color: var(--warning); }
|
||||
.badge.err { background: #fee2e2; color: var(--danger); }
|
||||
|
||||
/* ===== 表单 ===== */
|
||||
.form-group { margin-bottom: 16px; }
|
||||
.form-row { display: flex; gap: 14px; }
|
||||
.form-row .form-group { flex: 1; }
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
color: var(--text-light);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
/* ===== 按钮 ===== */
|
||||
.btn {
|
||||
padding: 11px 22px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 15px;
|
||||
cursor: pointer;
|
||||
transition: all .2s;
|
||||
font-weight: 600;
|
||||
}
|
||||
.btn-primary { background: var(--primary); color: #fff; }
|
||||
.btn-primary:hover { background: var(--primary-dark); }
|
||||
.btn-success { background: var(--success); color: #fff; }
|
||||
.btn-success:hover { filter: brightness(1.1); }
|
||||
.btn-danger { background: var(--danger); color: #fff; }
|
||||
.btn-danger:hover { filter: brightness(1.1); }
|
||||
.btn:disabled { opacity: .5; cursor: not-allowed; }
|
||||
.action-buttons { display: flex; gap: 12px; margin-top: 10px; }
|
||||
|
||||
/* ===== 加载 ===== */
|
||||
.spinner {
|
||||
margin-top: 16px;
|
||||
color: var(--primary);
|
||||
font-size: 14px;
|
||||
animation: pulse 1.5s infinite;
|
||||
}
|
||||
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
|
||||
|
||||
/* ===== 简历列表 ===== */
|
||||
.resume-list { margin-top: 18px; }
|
||||
.resume-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
margin-bottom: 10px;
|
||||
cursor: pointer;
|
||||
transition: all .2s;
|
||||
}
|
||||
.resume-item:hover { border-color: var(--primary); }
|
||||
.resume-item.primary {
|
||||
border-color: var(--success);
|
||||
background: #f0fdf4;
|
||||
}
|
||||
.resume-item .radio {
|
||||
width: 18px; height: 18px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid var(--border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.resume-item.primary .radio {
|
||||
border-color: var(--success);
|
||||
background: var(--success);
|
||||
}
|
||||
.resume-item .r-title { font-weight: 600; }
|
||||
.resume-item .r-pos { font-size: 13px; color: var(--text-light); }
|
||||
|
||||
/* ===== 进度 ===== */
|
||||
.progress-box {
|
||||
margin-top: 18px;
|
||||
padding: 16px;
|
||||
background: var(--bg);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.progress-current { font-size: 14px; margin-bottom: 10px; color: var(--primary); }
|
||||
.progress-stats { display: flex; gap: 24px; font-size: 14px; }
|
||||
|
||||
/* ===== 统计网格 ===== */
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.stat-card {
|
||||
background: var(--bg);
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
text-align: center;
|
||||
}
|
||||
.stat-card .num { font-size: 26px; font-weight: 700; color: var(--primary); }
|
||||
.stat-card .label { font-size: 13px; color: var(--text-light); margin-top: 4px; }
|
||||
|
||||
/* ===== 历史表格 ===== */
|
||||
.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
||||
.history-table th, .history-table td {
|
||||
padding: 10px 8px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.history-table th { color: var(--text-light); font-weight: 600; }
|
||||
.history-table td .tag {
|
||||
padding: 2px 8px; border-radius: 10px; font-size: 12px;
|
||||
}
|
||||
.tag.chat { background: #dcfce7; color: var(--success); }
|
||||
.tag.deliver { background: #dbeafe; color: var(--primary); }
|
||||
.tag.skipped { background: #f3f4f6; color: var(--text-light); }
|
||||
|
||||
/* ===== Toast ===== */
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 24px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(80px);
|
||||
background: #1f2937;
|
||||
color: #fff;
|
||||
padding: 12px 22px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
opacity: 0;
|
||||
transition: all .3s;
|
||||
z-index: 999;
|
||||
max-width: 80%;
|
||||
}
|
||||
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
|
||||
Reference in New Issue
Block a user