import { useMemo, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import type { AiAnalyzeHistoryItem, Batch } from "../types"; import { fetchAiAnalyzeHistory } from "../services/api"; import { formatSystemTime } from "../utils/time"; type Props = { batches: Batch[]; selectedBatch: string; onSelectBatch: (v: string) => void; aiAlarmCode: string; aiNeName: string; aiSeverity: string; onChangeAiAlarmCode: (v: string) => void; onChangeAiNeName: (v: string) => void; onChangeAiSeverity: (v: string) => void; onResetAiFilters: () => void; question: string; answer: string; isRunning: boolean; enabled: boolean; onChangeQuestion: (v: string) => void; onRunAnalyze: () => void; }; export function AiAnalysisPage({ batches, selectedBatch, onSelectBatch, aiAlarmCode, aiNeName, aiSeverity, onChangeAiAlarmCode, onChangeAiNeName, onChangeAiSeverity, onResetAiFilters, question, answer, isRunning, enabled, onChangeQuestion, onRunAnalyze, }: Props) { const [histPage, setHistPage] = useState(1); const [histPageSize, setHistPageSize] = useState(10); const [selectedHistId, setSelectedHistId] = useState(null); const historyQuery = useQuery({ queryKey: ["aiAnalyzeHistory", selectedBatch, histPage, histPageSize], queryFn: () => fetchAiAnalyzeHistory({ batchId: selectedBatch, page: histPage, pageSize: histPageSize }), enabled: Boolean(selectedBatch), staleTime: 3000, }); const historyItems: AiAnalyzeHistoryItem[] = useMemo(() => (historyQuery.data?.items || []) as AiAnalyzeHistoryItem[], [historyQuery.data]); const total = Number(historyQuery.data?.total || 0); const totalPages = Math.max(1, Math.ceil(Math.max(0, total) / Math.max(1, histPageSize))); const selectedItem = useMemo( () => historyItems.find((x) => Number(x.id) === Number(selectedHistId)), [historyItems, selectedHistId], ); return (

分析范围(前提条件)

此处筛选仅作用于 AI 分析请求中的 dataset_ref.filters,与告警列表页的过滤相互独立。

onChangeAiAlarmCode(e.target.value)} disabled={!selectedBatch} /> onChangeAiNeName(e.target.value)} disabled={!selectedBatch} />

AI 分析输入