Преглед изворни кода

feat: 支持 URL ?videoId=xxx 参数,自动按选题召回(0点击)

无 videoId 参数时保持原有行为(默认 ID 64632804,不自动召回)。
有 videoId 时,首次查询完成后若选题存在则自动触发 VIDEO_TOPIC 召回,
admin 端可通过该参数实现从外部页面跳转直达召回结果。
刘立冬 пре 3 дана
родитељ
комит
ff2212e820
1 измењених фајлова са 23 додато и 1 уклоњено
  1. 23 1
      src/pages/RecallTestPage.tsx

+ 23 - 1
src/pages/RecallTestPage.tsx

@@ -45,6 +45,14 @@ import type {
 const { TextArea } = Input
 const { TextArea } = Input
 const { Text, Title } = Typography
 const { Text, Title } = Typography
 
 
+/** 从 URL ?videoId=xxx 读取并校验,无效返回 null */
+function readUrlVideoId(): number | null {
+  const raw = new URLSearchParams(window.location.search).get('videoId')
+  if (!raw) return null
+  const n = Number(raw)
+  return Number.isFinite(n) && n > 0 ? n : null
+}
+
 /** 从召回结果里剔除指定视频ID, 同时刷新 modality 计数 */
 /** 从召回结果里剔除指定视频ID, 同时刷新 modality 计数 */
 function filterOutSelf(data: RecallResultVO, excludeId: number | null): RecallResultVO {
 function filterOutSelf(data: RecallResultVO, excludeId: number | null): RecallResultVO {
   if (!excludeId) return data
   if (!excludeId) return data
@@ -120,7 +128,10 @@ export default function RecallTestPage() {
 const DEFAULT_VIDEO_ID = 64632804
 const DEFAULT_VIDEO_ID = 64632804
 
 
 function VideoIdTab() {
 function VideoIdTab() {
-  const [videoId, setVideoId] = useState<number | null>(DEFAULT_VIDEO_ID)
+  /** URL 上 ?videoId=xxx 优先于默认 ID;有则首次查询后自动按选题召回 */
+  const urlVideoId = readUrlVideoId()
+  const [videoId, setVideoId] = useState<number | null>(urlVideoId ?? DEFAULT_VIDEO_ID)
+  const pendingAutoRecallRef = useRef(urlVideoId !== null)
   const [detail, setDetail] = useState<VideoBasicVO | null>(null)
   const [detail, setDetail] = useState<VideoBasicVO | null>(null)
   const [ai, setAi] = useState<AIUnderstandingVO | null>(null)
   const [ai, setAi] = useState<AIUnderstandingVO | null>(null)
   const [points, setPoints] = useState<DeconstructPointsVO | null>(null)
   const [points, setPoints] = useState<DeconstructPointsVO | null>(null)
@@ -205,6 +216,17 @@ function VideoIdTab() {
     [topN, videoId],
     [topN, videoId],
   )
   )
 
 
+  /** URL 传入 videoId 时, 首次查询结束后自动按"选题"维度召回 (0 点击) */
+  useEffect(() => {
+    if (!pendingAutoRecallRef.current) return
+    if (!autoQueriedRef.current) return
+    if (loadingMain) return
+    pendingAutoRecallRef.current = false
+    if (points?.topic && points.topic.trim()) {
+      onRecallByText(points.topic, 'VIDEO_TOPIC')
+    }
+  }, [loadingMain, points, onRecallByText])
+
   return (
   return (
     <Space direction="vertical" size={16} style={{ width: '100%' }}>
     <Space direction="vertical" size={16} style={{ width: '100%' }}>
       {/* 查询条 */}
       {/* 查询条 */}