import React, { useEffect, useRef, useState } from "react"; import { RotateCw } from "lucide-react"; import Markdown from "react-markdown"; import { Button } from "@/components/ui/button"; import { TaijiIcon } from "@/components/svg/taiji"; import { cn } from "@/lib/utils"; function ResultAI({ completion, isLoading, onCompletion, error, panel = false, emptyHint = "完成左侧填写并起卦/排盘后,点击「AI 解读」", }: { completion: string; isLoading: boolean; onCompletion: () => void; error: string; panel?: boolean; emptyHint?: string; }) { const scrollRef = useRef(null); const [autoScroll, setAutoScroll] = useState(false); useEffect(() => { setAutoScroll(isLoading); }, [isLoading]); useEffect(() => { if (!autoScroll) { return; } scrollRef.current?.scrollTo(0, scrollRef.current.scrollHeight); }, [completion, autoScroll]); function onScroll(e: HTMLElement) { if (!isLoading) { return; } const hitBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 15; if (hitBottom !== autoScroll) { setAutoScroll(hitBottom); } } return (
{isLoading && !panel && (
AI 分析中...
)}
onScroll(e.currentTarget)} className={cn( "overflow-y-auto", panel ? "min-h-0 flex-1" : "min-h-[240px] max-h-[420px] rounded-md border bg-background p-3 shadow sm:p-5 dark:border-0 dark:bg-secondary/90", )} > {isLoading && panel && (
AI 分析中...
)} {error ? (

请求出错了

{error}

) : completion ? ( {completion} ) : isLoading ? (

正在等待 AI 响应...

) : (

{emptyHint}

)} {!isLoading && (completion || error) && ( )}
); } export default ResultAI;