Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2da005ecca | ||
|
|
4e40f486d5 | ||
|
|
039ad42025 |
@@ -191,15 +191,10 @@ def api_playoffs():
|
||||
def api_news():
|
||||
q = request.args.get("q", "")
|
||||
kind = request.args.get("kind", "")
|
||||
limit = int(request.args.get("limit", 20))
|
||||
if q:
|
||||
r = tools.search_news(q, limit=limit)
|
||||
return jsonify(r.get("results", []))
|
||||
from db import query
|
||||
rows = query("""SELECT id,title,author,source,publish_time,tags,kind,substr(content,1,160) AS summary
|
||||
FROM news WHERE (?='' OR kind=?) ORDER BY publish_time DESC, id DESC LIMIT ?""",
|
||||
(kind, kind, limit))
|
||||
return jsonify(rows)
|
||||
tag = request.args.get("tag", "")
|
||||
page = max(1, int(request.args.get("page", 1)))
|
||||
size = min(30, max(1, int(request.args.get("size", 10))))
|
||||
return jsonify(tools.list_news(q, kind=kind, tag=tag, page=page, size=size))
|
||||
|
||||
|
||||
@app.route("/api/news/<int:nid>")
|
||||
|
||||
+22
-5
@@ -92,7 +92,12 @@ function loadView(v) {
|
||||
$$("#view-games .btn.small").forEach((x) => x.classList.toggle("active", x.dataset.status === ""));
|
||||
loadGames();
|
||||
}
|
||||
else if (v === "news") loadNews("");
|
||||
else if (v === "news") {
|
||||
newsPage = 1; newsQ = ""; newsKind = ""; newsTag = "";
|
||||
$("#search-news").value = "";
|
||||
$$("#view-news .btn.small").forEach((x) => x.classList.toggle("active", !x.dataset.kind && !x.dataset.tag));
|
||||
loadNews();
|
||||
}
|
||||
else if (v === "persons") loadPersons("");
|
||||
else if (v === "standings") {
|
||||
if ($("#season-select").options.length) { loadStandings(); loadPlayoffs(); }
|
||||
@@ -411,6 +416,7 @@ function renderPager(d, key) {
|
||||
function goPage(key, p) {
|
||||
if (key === "players") { playersPage = p; loadPlayers(); }
|
||||
else if (key === "games") { gamesPage = p; loadGames(); }
|
||||
else if (key === "news") { newsPage = p; loadNews(); }
|
||||
}
|
||||
|
||||
$("#btn-players").addEventListener("click", () => { playersQ = $("#search-players").value.trim(); playersPage = 1; loadPlayers(); });
|
||||
@@ -497,8 +503,10 @@ async function openGame(id) {
|
||||
}
|
||||
|
||||
/* ================= 新闻 ================= */
|
||||
async function loadNews(q) {
|
||||
const news = await getJSON(`/api/news?q=${encodeURIComponent(q)}&limit=30`);
|
||||
let newsPage = 1, newsQ = "", newsKind = "", newsTag = "";
|
||||
async function loadNews() {
|
||||
const d = await getJSON(`/api/news?q=${encodeURIComponent(newsQ)}&kind=${newsKind}&tag=${encodeURIComponent(newsTag)}&page=${newsPage}&size=10`);
|
||||
const news = d.results || [];
|
||||
$("#list-news").innerHTML = news.map((n) => `
|
||||
<div class="list-item" onclick="openNews(${n.id})">
|
||||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">
|
||||
@@ -507,10 +515,19 @@ async function loadNews(q) {
|
||||
</div>
|
||||
<div class="meta">🕐 ${esc(n.publish_time)} · ${esc(n.source)}${n.author ? " · " + esc(n.author) : ""}</div>
|
||||
<div class="meta" style="margin-top:4px">${esc(n.summary || n.content || "")}…</div>
|
||||
</div>`).join("");
|
||||
</div>`).join("") || '<div class="meta">没有符合条件的新闻</div>';
|
||||
renderPager(d, "news");
|
||||
}
|
||||
$("#btn-news").addEventListener("click", () => loadNews($("#search-news").value.trim()));
|
||||
$("#btn-news").addEventListener("click", () => { newsQ = $("#search-news").value.trim(); newsPage = 1; loadNews(); });
|
||||
$("#search-news").addEventListener("keydown", (e) => { if (e.key === "Enter") $("#btn-news").click(); });
|
||||
$$("#view-news .btn.small").forEach((b) => b.addEventListener("click", () => {
|
||||
$$("#view-news .btn.small").forEach((x) => x.classList.remove("active"));
|
||||
b.classList.add("active");
|
||||
newsKind = b.dataset.kind;
|
||||
newsTag = b.dataset.tag;
|
||||
newsPage = 1;
|
||||
loadNews();
|
||||
}));
|
||||
async function openNews(id) {
|
||||
const n = await getJSON(`/api/news/${id}`);
|
||||
openModal(`
|
||||
|
||||
+11
-1
@@ -82,8 +82,18 @@
|
||||
<div class="pager" id="pager-games"></div>
|
||||
</section>
|
||||
<section id="view-news" class="view">
|
||||
<div class="toolbar"><input class="search" id="search-news" placeholder="搜索新闻关键词"><button class="btn" id="btn-news">搜索</button></div>
|
||||
<div class="toolbar">
|
||||
<button class="btn small active" data-kind="" data-tag="">全部</button>
|
||||
<button class="btn small" data-kind="news" data-tag="">新闻</button>
|
||||
<button class="btn small" data-kind="wiki" data-tag="">百科</button>
|
||||
<button class="btn small" data-kind="" data-tag="总决赛">总决赛</button>
|
||||
<button class="btn small" data-kind="" data-tag="续约">续约</button>
|
||||
<button class="btn small" data-kind="" data-tag="中国球员">中国球员</button>
|
||||
<button class="btn small" data-kind="" data-tag="选秀">选秀</button>
|
||||
<input class="search" id="search-news" placeholder="搜索新闻关键词"><button class="btn" id="btn-news">搜索</button>
|
||||
</div>
|
||||
<div class="list" id="list-news"></div>
|
||||
<div class="pager" id="pager-news"></div>
|
||||
</section>
|
||||
<section id="view-persons" class="view">
|
||||
<div class="toolbar">
|
||||
|
||||
+3
-3
@@ -133,9 +133,9 @@ main { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 20px 16
|
||||
.pager button:disabled { opacity: .35; cursor: default; }
|
||||
.pager span { margin: 0 4px; }
|
||||
|
||||
/* ---------- 比赛网格卡片(固定宽度,宽度足够一行多个) ---------- */
|
||||
.games-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); align-items: stretch; }
|
||||
.games-grid .list-item { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; height: 100%; padding: 14px 16px; }
|
||||
/* ---------- 比赛网格卡片(固定宽度420px,居中排列) ---------- */
|
||||
.games-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
|
||||
.games-grid .list-item { flex: 0 0 420px; width: 420px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; height: 100%; padding: 14px 16px; }
|
||||
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; transition: .18s; }
|
||||
.card:hover { transform: translateY(-3px); border-color: var(--orange2); box-shadow: 0 6px 20px rgba(0,0,0,.35); }
|
||||
.card h3 { font-size: 15.5px; margin-bottom: 4px; }
|
||||
|
||||
@@ -351,6 +351,28 @@ def player_game_logs(player_id, limit=10):
|
||||
return out
|
||||
|
||||
|
||||
# ================================================================== 新闻列表(前台分页版)
|
||||
def list_news(q="", kind="", tag="", page=1, size=10):
|
||||
"""前台新闻列表:关键词 + 类型(kind) + 话题标签(tag) + 分页"""
|
||||
conds, args = [], []
|
||||
if q:
|
||||
like = f"%{fuzzy(q)}%"
|
||||
conds.append("(title LIKE ? ESCAPE '\\' OR content LIKE ? ESCAPE '\\' OR tags LIKE ? ESCAPE '\\')")
|
||||
args += [like, like, like]
|
||||
if kind:
|
||||
conds.append("kind=?")
|
||||
args.append(kind)
|
||||
if tag:
|
||||
conds.append("tags LIKE ? ESCAPE '\\'")
|
||||
args.append(f"%{fuzzy(tag)}%")
|
||||
where = ("WHERE " + " AND ".join(conds)) if conds else ""
|
||||
total = query_one(f"SELECT COUNT(*) AS c FROM news {where}", args)["c"]
|
||||
rows = query(f"""SELECT id,title,author,source,publish_time,tags,kind,substr(content,1,160) AS summary
|
||||
FROM news {where} ORDER BY publish_time DESC, id DESC LIMIT ? OFFSET ?""",
|
||||
args + [size, (page - 1) * size])
|
||||
return {"results": rows, "total": total, "page": page, "size": size}
|
||||
|
||||
|
||||
# ================================================================== 新闻(SQL 关键词 + 向量语义 + 可选 rerank 融合)
|
||||
def search_news(query_text, limit=5):
|
||||
q = (query_text or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user