From ff7c6d84f152c901fb43f5cb0e932fc154867f23 Mon Sep 17 00:00:00 2001 From: lingyunxsh Date: Tue, 25 Aug 2026 23:39:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/browser/applicant.py | 6 +-- client/server_api.py | 17 ++++++ client/web/app.py | 31 ++++++++++- client/web/static/app.js | 94 +++++++++++++++++++++++++++++---- client/web/static/style.css | 40 ++++++++++++++ client/web/templates/index.html | 37 +++++++++---- server/routers/resumes.py | 24 ++++++++- server/schemas.py | 7 +++ 8 files changed, 230 insertions(+), 26 deletions(-) diff --git a/client/browser/applicant.py b/client/browser/applicant.py index 0d86a80..571a586 100644 --- a/client/browser/applicant.py +++ b/client/browser/applicant.py @@ -164,7 +164,7 @@ class Applicant: # ------------------------------------------------------------------ def start(self, keywords: list[str], city_code: str, salary_min: int | None, salary_max: int | None, - greeting: str, min_score: int, delay_range: tuple[int, int], + min_score: int, delay_range: tuple[int, int], boss_online_only: bool = False, daily_limit: int = 0) -> None: if self.is_running: logger.warning("已有投递任务在运行") @@ -189,7 +189,7 @@ class Applicant: self._thread = threading.Thread( target=self._run, args=(keywords, city_code, salary_min, salary_max, - greeting, min_score, delay_range), + min_score, delay_range), daemon=True, ) self._thread.start() @@ -224,7 +224,7 @@ class Applicant: # 主循环 # ------------------------------------------------------------------ def _run(self, keywords, city_code, salary_min, salary_max, - greeting, min_score, delay_range): + min_score, delay_range): try: self.manager.ensure_browser_started() # 整个任务只开一个列表标签页,模拟真人持续浏览 diff --git a/client/server_api.py b/client/server_api.py index a502614..c9532e1 100644 --- a/client/server_api.py +++ b/client/server_api.py @@ -158,6 +158,23 @@ class ServerAPI: resp.raise_for_status() return resp.json() + def update_resume(self, resume_id: int, data: dict) -> dict: + """编辑简历(标题/求职意向/正文)""" + resp = requests.put( + f"{self.base_url}/api/resumes/{resume_id}", + json=data, headers=self._headers(), timeout=15, + ) + resp.raise_for_status() + return resp.json() + + def delete_resume(self, resume_id: int) -> dict: + resp = requests.delete( + f"{self.base_url}/api/resumes/{resume_id}", + headers=self._headers(), timeout=15, + ) + resp.raise_for_status() + return resp.json() + # ------------------------------------------------------------------ # 投递会话 # ------------------------------------------------------------------ diff --git a/client/web/app.py b/client/web/app.py index 7c03fbd..0ab77bd 100644 --- a/client/web/app.py +++ b/client/web/app.py @@ -108,7 +108,6 @@ class StartApplyReq(BaseModel): city_code: str salary_min: int | None = None salary_max: int | None = None - greeting: str = "" min_score: int = 65 delay_min: int = 3 delay_max: int = 8 @@ -116,6 +115,12 @@ class StartApplyReq(BaseModel): daily_limit: int = 0 +class ResumeUpdateReq(BaseModel): + title: str | None = None + position: str | None = None + content: str | None = None + + # ======================================================= # 页面 # ======================================================= @@ -335,6 +340,29 @@ def set_primary(resume_id: int): return state.server_api.set_primary_resume(resume_id) +@app.put("/api/resumes/{resume_id}") +def update_resume(resume_id: int, req: ResumeUpdateReq): + """编辑简历(标题/求职意向/正文)""" + _require_auth() + data = {k: v for k, v in req.model_dump().items() if v is not None} + if not data: + raise HTTPException(status_code=400, detail="没有需要更新的字段") + try: + return state.server_api.update_resume(resume_id, data) + except requests.HTTPError as e: + raise HTTPException(status_code=e.response.status_code, detail=_extract_error(e)) + + +@app.delete("/api/resumes/{resume_id}") +def delete_resume(resume_id: int): + """删除简历""" + _require_auth() + try: + return state.server_api.delete_resume(resume_id) + except requests.HTTPError as e: + raise HTTPException(status_code=e.response.status_code, detail=_extract_error(e)) + + # ======================================================= # Step 3 & 4: 开始 / 结束投递 # ======================================================= @@ -359,7 +387,6 @@ def start_apply(req: StartApplyReq): city_code=req.city_code, salary_min=req.salary_min, salary_max=req.salary_max, - greeting=req.greeting, min_score=req.min_score, delay_range=(req.delay_min, req.delay_max), boss_online_only=req.boss_online_only, diff --git a/client/web/static/app.js b/client/web/static/app.js index 910c444..b5fe490 100644 --- a/client/web/static/app.js +++ b/client/web/static/app.js @@ -82,6 +82,11 @@ async function refreshStatus() { // 本地 token 免登录:自动跳过账号步骤 if (currentStep === 1) goToStep(2); } + // 页面刷新/重新进入后恢复投递运行态:后端任务还在跑就切到运行中 UI 并接管轮询 + if (s.applying) { + toggleApplyUI(true); + startApplyPoll(); + } return s; } catch (e) { console.error(e); @@ -108,10 +113,15 @@ function setAuthMode(isRegister) { registerMode = isRegister; $('btnLogin').classList.toggle('hidden', isRegister); $('btnRegister').classList.toggle('hidden', !isRegister); + // 当前模式可见的就是主操作按钮,统一用主色突出 + $('btnLogin').className = 'btn btn-primary'; + $('btnRegister').className = 'btn btn-primary'; $('nicknameGroup').classList.toggle('hidden', !isRegister); - $('authSwitchHint').textContent = isRegister - ? '已有账号?点击上方“登 录”切换为登录模式。' - : '没有账号?点击上方“注册新账号”切换为注册模式。'; + // 当前模式的主按钮用主色,标题与切换引导同步切换 + $('authTitle').textContent = isRegister ? '注册系统账号' : '登录系统账号'; + $('authSwitchHint').innerHTML = isRegister + ? '已有账号?点此返回登录 →' + : '没有账号?点此注册新账号 →'; } // 登录/注册模式切换:登录模式下“注册新账号”是切换按钮;注册模式下“登 录”是切换按钮 @@ -170,13 +180,17 @@ async function detectBossLogin() { try { const r = await api('/api/detect-login', { method: 'POST' }); if (r.logged_in) { + // 浏览器在运行且 Boss 已登录:不再引导手动登录,自动进入下一步 updateLoginBadge('logged_in', r.account); + $('btnStartLogin').classList.add('hidden'); $('btnSkipLogin').classList.remove('hidden'); - toast(`检测到已登录:${r.account},可直接进入下一步`); + toast(`Boss 已登录:${r.account},自动进入下一步`); + setTimeout(() => { if (currentStep === 2) goToStep(3); }, 1200); } else { updateLoginBadge('not_login'); + $('btnStartLogin').classList.remove('hidden'); $('btnSkipLogin').classList.add('hidden'); - toast('未检测到登录,请点击“打开浏览器登录”'); + toast('未检测到 Boss 登录,请点击“打开浏览器登录”'); } } catch (e) { toast('登录检测失败:' + e.message, 5000); @@ -239,9 +253,13 @@ $('btnScrape').addEventListener('click', async () => { } }); +let resumesCache = []; // 当前简历列表缓存(供编辑弹窗取内容) +let editingResumeId = null; + async function loadResumes() { try { const resumes = await api('/api/resumes'); + resumesCache = resumes; const list = $('resumeList'); if (!resumes.length) { list.innerHTML = '

暂无简历,请先抓取。

'; @@ -250,18 +268,76 @@ async function loadResumes() { list.innerHTML = resumes.map(r => `
-
+
${escapeHtml(r.title)}
${escapeHtml(r.position || '未设置求职意向')}
+
+ + +
`).join(''); list.querySelectorAll('.resume-item').forEach(el => { - el.addEventListener('click', () => setPrimary(parseInt(el.dataset.id))); + const id = parseInt(el.dataset.id); + el.addEventListener('click', (e) => { + if (e.target.closest('.r-edit')) { openResumeEdit(id); return; } + if (e.target.closest('.r-delete')) { deleteResume(id); return; } + setPrimary(id); // 点其他区域 = 设为主简历 + }); }); } catch (e) { console.error(e); } } +function openResumeEdit(id) { + const r = resumesCache.find(x => x.id === id); + if (!r) return; + editingResumeId = id; + $('editResumeTitle').value = r.title || ''; + $('editResumeContent').value = r.content || ''; + $('resumeModal').classList.remove('hidden'); +} + +$('btnCancelResume').addEventListener('click', () => { + $('resumeModal').classList.add('hidden'); + editingResumeId = null; +}); + +$('btnSaveResume').addEventListener('click', async () => { + if (!editingResumeId) return; + const title = $('editResumeTitle').value.trim(); + if (!title) { toast('简历名称不能为空'); return; } + const btn = $('btnSaveResume'); + btn.disabled = true; + try { + await api(`/api/resumes/${editingResumeId}`, { + method: 'PUT', + body: JSON.stringify({ title, content: $('editResumeContent').value }), + }); + toast('简历已保存'); + $('resumeModal').classList.add('hidden'); + editingResumeId = null; + loadResumes(); + } catch (e) { + toast('保存失败:' + e.message, 5000); + } finally { + btn.disabled = false; + } +}); + +async function deleteResume(id) { + const r = resumesCache.find(x => x.id === id); + if (!confirm(`确定删除简历《${r ? r.title : id}》?删除后不可恢复。`)) return; + try { + await api(`/api/resumes/${id}`, { method: 'DELETE' }); + toast('简历已删除'); + if (r && r.is_primary) toast('删除的是主简历,请重新选择一份设为主简历', 5000); + loadResumes(); + } catch (e) { + toast('删除失败:' + e.message, 5000); + } +} + async function setPrimary(id) { try { await api(`/api/resumes/${id}/primary`, { method: 'POST' }); @@ -291,7 +367,6 @@ $('btnStartApply').addEventListener('click', async () => { 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, boss_online_only: $('bossOnlineOnly').checked, daily_limit: parseInt($('dailyLimit').value) || 0, @@ -321,7 +396,7 @@ function toggleApplyUI(running) { } function startApplyPoll() { - if (applyPollTimer) clearInterval(applyPollTimer); + if (applyPollTimer) return; // 已在轮询则不重复启动(refreshStatus 每 8s 会再次触发) applyPollTimer = setInterval(async () => { try { const r = await api('/api/apply-status'); @@ -332,6 +407,7 @@ function startApplyPoll() { } if (!r.running) { clearInterval(applyPollTimer); + applyPollTimer = null; toggleApplyUI(false); toast('投递任务已结束'); } diff --git a/client/web/static/style.css b/client/web/static/style.css index faa7053..20b697c 100644 --- a/client/web/static/style.css +++ b/client/web/static/style.css @@ -178,6 +178,46 @@ body { .btn-danger:hover { filter: brightness(1.1); } .btn:disabled { opacity: .5; cursor: not-allowed; } .action-buttons { display: flex; gap: 12px; margin-top: 10px; } +.btn-outline { background: #fff; border: 1px solid var(--primary); color: var(--primary); } +.btn-outline:hover { filter: brightness(.96); } + +/* 登录/注册模式切换引导链接 */ +.switch-link { + text-align: center; + margin-top: 16px; + color: var(--text-light); + font-size: 14px; + cursor: pointer; + user-select: none; +} +.switch-link b { color: var(--primary); } +.switch-link:hover b { text-decoration: underline; } + +/* ===== 弹窗 ===== */ +.modal-mask { + position: fixed; + inset: 0; + background: rgba(0,0,0,.45); + display: flex; + align-items: center; + justify-content: center; + z-index: 1000; +} +.modal-box { + background: var(--card); + border-radius: 12px; + padding: 24px; + width: 640px; + max-width: 92vw; + max-height: 86vh; + overflow-y: auto; +} +.modal-box h3 { margin-bottom: 14px; } + +/* 简历条目操作区 */ +.resume-item { justify-content: space-between; } +.r-main { flex: 1; } +.r-actions { display: flex; gap: 12px; align-items: center; } /* ===== 加载 ===== */ .spinner { diff --git a/client/web/templates/index.html b/client/web/templates/index.html index 86d7b00..bdc96e7 100644 --- a/client/web/templates/index.html +++ b/client/web/templates/index.html @@ -29,7 +29,7 @@
-

登录系统账号

+

登录系统账号

简历与投递记录都保存在你的账号下,换机器登录同一账号即可延续数据。

服务端状态:检测中
@@ -47,19 +47,19 @@
- - + +
-

没有账号?点击上方“注册新账号”切换为注册模式。

+
-
- - -
@@ -145,7 +141,7 @@