分页优化
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ REM 每次升级改 APP_VERSION,避免与正在运行的旧版本目录冲突
|
|||||||
REM 使用:把整个文件夹拷到目标机器(或压缩成 zip 发送),
|
REM 使用:把整个文件夹拷到目标机器(或压缩成 zip 发送),
|
||||||
REM 双击文件夹里的 Boss直聘AI投递-%APP_VERSION%.exe 运行。
|
REM 双击文件夹里的 Boss直聘AI投递-%APP_VERSION%.exe 运行。
|
||||||
REM ============================================================
|
REM ============================================================
|
||||||
set APP_VERSION=1.3
|
set APP_VERSION=1.4
|
||||||
|
|
||||||
echo [1/2] 安装打包依赖...
|
echo [1/2] 安装打包依赖...
|
||||||
pip install pyinstaller PySide6 --quiet
|
pip install pyinstaller PySide6 --quiet
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
"""排查:期望项 .expect-item 的 class 结构(含选中态标记)"""
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from client.browser.cdp_lite import LiteCDP, CDPSession
|
||||||
|
from client.browser.manager import BrowserManager
|
||||||
|
|
||||||
|
OUT = Path(__file__).resolve().parent / "data" / "debug" / "期望项结构.txt"
|
||||||
|
|
||||||
|
_JS = """JSON.stringify([...document.querySelectorAll('.expect-item')].map(e => ({
|
||||||
|
cls: String(e.className),
|
||||||
|
text: (e.innerText || '').trim().slice(0, 50),
|
||||||
|
html: e.outerHTML.replace(/\\s+/g, ' ').slice(0, 300),
|
||||||
|
})))"""
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
BrowserManager().ensure_browser_started()
|
||||||
|
lite = LiteCDP()
|
||||||
|
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs")
|
||||||
|
time.sleep(8)
|
||||||
|
s = CDPSession(tab["webSocketDebuggerUrl"])
|
||||||
|
raw = s.eval_js(_JS)
|
||||||
|
items = json.loads(raw or "[]")
|
||||||
|
lines = [json.dumps(it, ensure_ascii=False) for it in items]
|
||||||
|
OUT.write_text("\n".join(lines) or "(未找到 .expect-item)", encoding="utf-8")
|
||||||
|
s.close()
|
||||||
|
lite.close_tab(tab["id"])
|
||||||
|
print("完成 ->", OUT)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
"""验证:_select_expect_js 新版返回结构(坐标/落点元素/全量项/视口)"""
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from client.browser.applicant import _select_expect_js
|
||||||
|
from client.browser.cdp_lite import LiteCDP, CDPSession
|
||||||
|
from client.browser.manager import BrowserManager
|
||||||
|
|
||||||
|
OUT = Path(__file__).resolve().parent / "data" / "debug" / "期望定位验证.txt"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
BrowserManager().ensure_browser_started()
|
||||||
|
lite = LiteCDP()
|
||||||
|
tab = lite.open_tab("https://www.zhipin.com/web/geek/jobs")
|
||||||
|
time.sleep(8)
|
||||||
|
s = CDPSession(tab["webSocketDebuggerUrl"])
|
||||||
|
raw = s.eval_js(_select_expect_js("Java", "天津"))
|
||||||
|
OUT.write_text(json.dumps(json.loads(raw or "{}"),
|
||||||
|
ensure_ascii=False, indent=2), encoding="utf-8")
|
||||||
|
s.close()
|
||||||
|
lite.close_tab(tab["id"])
|
||||||
|
print("完成 ->", OUT)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
+31
-5
@@ -247,11 +247,21 @@ class ServerAPI:
|
|||||||
return resp.json().get("applied", False)
|
return resp.json().get("applied", False)
|
||||||
|
|
||||||
def list_blacklist(self) -> list[str]:
|
def list_blacklist(self) -> list[str]:
|
||||||
"""公司黑名单名单(公司名列表,拉黑后不再投递该公司)"""
|
"""公司黑名单名单(公司名列表,拉黑后不再投递该公司)。
|
||||||
resp = self._req("get", f"{self.base_url}/api/blacklist",
|
接口分页返回,这里翻页拉全(黑名单用于投递前过滤,必须拿到全量)"""
|
||||||
headers=self._headers(), timeout=15)
|
companies: list[str] = []
|
||||||
resp.raise_for_status()
|
page = 1
|
||||||
return [i["company"] for i in resp.json()]
|
while True:
|
||||||
|
resp = self._req("get", f"{self.base_url}/api/blacklist",
|
||||||
|
params={"page": page, "page_size": 100},
|
||||||
|
headers=self._headers(), timeout=15)
|
||||||
|
resp.raise_for_status()
|
||||||
|
data = resp.json()
|
||||||
|
companies.extend(i["company"] for i in data.get("items", []))
|
||||||
|
if page >= data.get("pages", 1) or page >= 10:
|
||||||
|
break
|
||||||
|
page += 1
|
||||||
|
return companies
|
||||||
|
|
||||||
def get_stats(self) -> dict:
|
def get_stats(self) -> dict:
|
||||||
resp = self._req("get", f"{self.base_url}/api/jobs/stats", headers=self._headers(), timeout=15)
|
resp = self._req("get", f"{self.base_url}/api/jobs/stats", headers=self._headers(), timeout=15)
|
||||||
@@ -275,6 +285,22 @@ class ServerAPI:
|
|||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return resp.json()
|
return resp.json()
|
||||||
|
|
||||||
|
def get_history_page(self, page: int = 1, page_size: int = 20,
|
||||||
|
apply_type: str | None = None,
|
||||||
|
start: str | None = None, end: str | None = None) -> dict:
|
||||||
|
"""投递记录分页筛选(北京时间范围 + 投递结果,时间倒序)"""
|
||||||
|
params: dict = {"page": page, "page_size": page_size}
|
||||||
|
if apply_type:
|
||||||
|
params["apply_type"] = apply_type
|
||||||
|
if start:
|
||||||
|
params["start"] = start
|
||||||
|
if end:
|
||||||
|
params["end"] = end
|
||||||
|
resp = self._req("get", f"{self.base_url}/api/jobs/page",
|
||||||
|
params=params, headers=self._headers(), timeout=15)
|
||||||
|
resp.raise_for_status()
|
||||||
|
return resp.json()
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 连通性
|
# 连通性
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -428,6 +428,19 @@ def history(limit: int = 50, apply_type: str | None = None):
|
|||||||
return state.server_api.get_history(limit=limit, apply_type=apply_type)
|
return state.server_api.get_history(limit=limit, apply_type=apply_type)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/history-page")
|
||||||
|
def history_page(page: int = 1, page_size: int = 20,
|
||||||
|
apply_type: str | None = None,
|
||||||
|
start: str | None = None, end: str | None = None):
|
||||||
|
"""投递记录分页筛选(时间范围 + 投递结果,时间倒序)"""
|
||||||
|
if not state.connected:
|
||||||
|
return {"items": [], "total": 0, "applied": 0, "skipped": 0,
|
||||||
|
"page": page, "page_size": page_size, "pages": 0}
|
||||||
|
return state.server_api.get_history_page(
|
||||||
|
page=page, page_size=page_size, apply_type=apply_type,
|
||||||
|
start=start, end=end)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/stats")
|
@app.get("/api/stats")
|
||||||
def stats():
|
def stats():
|
||||||
if not state.connected:
|
if not state.connected:
|
||||||
|
|||||||
+66
-11
@@ -425,21 +425,42 @@ function startApplyPoll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================================
|
// ==========================================================
|
||||||
// Step 5: 历史与统计
|
// Step 5: 历史与统计(筛选 + 分页)
|
||||||
// ==========================================================
|
// ==========================================================
|
||||||
|
const histState = { range: 'today', start: '', end: '', type: '', page: 1, pageSize: 20 };
|
||||||
|
|
||||||
|
function fmtDate(d) {
|
||||||
|
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0')
|
||||||
|
+ '-' + String(d.getDate()).padStart(2, '0');
|
||||||
|
}
|
||||||
|
function histRangeDates() {
|
||||||
|
const now = new Date(), today = fmtDate(now);
|
||||||
|
if (histState.range === 'today') return [today, today];
|
||||||
|
if (histState.range === 'week') {
|
||||||
|
const d = new Date(now); d.setDate(d.getDate() - ((d.getDay() + 6) % 7)); // 周一
|
||||||
|
return [fmtDate(d), today];
|
||||||
|
}
|
||||||
|
if (histState.range === 'month') {
|
||||||
|
return [fmtDate(new Date(now.getFullYear(), now.getMonth(), 1)), today];
|
||||||
|
}
|
||||||
|
return [histState.start, histState.end]; // 自定义
|
||||||
|
}
|
||||||
|
|
||||||
async function loadHistory() {
|
async function loadHistory() {
|
||||||
try {
|
try {
|
||||||
const [stats, history] = await Promise.all([
|
const [start, end] = histRangeDates();
|
||||||
api('/api/stats'),
|
if (histState.range === 'custom' && (!start || !end)) return;
|
||||||
api('/api/history?limit=50'),
|
const params = new URLSearchParams({ page: histState.page, page_size: histState.pageSize });
|
||||||
]);
|
if (start) params.set('start', start);
|
||||||
|
if (end) params.set('end', end);
|
||||||
|
if (histState.type) params.set('apply_type', histState.type);
|
||||||
|
const d = await api('/api/history-page?' + params);
|
||||||
$('statsGrid').innerHTML = `
|
$('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">${d.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">${d.skipped || 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">${d.total || 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 => `
|
$('historyBody').innerHTML = (d.items || []).map(h => `
|
||||||
<tr>
|
<tr>
|
||||||
<td title="${escapeHtml(recordDetail(h))}">${escapeHtml(h.job_title || '-')}</td>
|
<td title="${escapeHtml(recordDetail(h))}">${escapeHtml(h.job_title || '-')}</td>
|
||||||
<td>${escapeHtml(h.company || '-')}</td>
|
<td>${escapeHtml(h.company || '-')}</td>
|
||||||
@@ -448,7 +469,10 @@ async function loadHistory() {
|
|||||||
<td>${h.ai_score >= 0 ? h.ai_score : '-'}</td>
|
<td>${h.ai_score >= 0 ? h.ai_score : '-'}</td>
|
||||||
<td>${formatTime(h.applied_at)}</td>
|
<td>${formatTime(h.applied_at)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
`).join('') || '<tr><td colspan="6" style="text-align:center;color:#999">暂无记录</td></tr>';
|
`).join('') || '<tr><td colspan="6" style="text-align:center;color:#999">该筛选条件下暂无记录</td></tr>';
|
||||||
|
$('histPageInfo').textContent = `共 ${d.total} 条 · 第 ${d.page} / ${Math.max(d.pages, 1)} 页`;
|
||||||
|
$('btnHistPrev').disabled = d.page <= 1;
|
||||||
|
$('btnHistNext').disabled = d.page >= d.pages;
|
||||||
} catch (e) { console.error(e); }
|
} catch (e) { console.error(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,6 +502,37 @@ function escapeHtml(s) {
|
|||||||
}[c]));
|
}[c]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- 记录筛选/分页事件 ----------
|
||||||
|
document.querySelectorAll('[data-hrange]').forEach(el => el.addEventListener('click', () => {
|
||||||
|
document.querySelectorAll('[data-hrange]').forEach(c => c.classList.toggle('active', c === el));
|
||||||
|
histState.range = el.dataset.hrange;
|
||||||
|
$('histCustomRange').classList.toggle('hidden', histState.range !== 'custom');
|
||||||
|
if (histState.range !== 'custom') { histState.page = 1; loadHistory(); }
|
||||||
|
}));
|
||||||
|
$('btnHistQuery').onclick = () => {
|
||||||
|
histState.start = $('histDateStart').value;
|
||||||
|
histState.end = $('histDateEnd').value;
|
||||||
|
if (!histState.start || !histState.end) { toast('请选择起止日期'); return; }
|
||||||
|
if (histState.start > histState.end) { toast('起始日期不能晚于结束日期'); return; }
|
||||||
|
histState.page = 1; loadHistory();
|
||||||
|
};
|
||||||
|
document.querySelectorAll('[data-htype]').forEach(el => el.addEventListener('click', () => {
|
||||||
|
document.querySelectorAll('[data-htype]').forEach(c => c.classList.toggle('active', c === el));
|
||||||
|
histState.type = el.dataset.htype;
|
||||||
|
histState.page = 1; loadHistory();
|
||||||
|
}));
|
||||||
|
$('histPageSize').onchange = e => {
|
||||||
|
histState.pageSize = parseInt(e.target.value, 10);
|
||||||
|
histState.page = 1; loadHistory();
|
||||||
|
};
|
||||||
|
$('btnHistPrev').onclick = () => { if (histState.page > 1) { histState.page--; loadHistory(); } };
|
||||||
|
$('btnHistNext').onclick = () => { histState.page++; loadHistory(); };
|
||||||
|
|
||||||
// ---------- 启动 ----------
|
// ---------- 启动 ----------
|
||||||
|
{ // 自定义日期默认填入今天
|
||||||
|
const today = fmtDate(new Date());
|
||||||
|
$('histDateStart').value = today;
|
||||||
|
$('histDateEnd').value = today;
|
||||||
|
}
|
||||||
refreshStatus();
|
refreshStatus();
|
||||||
setInterval(refreshStatus, 8000);
|
setInterval(refreshStatus, 8000);
|
||||||
|
|||||||
@@ -314,6 +314,24 @@ body {
|
|||||||
.tag.deliver { background: #dbeafe; color: var(--primary); }
|
.tag.deliver { background: #dbeafe; color: var(--primary); }
|
||||||
.tag.skipped { background: #f3f4f6; color: var(--text-light); }
|
.tag.skipped { background: #f3f4f6; color: var(--text-light); }
|
||||||
|
|
||||||
|
/* ===== 记录筛选栏与分页 ===== */
|
||||||
|
.filters-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 12px; font-size: 13px; }
|
||||||
|
.filters-bar .grp { display: flex; align-items: center; gap: 6px; }
|
||||||
|
.filters-bar .grp > label { color: var(--text-light); }
|
||||||
|
.chip {
|
||||||
|
padding: 4px 12px; border: 1px solid var(--border); border-radius: 14px;
|
||||||
|
cursor: pointer; color: var(--text-light); background: #fff; font-size: 12px;
|
||||||
|
}
|
||||||
|
.chip:hover { border-color: var(--primary); color: var(--primary); }
|
||||||
|
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
|
||||||
|
.filters-bar input[type=date] { padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
|
||||||
|
.filters-bar select { padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
|
||||||
|
.btn-query { padding: 4px 14px; background: var(--primary); border: none; color: #fff; border-radius: 6px; cursor: pointer; font-size: 12px; }
|
||||||
|
.pager-bar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--text-light); }
|
||||||
|
.pager-bar button { padding: 4px 12px; border: 1px solid var(--border); background: #fff; border-radius: 6px; cursor: pointer; font-size: 12px; }
|
||||||
|
.pager-bar button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
|
||||||
|
.pager-bar button:disabled { color: #ccc; cursor: not-allowed; }
|
||||||
|
|
||||||
/* ===== Toast ===== */
|
/* ===== Toast ===== */
|
||||||
.toast {
|
.toast {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
|||||||
@@ -145,6 +145,34 @@
|
|||||||
<section class="panel hidden" id="panel-5">
|
<section class="panel hidden" id="panel-5">
|
||||||
<h2>投递记录与统计</h2>
|
<h2>投递记录与统计</h2>
|
||||||
<p class="hint">将鼠标悬停在职位名上,可查看归档的 JD 摘要与跳过原因。</p>
|
<p class="hint">将鼠标悬停在职位名上,可查看归档的 JD 摘要与跳过原因。</p>
|
||||||
|
<div class="filters-bar">
|
||||||
|
<div class="grp">
|
||||||
|
<label>时间:</label>
|
||||||
|
<span class="chip active" data-hrange="today">今日</span>
|
||||||
|
<span class="chip" data-hrange="week">本周</span>
|
||||||
|
<span class="chip" data-hrange="month">本月</span>
|
||||||
|
<span class="chip" data-hrange="custom">自定义</span>
|
||||||
|
<span id="histCustomRange" class="hidden">
|
||||||
|
<input type="date" id="histDateStart"> ~ <input type="date" id="histDateEnd">
|
||||||
|
<button class="btn-query" id="btnHistQuery">查询</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="grp">
|
||||||
|
<label>结果:</label>
|
||||||
|
<span class="chip active" data-htype="">全部</span>
|
||||||
|
<span class="chip" data-htype="chat">已沟通</span>
|
||||||
|
<span class="chip" data-htype="deliver">已投递</span>
|
||||||
|
<span class="chip" data-htype="skipped">已跳过</span>
|
||||||
|
</div>
|
||||||
|
<div class="grp">
|
||||||
|
<label>每页:</label>
|
||||||
|
<select id="histPageSize">
|
||||||
|
<option value="20" selected>20</option>
|
||||||
|
<option value="50">50</option>
|
||||||
|
<option value="100">100</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="stats-grid" id="statsGrid"></div>
|
<div class="stats-grid" id="statsGrid"></div>
|
||||||
<table class="history-table">
|
<table class="history-table">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -154,6 +182,11 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody id="historyBody"></tbody>
|
<tbody id="historyBody"></tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class="pager-bar">
|
||||||
|
<span id="histPageInfo"></span>
|
||||||
|
<button id="btnHistPrev">上一页</button>
|
||||||
|
<button id="btnHistNext">下一页</button>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
公司黑名单路由:拉黑后 RPA 不再投递该公司的任何职位
|
公司黑名单路由:拉黑后 RPA 不再投递该公司的任何职位
|
||||||
"""
|
"""
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from ..auth import get_current_user
|
from ..auth import get_current_user
|
||||||
@@ -12,15 +14,30 @@ from ..schemas import BlacklistIn, BlacklistOut, Message
|
|||||||
router = APIRouter(prefix="/api/blacklist", tags=["公司黑名单"])
|
router = APIRouter(prefix="/api/blacklist", tags=["公司黑名单"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("", response_model=list[BlacklistOut])
|
@router.get("", response_model=dict)
|
||||||
def list_blacklist(
|
def list_blacklist(
|
||||||
|
page: int = Query(1, ge=1, description="页码(1 起)"),
|
||||||
|
page_size: int = Query(20, ge=1, le=500, description="每页条数"),
|
||||||
current_user: User = Depends(get_current_user),
|
current_user: User = Depends(get_current_user),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""查询当前用户的黑名单列表(按拉黑时间倒序)"""
|
"""查询当前用户的黑名单列表(按拉黑时间倒序,分页返回)"""
|
||||||
return db.query(CompanyBlacklist).filter(
|
query = db.query(CompanyBlacklist).filter(
|
||||||
CompanyBlacklist.user_id == current_user.id,
|
CompanyBlacklist.user_id == current_user.id,
|
||||||
).order_by(CompanyBlacklist.created_at.desc()).all()
|
)
|
||||||
|
total = query.count()
|
||||||
|
rows = query.order_by(CompanyBlacklist.created_at.desc()) \
|
||||||
|
.offset((page - 1) * page_size).limit(page_size).all()
|
||||||
|
items = [{
|
||||||
|
"id": r.id,
|
||||||
|
"company": r.company,
|
||||||
|
"created_at": (r.created_at + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
} for r in rows]
|
||||||
|
return {
|
||||||
|
"items": items, "total": total,
|
||||||
|
"page": page, "page_size": page_size,
|
||||||
|
"pages": (total + page_size - 1) // page_size if page_size else 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.post("", response_model=BlacklistOut)
|
@router.post("", response_model=BlacklistOut)
|
||||||
|
|||||||
@@ -146,6 +146,61 @@ def list_applications(
|
|||||||
return query.order_by(JobApplication.applied_at.desc()).limit(limit).all()
|
return query.order_by(JobApplication.applied_at.desc()).limit(limit).all()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/page", response_model=dict)
|
||||||
|
def page_applications(
|
||||||
|
page: int = Query(1, ge=1, description="页码(1 起)"),
|
||||||
|
page_size: int = Query(20, ge=1, le=100, description="每页条数"),
|
||||||
|
apply_type: Optional[str] = Query(None, description="投递结果:chat/deliver/skipped"),
|
||||||
|
start: Optional[str] = Query(None, description="起始日期(北京时间,YYYY-MM-DD,含)"),
|
||||||
|
end: Optional[str] = Query(None, description="结束日期(北京时间,YYYY-MM-DD,含)"),
|
||||||
|
current_user: User = Depends(get_current_user),
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
):
|
||||||
|
"""投递记录分页筛选(北京时间范围 + 投递结果),时间倒序"""
|
||||||
|
query = db.query(JobApplication).filter(JobApplication.user_id == current_user.id)
|
||||||
|
|
||||||
|
# 北京时间日期区间 → UTC 区间(北京 00:00 == UTC 前一日 16:00)
|
||||||
|
try:
|
||||||
|
if start:
|
||||||
|
d = datetime.strptime(start, "%Y-%m-%d")
|
||||||
|
query = query.filter(JobApplication.applied_at >= d - timedelta(hours=8))
|
||||||
|
if end:
|
||||||
|
d = datetime.strptime(end, "%Y-%m-%d") + timedelta(days=1)
|
||||||
|
query = query.filter(JobApplication.applied_at < d - timedelta(hours=8))
|
||||||
|
except ValueError:
|
||||||
|
raise HTTPException(status_code=422, detail="日期格式应为 YYYY-MM-DD")
|
||||||
|
|
||||||
|
if apply_type:
|
||||||
|
query = query.filter(JobApplication.apply_type == apply_type)
|
||||||
|
|
||||||
|
# 筛选范围内统计(不受分页影响)
|
||||||
|
total = query.count()
|
||||||
|
applied = query.filter(JobApplication.apply_type.in_(["chat", "deliver"])).count()
|
||||||
|
skipped = query.filter(JobApplication.apply_type == "skipped").count()
|
||||||
|
|
||||||
|
rows = query.order_by(JobApplication.applied_at.desc()) \
|
||||||
|
.offset((page - 1) * page_size).limit(page_size).all()
|
||||||
|
items = [{
|
||||||
|
"job_title": r.job_title,
|
||||||
|
"company": r.company,
|
||||||
|
"salary": r.salary,
|
||||||
|
"location": r.location,
|
||||||
|
"apply_type": r.apply_type,
|
||||||
|
"ai_score": r.ai_score,
|
||||||
|
"ai_reason": r.ai_reason,
|
||||||
|
"skip_reason": r.skip_reason,
|
||||||
|
"greeting": r.greeting,
|
||||||
|
# JD 全文截断,供客户端悬停摘要展示,控制分页响应体积
|
||||||
|
"jd_text": (r.jd_text or "")[:500],
|
||||||
|
"applied_at": (r.applied_at + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
} for r in rows]
|
||||||
|
return {
|
||||||
|
"items": items, "total": total, "applied": applied, "skipped": skipped,
|
||||||
|
"page": page, "page_size": page_size,
|
||||||
|
"pages": (total + page_size - 1) // page_size if page_size else 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/stats", response_model=StatsOut)
|
@router.get("/stats", response_model=StatsOut)
|
||||||
def get_stats(
|
def get_stats(
|
||||||
current_user: User = Depends(get_current_user),
|
current_user: User = Depends(get_current_user),
|
||||||
|
|||||||
+163
-23
@@ -33,8 +33,19 @@
|
|||||||
aside .menu-item.active { background: #e8f4ff; color: #1890ff; border-left-color: #1890ff; font-weight: 600; }
|
aside .menu-item.active { background: #e8f4ff; color: #1890ff; border-left-color: #1890ff; font-weight: 600; }
|
||||||
.content { flex: 1; min-width: 0; }
|
.content { flex: 1; min-width: 0; }
|
||||||
|
|
||||||
/* 今日数据 */
|
/* 筛选栏 */
|
||||||
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
|
.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 { 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 .num { font-size: 30px; font-weight: 700; }
|
||||||
.stat-card .label { font-size: 13px; color: #888; margin-top: 4px; }
|
.stat-card .label { font-size: 13px; color: #888; margin-top: 4px; }
|
||||||
@@ -49,7 +60,13 @@
|
|||||||
.badge.skipped { background: #fff7e6; color: #faad14; border: 1px solid #ffd591; }
|
.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; }
|
.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; }
|
.remark { color: #999; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
.empty { text-align: center; padding: 40px; color: #999; }
|
.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 { border: 1px solid #ffd6d6; background: #fff; color: #e64340; border-radius: 4px; font-size: 12px; padding: 1px 8px; cursor: pointer; margin-left: 6px; }
|
||||||
@@ -92,26 +109,62 @@
|
|||||||
<div class="layout">
|
<div class="layout">
|
||||||
<!-- 左侧菜单 -->
|
<!-- 左侧菜单 -->
|
||||||
<aside>
|
<aside>
|
||||||
<div class="menu-item active" data-page="today">今日投递数据</div>
|
<div class="menu-item active" data-page="data">投递数据</div>
|
||||||
<div class="menu-item" data-page="blacklist">公司黑名单</div>
|
<div class="menu-item" data-page="blacklist">公司黑名单</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<!-- 右侧内容 -->
|
<!-- 右侧内容 -->
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<!-- 今日投递数据 -->
|
<!-- 投递数据(筛选 + 分页) -->
|
||||||
<div id="pageToday">
|
<div id="pageData">
|
||||||
<div class="stats">
|
<div class="filters">
|
||||||
<div class="stat-card"><div class="num green" id="stApplied">0</div><div class="label">今日已投递</div></div>
|
<div class="grp">
|
||||||
<div class="stat-card"><div class="num orange" id="stSkipped">0</div><div class="label">今日已跳过</div></div>
|
<label class="t">时间:</label>
|
||||||
<div class="stat-card"><div class="num blue" id="stTotal">0</div><div class="label">今日处理总数</div></div>
|
<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>
|
||||||
|
|
||||||
|
<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>
|
<table>
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
<th>时间</th><th>职位</th><th>公司</th><th>薪资</th><th>结果</th><th>AI评分</th><th>备注</th>
|
<th>时间</th><th>职位</th><th>公司</th><th>薪资</th><th>结果</th><th>AI评分</th><th>备注</th>
|
||||||
</tr></thead>
|
</tr></thead>
|
||||||
<tbody id="tbody"></tbody>
|
<tbody id="tbody"></tbody>
|
||||||
</table>
|
</table>
|
||||||
<div class="empty hidden" id="empty">今天还没有投递记录</div>
|
<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>
|
||||||
|
|
||||||
<!-- 公司黑名单 -->
|
<!-- 公司黑名单 -->
|
||||||
@@ -120,12 +173,18 @@
|
|||||||
<input type="text" id="blCompany" placeholder="输入公司名,如:某某科技有限公司" maxlength="128">
|
<input type="text" id="blCompany" placeholder="输入公司名,如:某某科技有限公司" maxlength="128">
|
||||||
<button id="btnBlAdd">拉黑</button>
|
<button id="btnBlAdd">拉黑</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="bl-tip">拉黑后,投递任务将自动跳过该公司的所有职位;在「今日投递数据」的公司列也可快捷拉黑。</div>
|
<div class="bl-tip">拉黑后,投递任务将自动跳过该公司的所有职位;在「投递数据」的公司列也可快捷拉黑。</div>
|
||||||
<table>
|
<table>
|
||||||
<thead><tr><th style="width:60px">#</th><th>公司名</th><th style="width:170px">拉黑时间</th><th style="width:90px">操作</th></tr></thead>
|
<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>
|
<tbody id="blTbody"></tbody>
|
||||||
</table>
|
</table>
|
||||||
<div class="empty hidden" id="blEmpty">黑名单为空</div>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -134,7 +193,11 @@
|
|||||||
<script>
|
<script>
|
||||||
const TOKEN_KEY = 'view_token';
|
const TOKEN_KEY = 'view_token';
|
||||||
const token = () => localStorage.getItem(TOKEN_KEY);
|
const token = () => localStorage.getItem(TOKEN_KEY);
|
||||||
let blSet = new Set(); // 当前黑名单公司名集合,用于今日表格快捷拉黑按钮状态
|
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 = {}) {
|
async function api(path, opts = {}) {
|
||||||
const resp = await fetch(path, {
|
const resp = await fetch(path, {
|
||||||
@@ -183,10 +246,35 @@ function esc(s) {
|
|||||||
return div.innerHTML;
|
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() {
|
async function load() {
|
||||||
try {
|
try {
|
||||||
const [me, d] = await Promise.all([api('/api/auth/me'), api('/api/jobs/today')]);
|
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('who').textContent = me.nickname || me.username;
|
||||||
document.getElementById('stApplied').textContent = d.applied;
|
document.getElementById('stApplied').textContent = d.applied;
|
||||||
document.getElementById('stSkipped').textContent = d.skipped;
|
document.getElementById('stSkipped').textContent = d.skipped;
|
||||||
@@ -202,7 +290,6 @@ async function load() {
|
|||||||
const score = r.ai_score == null || r.ai_score < 0 ? '-'
|
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>';
|
: '<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 remark = r.apply_type === 'skipped' ? (r.skip_reason || '') : (r.ai_reason || '');
|
||||||
// 公司列:未拉黑时显示快捷拉黑按钮
|
|
||||||
const company = r.company || '';
|
const company = r.company || '';
|
||||||
const blBtn = (company && !blSet.has(company))
|
const blBtn = (company && !blSet.has(company))
|
||||||
? '<button class="bl-btn" data-company="' + esc(company) + '">拉黑</button>' : '';
|
? '<button class="bl-btn" data-company="' + esc(company) + '">拉黑</button>' : '';
|
||||||
@@ -211,20 +298,32 @@ async function load() {
|
|||||||
'</td><td class="remark" title="' + esc(remark) + '">' + esc(remark) + '</td></tr>';
|
'</td><td class="remark" title="' + esc(remark) + '">' + esc(remark) + '</td></tr>';
|
||||||
}).join('');
|
}).join('');
|
||||||
document.getElementById('empty').classList.toggle('hidden', (d.items || []).length > 0);
|
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 内处理 */ }
|
} catch (e) { /* 401 已在 api 内处理 */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- 公司黑名单 ---------- */
|
/* ---------- 公司黑名单 ---------- */
|
||||||
async function loadBlacklist() {
|
async function loadBlacklist() {
|
||||||
try {
|
try {
|
||||||
const items = await api('/api/blacklist');
|
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));
|
blSet = new Set(items.map(i => i.company));
|
||||||
const tbody = document.getElementById('blTbody');
|
const tbody = document.getElementById('blTbody');
|
||||||
tbody.innerHTML = items.map((i, idx) =>
|
tbody.innerHTML = items.map((i, idx) =>
|
||||||
'<tr><td>' + (idx + 1) + '</td><td>' + esc(i.company) + '</td><td>' + esc(i.created_at) +
|
'<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>'
|
'</td><td><button class="bl-remove" data-id="' + i.id + '">移除</button></td></tr>'
|
||||||
).join('');
|
).join('');
|
||||||
document.getElementById('blEmpty').classList.toggle('hidden', items.length > 0);
|
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 内处理 */ }
|
} catch (e) { /* 401 已在 api 内处理 */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,6 +332,7 @@ async function addBlacklist(company) {
|
|||||||
if (!company) return;
|
if (!company) return;
|
||||||
try {
|
try {
|
||||||
await api('/api/blacklist', { method: 'POST', body: JSON.stringify({ company }) });
|
await api('/api/blacklist', { method: 'POST', body: JSON.stringify({ company }) });
|
||||||
|
blState.page = 1; // 新拉黑按时间倒序排第一,回到首页才能看到
|
||||||
await loadBlacklist();
|
await loadBlacklist();
|
||||||
await load(); // 刷新快捷拉黑按钮状态
|
await load(); // 刷新快捷拉黑按钮状态
|
||||||
alert('已拉黑:' + company + ',后续不再投递该公司');
|
alert('已拉黑:' + company + ',后续不再投递该公司');
|
||||||
@@ -242,7 +342,9 @@ async function addBlacklist(company) {
|
|||||||
async function removeBlacklist(id) {
|
async function removeBlacklist(id) {
|
||||||
try {
|
try {
|
||||||
await api('/api/blacklist/' + id, { method: 'DELETE' });
|
await api('/api/blacklist/' + id, { method: 'DELETE' });
|
||||||
await loadBlacklist();
|
const d = await loadBlacklist();
|
||||||
|
// 删掉末页最后一条时当前页会超出总页数,退回上一页
|
||||||
|
if (d && d.page > d.pages && d.pages >= 1) { blState.page = d.pages; await loadBlacklist(); }
|
||||||
} catch (e) { alert('移除失败:' + (e.message || '')); }
|
} catch (e) { alert('移除失败:' + (e.message || '')); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,9 +352,9 @@ async function removeBlacklist(id) {
|
|||||||
function switchPage(page) {
|
function switchPage(page) {
|
||||||
document.querySelectorAll('aside .menu-item').forEach(el =>
|
document.querySelectorAll('aside .menu-item').forEach(el =>
|
||||||
el.classList.toggle('active', el.dataset.page === page));
|
el.classList.toggle('active', el.dataset.page === page));
|
||||||
document.getElementById('pageToday').classList.toggle('hidden', page !== 'today');
|
document.getElementById('pageData').classList.toggle('hidden', page !== 'data');
|
||||||
document.getElementById('pageBlacklist').classList.toggle('hidden', page !== 'blacklist');
|
document.getElementById('pageBlacklist').classList.toggle('hidden', page !== 'blacklist');
|
||||||
if (page === 'today') load(); else loadBlacklist();
|
if (page === 'data') load(); else loadBlacklist();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- 事件绑定 ---------- */
|
/* ---------- 事件绑定 ---------- */
|
||||||
@@ -261,6 +363,38 @@ document.getElementById('password').addEventListener('keydown', e => { if (e.key
|
|||||||
document.getElementById('btnLogout').onclick = logout;
|
document.getElementById('btnLogout').onclick = logout;
|
||||||
document.querySelectorAll('aside .menu-item').forEach(el =>
|
document.querySelectorAll('aside .menu-item').forEach(el =>
|
||||||
el.addEventListener('click', () => switchPage(el.dataset.page)));
|
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 = () => {
|
document.getElementById('btnBlAdd').onclick = () => {
|
||||||
const input = document.getElementById('blCompany');
|
const input = document.getElementById('blCompany');
|
||||||
addBlacklist(input.value);
|
addBlacklist(input.value);
|
||||||
@@ -269,7 +403,8 @@ document.getElementById('btnBlAdd').onclick = () => {
|
|||||||
document.getElementById('blCompany').addEventListener('keydown', e => {
|
document.getElementById('blCompany').addEventListener('keydown', e => {
|
||||||
if (e.key === 'Enter') document.getElementById('btnBlAdd').click();
|
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('blTbody').addEventListener('click', e => {
|
document.getElementById('blTbody').addEventListener('click', e => {
|
||||||
const btn = e.target.closest('.bl-remove');
|
const btn = e.target.closest('.bl-remove');
|
||||||
if (btn) removeBlacklist(btn.dataset.id);
|
if (btn) removeBlacklist(btn.dataset.id);
|
||||||
@@ -283,13 +418,18 @@ document.getElementById('tbody').addEventListener('click', e => {
|
|||||||
|
|
||||||
async function enter() {
|
async function enter() {
|
||||||
showData();
|
showData();
|
||||||
|
// 自定义日期默认填入今天
|
||||||
|
const today = fmt(new Date());
|
||||||
|
document.getElementById('dateStart').value = today;
|
||||||
|
document.getElementById('dateEnd').value = today;
|
||||||
await loadBlacklist();
|
await loadBlacklist();
|
||||||
await load();
|
await load();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token()) enter(); else showLogin();
|
if (token()) enter(); else showLogin();
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (token() && !document.getElementById('dataView').classList.contains('hidden')) load();
|
if (token() && !document.getElementById('dataView').classList.contains('hidden')
|
||||||
|
&& !document.getElementById('pageData').classList.contains('hidden')) load();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user