Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions frontend/src/app/today-picks/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'lucide-react';
import { contentsApi } from '@/lib/api';
import { PICKS_VIEWS, picksViewHref, readPicksView, readSnapshotDays, type PicksView } from '@/lib/picks-view';
import keywordStyles from '../trends/_keyword-index.module.css';
import TrendExplorer from '../trends/TrendExplorer';
import type { EvidenceMark } from '@/types';
import { useAppContext } from '@/components/ClientLayout';
Expand Down Expand Up @@ -343,7 +344,7 @@ function TodayPicksPage() {

return (
<div ref={scrollRef} onScroll={event => { if (restoringScroll.current === null) viewScrolls.current[scrollKey] = event.currentTarget.scrollTop; }} className="workspace-scroll">
<div className="sticky top-0 z-10 -mx-4 sm:-mx-6 lg:-mx-10 border-b border-gray-200 bg-[#F8FAFC]/90 px-4 sm:px-6 lg:px-10 pb-4 backdrop-blur-xl">
<div className={cx("sticky top-0 z-10 -mx-4 sm:-mx-6 lg:-mx-10 border-b border-gray-200 bg-[#F8FAFC]/90 px-4 sm:px-6 lg:px-10 pb-4 backdrop-blur-xl", pageView === 'keywords' && keywordStyles.workspaceHeader)}>
<div className="mx-auto flex max-w-[1200px] flex-wrap items-center gap-3">
<div className="min-w-0 flex-1">
<div className="flex items-center gap-3">
Expand All @@ -352,9 +353,9 @@ function TodayPicksPage() {
<h1 className="page-title text-gray-900">当日精选</h1>
</div>
</div>
<p className="mt-1 hidden text-sm leading-6 text-gray-600 sm:block">
{pageView !== 'keywords' && <p className="mt-1 hidden text-sm leading-6 text-gray-600 sm:block">
{pageView === 'picks' ? '从算法候选中筛出可写选题,按话题、质量和来源做二次判断' : '补充查看公共收录的材料与标签分布,观察窗口独立于精选筛选'}
</p>
</p>}
</div>
{pageView === 'picks' && <Button
type="button"
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/app/trends/KeywordIndex.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it } from 'vitest';
import KeywordIndex from './KeywordIndex';

const longName = '人工智能在内容创作与研究工作流中的可靠性评估';
const words = Array.from({ length: 60 }, (_, i) => ({ keyword: i === 59 ? longName : `关键词${String(i + 1).padStart(2, '0')}`, count: 59 - i }));

describe('热词频率索引', () => {
it('全部条目保持接口顺序,零频次与长词仍有完整来源入口', () => {
const html = renderToStaticMarkup(<KeywordIndex words={words} selectedKeyword={null} onSelect={() => {}} />);
expect((html.match(/aria-haspopup="dialog"/g) || []).length).toBe(60);
expect(html.indexOf('关键词03')).toBeLessThan(html.indexOf('关键词04'));
expect(html.indexOf('关键词04')).toBeLessThan(html.indexOf(longName));
expect(html).toContain(`aria-label="查看关键词「${longName}」的来源明细"`);
expect(html).toMatch(/>0<span[^>]*>条/);
});
it('来源展开状态只标记所选原始词名,不按显示名或次数合并', () => {
const html = renderToStaticMarkup(<KeywordIndex words={[{ keyword: 'ai', count: 10000 }, { keyword: 'AI', count: 10000 }]} selectedKeyword="AI" onSelect={() => {}} />);
expect((html.match(/aria-expanded="true"/g) || []).length).toBe(1);
expect(html).toMatch(/aria-label="查看关键词「AI」的来源明细"[^>]*aria-expanded="true"/);
expect(html).toContain('10,000');
expect(html).not.toContain('%');
});
});
38 changes: 38 additions & 0 deletions frontend/src/app/trends/KeywordIndex.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use client';

import { ArrowRight } from 'lucide-react';
import type { TrendKeywordItem } from '@/types/trends';
import TitleText from './_title-text';
import styles from './_keyword-index.module.css';

export default function KeywordIndex({
words,
selectedKeyword,
onSelect,
}: {
words: TrendKeywordItem[];
selectedKeyword: string | null;
onSelect: (keyword: string) => void;
}) {
return (
<ol className={styles.index} aria-label="按收录内容数排序的关键词">
{words.map((word, index) => (
<li key={word.keyword}>
<button
type="button"
className={styles.word}
aria-label={`查看关键词「${word.keyword}」的来源明细`}
aria-haspopup="dialog"
aria-expanded={selectedKeyword === word.keyword}
onClick={() => onSelect(word.keyword)}
>
<span className={styles.rank} aria-hidden>{String(index + 1).padStart(2, '0')}</span>
<span className={styles.name}><TitleText title={word.keyword} /></span>
<span className={styles.count}>{word.count.toLocaleString('zh-CN')}<span className={styles.unit}>条</span></span>
<ArrowRight className={styles.arrow} size={16} aria-hidden />
</button>
</li>
))}
</ol>
);
}
25 changes: 15 additions & 10 deletions frontend/src/app/trends/TrendExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React, { useEffect, useRef, useState } from 'react';
import { ArrowDownRight, ArrowUpRight, ArrowRight, RefreshCw } from 'lucide-react';
import { Button, Panel, cx } from '@/components/ui';
import { Button, cx } from '@/components/ui';
import { EmptyState, ErrorState, LoadingState } from '@/components/StateView';
import { useFetch } from '@/hooks/useFetch';
import { trendsApi } from '@/lib/api';
Expand All @@ -12,6 +12,8 @@ import { buildTrendModel } from './_trend-model';
import TopicMaterials from './TopicMaterials';
import TitleText from './_title-text';
import styles from './page.module.css';
import KeywordIndex from './KeywordIndex';
import keywordStyles from './_keyword-index.module.css';

type View = 'topics' | 'keywords';
const WINDOWS = [3, 7, 14, 30];
Expand Down Expand Up @@ -42,18 +44,22 @@ export default function TrendExplorer({ view, days, onDaysChange, onReady, initi
setSelectedTopic(null);
requestAnimationFrame(() => { const trigger = triggerRefs.current.get(id); trigger?.focus({ preventScroll: true }); trigger?.scrollIntoView({ block: 'nearest', behavior: 'instant' }); });
};
return <div className={styles.page}>
<div className={cx(styles.controls, "mt-4 flex flex-wrap items-center justify-between gap-3")} aria-label="趋势筛选">
const controls = (<div className={cx(styles.controls, view === 'keywords' && keywordStyles.controls, "mt-4 flex flex-wrap items-center justify-between gap-3")} aria-label="趋势筛选">
<div role="group" aria-label="观察窗口" className="relative grid w-full grid-cols-4 rounded-sm bg-gray-100 p-1 sm:w-[280px]">
<span aria-hidden className={cx(styles.indicator, 'absolute bottom-1 left-1 top-1 rounded-xs bg-white shadow-sm')} style={{ width: 'calc((100% - 8px) / 4)', transform: `translateX(${WINDOWS.indexOf(days) * 100}%)` }} />
{WINDOWS.map(value => <button key={value} type="button" aria-pressed={days === value} onClick={() => changeDays(value)} className={cx(styles.press, 'relative min-h-9 rounded-xs px-3 text-sm font-semibold focus-visible:outline-2 focus-visible:outline-primary', days === value ? 'text-primary-text' : 'text-gray-600')}>{value}天</button>)}
</div>
<Button variant="ghost" type="button" disabled={busy} onClick={() => { setSelectedTopic(null); void refetch(); }} className="min-h-9 text-xs"><RefreshCw size={14} className={busy ? 'animate-spin motion-reduce:animate-none' : ''} />刷新{view === 'topics' ? '材料' : '热词'}</Button>
</div>
<div className={styles.edition}>
<p role="status">{busy ? `正在读取近 ${days} 天的${view === 'topics' ? '话题线索' : '高频热词'}…` : view === 'keywords' ? (current ? `近 ${days} 天 · 公共内容标签频率` : '尚未取得当前窗口数据') : model.latestDate ? `数据截至 ${dateLabel(model.latestDate)} · 近 ${days} 天有 ${model.recordedDays} 个记录日` : error ? '尚未取得当前窗口数据' : `近 ${days} 天暂无快照`}</p>
{current && !busy && (view === 'topics' ? <p aria-label="话题快照统计"><b>{model.topics.length}</b> 个话题 <span> / </span><b>{model.totalContent}</b> 条收录 <span> / </span><b>{model.totalPicks}</b> 条入选</p> : <p>显示 <b>{words.length}</b> 个关键词</p>)}
</div>
</div>);
return <div className={styles.page}>
{view === 'keywords' ? <header className={keywordStyles.header}><h2>高频热词</h2>{controls}</header> : controls}
{view === 'keywords' ? <div className={keywordStyles.meta}>
<p role="status">{busy ? `正在读取近 ${days} 天的高频热词…` : current ? <>近 {days} 天<span className={keywordStyles.dot}>·</span><span><b>{words.length}</b> 个关键词</span><span className={keywordStyles.dot}>·</span><span>按内容数排序</span></> : '尚未取得当前窗口数据'}</p>
<details className={keywordStyles.help}><summary>统计说明</summary><p>来自公共收录内容的分析标签。数值为带有该标签的内容数,一条内容可对应多个关键词,计数不能相加。点击词条查看来源。</p></details>
</div> : <div className={styles.edition}>
<p role="status">{busy ? `正在读取近 ${days} 天的话题线索…` : model.latestDate ? `数据截至 ${dateLabel(model.latestDate)} · 近 ${days} 天有 ${model.recordedDays} 个记录日` : error ? '尚未取得当前窗口数据' : `近 ${days} 天暂无快照`}</p>
{current && !busy && <p aria-label="话题快照统计"><b>{model.topics.length}</b> 个话题 <span> / </span><b>{model.totalContent}</b> 条收录 <span> / </span><b>{model.totalPicks}</b> 条入选</p>}
</div>}
{error && <div className="mt-3"><ErrorState error={error} onRetry={() => void refetch()} panel={false} />{current && <p className="text-xs text-gray-500">以下保留当前窗口上次成功读取的快照。</p>}</div>}
{busy ? <LoadingState label="加载趋势快照…" minHeight="180px" /> : current && <div className={entered ? undefined : styles.enter} onAnimationEnd={() => setEntered(true)}>
<section id="trends-topics-panel" aria-label="话题线索" hidden={view !== 'topics'} tabIndex={0}>
Expand All @@ -77,8 +83,7 @@ export default function TrendExplorer({ view, days, onDaysChange, onReady, initi
{shown.length < model.topics.length && <Button variant="secondary" type="button" onClick={() => { setLimit(model.topics.length); onLimitChange?.(model.topics.length); }} className="mt-3 w-full">查看其余 {model.topics.length - shown.length} 个话题</Button>}
</section>
<section id="trends-keywords-panel" aria-label="高频热词" hidden={view !== 'keywords'} tabIndex={0}>
<div className={styles.sectionHeading}><h2>高频热词</h2></div><p className="mb-4 text-sm leading-6 text-gray-600">来自公共收录内容的分析标签;数值为带有该标签的内容数,同一内容可贡献多个标签。点击查看来源。</p>
{!words.length ? <EmptyState title="暂无关键词数据" desc="关键词快照生成后会在这里展示。" /> : <div className="grid gap-2.5 sm:grid-cols-2 lg:grid-cols-3">{words.map(word => <Panel key={word.keyword}><button type="button" onClick={() => openKeyword(word.keyword)} className={cx(styles.press, 'block min-h-20 w-full rounded-sm p-4 text-left focus-visible:outline-2 focus-visible:outline-primary')} aria-label={`查看关键词「${word.keyword}」的来源明细`}><span className="flex justify-between gap-3"><span className="min-w-0 break-words text-sm font-semibold text-gray-900">{word.keyword}</span><span className="font-mono text-sm text-gray-600">{word.count}</span></span><span className="mt-3 block h-1 overflow-hidden rounded-full bg-gray-100"><span className="block h-full bg-gray-400" style={{ width: `${Math.min(100, Math.max(0, word.count / Math.max(...words.map(item => item.count), 1) * 100))}%` }} /></span></button></Panel>)}</div>}
{!words.length ? <EmptyState title="暂无关键词数据" desc="关键词快照生成后会在这里展示。" /> : <KeywordIndex words={words} selectedKeyword={evidence?.kind === 'keyword' ? evidence.keyword : null} onSelect={openKeyword} />}
</section>
</div>}
<TrendEvidenceDrawer request={evidence} onClose={() => setEvidence(null)} />
Expand Down
71 changes: 71 additions & 0 deletions frontend/src/app/trends/_keyword-index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* A single reading surface: rank is the hierarchy, count is never a trend score. */
.workspaceHeader { display:flex; align-items:center; gap:32px; padding-bottom:0; }
.workspaceHeader > div:first-child { margin-inline:0; flex:1; }
.workspaceHeader > [role=tablist] { margin-top:0; margin-inline:0; flex-shrink:0; }
.workspaceHeader > [role=tablist] button { min-height:56px; }

.header { display:flex; align-items:center; justify-content:space-between; gap:20px; margin-top:26px; }
.header h2 { margin:0; color:var(--color-gray-900); font-size:28px; font-weight:700; line-height:1.35; letter-spacing:-.035em; }
.header .controls { display:flex; flex-wrap:nowrap; align-items:center; justify-content:flex-end; gap:14px; margin-top:0; }
.header .controls > [role=group] { width:252px; }
.header .controls button { min-height:40px; font-size:14px; }
.meta { position:relative; display:flex; align-items:start; justify-content:space-between; gap:12px 24px; margin:12px 0 22px; color:var(--color-gray-600); font-size:13px; line-height:1.8; }
.meta > p { display:flex; flex-wrap:wrap; align-items:baseline; gap:0 8px; margin:0; }
.meta b { color:var(--color-gray-800); font-weight:600; }
.dot { color:var(--color-gray-500); }
.help { position:relative; flex-shrink:0; }
.help summary { min-height:28px; padding-inline:3px; cursor:pointer; list-style:none; text-decoration:underline; text-decoration-color:var(--color-gray-300); text-underline-offset:4px; }
.help summary::-webkit-details-marker { display:none; }
.help summary:hover { color:var(--color-primary-text); }
.help summary:focus-visible { outline:2px solid var(--color-primary-solid); outline-offset:3px; border-radius:3px; }
.help > p { position:absolute; z-index:5; right:0; top:34px; width:300px; max-width:calc(100vw - 40px); margin:0; padding:16px 18px; border:1px solid var(--color-gray-200); border-radius:8px; background:white; box-shadow:0 8px 24px #11182712; color:var(--color-gray-700); font-size:14px; line-height:1.8; }

.index { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); column-gap:30px; margin:0; padding:0 26px 12px; list-style:none; border:1px solid var(--color-gray-200); border-radius:12px; background:white; }
.index > li { display:flex; min-width:0; }
.word { position:relative; display:grid; grid-template-columns:26px minmax(0,1fr) auto 16px; align-items:center; gap:12px; width:100%; min-height:62px; padding:14px 2px; border-bottom:1px solid var(--color-gray-200); text-align:left; cursor:pointer; border-radius:2px; transition:background-color 140ms, color 140ms; }
.rank { color:var(--color-gray-600); font-family:var(--font-mono); font-size:13px; line-height:1.6; }
.name { min-width:0; color:var(--color-gray-900); font-size:15px; font-weight:600; line-height:1.65; overflow-wrap:anywhere; }
.count { display:inline-flex; align-items:baseline; gap:4px; color:var(--color-gray-700); font-family:var(--font-mono); font-size:14px; font-variant-numeric:tabular-nums; line-height:1.5; white-space:nowrap; }
.unit { color:var(--color-gray-600); font-family:var(--font-sans); font-size:13px; font-weight:400; }
.arrow { justify-self:end; color:var(--color-gray-500); transition:transform 140ms,color 140ms; }
.word:hover,.word[aria-expanded=true] { background:var(--color-primary-light); }
.word:hover .name,.word[aria-expanded=true] .name { color:var(--color-primary-text); }
.word:hover .arrow { transform:translateX(2px); color:var(--color-primary-text); }
.word:active { background:var(--color-primary-soft); }
.word:focus-visible { z-index:1; outline:2px solid var(--color-primary-solid); outline-offset:3px; background:var(--color-primary-light); }
.index > li:nth-child(-n+3) .word { min-height:132px; grid-template-columns:minmax(0,1fr) auto; gap:14px 12px; padding-block:20px; }
.index > li:nth-child(-n+3) .rank { grid-column:1; grid-row:1; color:var(--color-primary-text); }
.index > li:nth-child(-n+3) .arrow { grid-column:2; grid-row:1; }
.index > li:nth-child(-n+3) .name { grid-column:1; grid-row:2; font-size:22px; font-weight:650; line-height:1.4; }
.index > li:nth-child(-n+3) .count { grid-column:2; grid-row:2; color:var(--color-gray-600); font-size:26px; font-weight:500; }

@media (max-width:1099px) {
.index { grid-template-columns:minmax(0,1fr); padding:0 22px 10px; }
.word { min-height:64px; }
.index > li:nth-child(-n+3) .word { min-height:78px; grid-template-columns:26px minmax(0,1fr) auto 16px; gap:12px; padding-block:16px; }
.index > li:nth-child(-n+3) .rank { grid-column:1; grid-row:1; }
.index > li:nth-child(-n+3) .name { grid-column:2; grid-row:1; font-size:18px; line-height:1.6; }
.index > li:nth-child(-n+3) .count { grid-column:3; grid-row:1; font-size:21px; }
.index > li:nth-child(-n+3) .arrow { grid-column:4; grid-row:1; }
}
@media (max-width:749px) {
.workspaceHeader { display:block; }
.workspaceHeader > [role=tablist] { margin-top:10px; }
.workspaceHeader > [role=tablist] button { min-height:44px; }
.header { flex-direction:column; align-items:stretch; gap:12px; margin-top:18px; }
.header h2 { font-size:26px; }
.header .controls { justify-content:space-between; gap:10px; }
.header .controls > [role=group] { width:auto; min-width:0; flex:1; }
.header .controls button { min-height:44px; font-size:14px; }
.meta { gap:8px; margin:8px 0 14px; }
.meta > p { gap:0 6px; }
.index { padding-inline:16px; }
.word { grid-template-columns:22px minmax(0,1fr) auto 16px; gap:9px; }
.index > li:nth-child(-n+3) .word { grid-template-columns:22px minmax(0,1fr) auto 16px; gap:9px; }
.index > li:nth-child(-n+3) .name { font-size:17px; }
.index > li:nth-child(-n+3) .count { font-size:20px; }
}
@media (prefers-reduced-motion:reduce) {
.word,.arrow { transition:none; }
.word:hover .arrow { transform:none; }
}
Loading
Loading