feat(danmaku): 支持快捷填入当前片名并优化重新搜索机制

This commit is contained in:
truewhile
2026-09-06 20:32:12 +08:00
parent 465e98a792
commit 394d1a3cda
4 changed files with 38 additions and 5 deletions
+5 -2
View File
@@ -28,6 +28,8 @@ type DanmakuStageProps = {
search?: string | null
/** Explicit danmaku library chosen by the user; null = auto-resolve. */
episodeId?: number | string | null
/** Counter or token changed to trigger refetch even when search stays identical. */
searchTrigger?: number
/** Called after each fetch attempt (success or error) finishes with metadata. */
onLoaded?: (info: DanmakuLoadedInfo | null) => void
/** Called when multiple anime matched and the user must pick one. */
@@ -50,6 +52,7 @@ export function DanmakuStage({
area = 1,
search = null,
episodeId = null,
searchTrigger = 0,
onLoaded,
onCandidates,
}: DanmakuStageProps) {
@@ -252,8 +255,8 @@ export function DanmakuStage({
manager.unmount()
managerRef.current = null
}
// search / episodeId 变化时重新拉取弹幕(含媒体/开关切换)。
}, [media, videoRef, enabled, search, episodeId, onLoaded, onCandidates])
// search / episodeId / searchTrigger 变化时重新拉取弹幕(含媒体/开关切换)。
}, [media, videoRef, enabled, search, episodeId, searchTrigger, onLoaded, onCandidates])
// Live renderer knobs: opacity / area / font size without recreating the
// engine. font size additionally rescales currently visible comments.
+18 -3
View File
@@ -25,6 +25,8 @@ type PlayerDanmakuPanelProps = {
candidates: DanmakuAnime[]
/** Human-readable label of the currently selected library. */
selectedSource?: string
/** Title used by auto-matching (e.g. anime title, media title or filename). */
autoMatchTitle?: string
/** Loaded danmaku metadata (title, episode, count, match mode). */
danmakuInfo?: DanmakuLoadedInfo | null
onSelectEpisode: (episodeId: number, animeTitle: string, episodeTitle: string) => void
@@ -47,6 +49,7 @@ export function PlayerDanmakuPanel({
onFontSizeChange,
candidates,
selectedSource,
autoMatchTitle,
danmakuInfo,
onSelectEpisode,
onResetAuto,
@@ -203,7 +206,19 @@ export function PlayerDanmakuPanel({
{/* 搜索弹幕 */}
<div className="mb-4">
<div className="mb-1 text-xs text-white/60">搜索弹幕(留空 = 按视频名自动匹配)</div>
<div className="mb-1 flex items-center justify-between text-xs text-white/60">
<span>搜索弹幕(留空 = 按视频名自动匹配)</span>
{autoMatchTitle && (
<button
type="button"
onClick={() => setDraft(autoMatchTitle)}
className="text-[11px] text-rose-300 transition hover:text-rose-200"
title="填入当前识别到的视频名"
>
填入当前名
</button>
)}
</div>
<div className="flex items-center gap-1.5">
<input
value={draft}
@@ -211,8 +226,8 @@ export function PlayerDanmakuPanel({
onKeyDown={(e) => {
if (e.key === 'Enter') onSearch(draft.trim())
}}
placeholder="输入番剧或电影名…"
className="min-w-0 flex-1 rounded-lg border border-white/15 bg-white/5 px-2.5 py-1.5 text-xs outline-none placeholder:text-white/35 focus:border-rose-400/60"
placeholder={autoMatchTitle ? `自动匹配:${autoMatchTitle}` : '输入番剧或电影名…'}
className="min-w-0 flex-1 rounded-lg border border-white/15 bg-white/5 px-2.5 py-1.5 text-xs outline-none placeholder:text-white/40 focus:border-rose-400/60"
/>
<button
onClick={() => onSearch(draft.trim())}