import { useEffect, useState } from 'react'; import LeftAvatar from '../CopilotAvatar'; import Message from '../Message'; import styles from './style.module.less'; import { queryRecommendQuestions } from '../../service'; import { isMobile } from '../../../utils/utils'; type Props = { onSelectQuestion: (value: string) => void; }; const RecommendQuestions: React.FC = ({ onSelectQuestion }) => { const [questions, setQuestions] = useState([]); const [loading, setLoading] = useState(false); const initData = async () => { setLoading(true); const res = await queryRecommendQuestions(); setLoading(false); setQuestions( res.data?.reduce((result: any[], item: any) => { result = [ ...result, ...item.recommendedQuestions.slice(0, 20).map((item: any) => item.question), ]; return result; }, []) || [] ); }; useEffect(() => { initData(); }, []); return (
{!isMobile && } {loading ? ( <> ) : questions.length > 0 ? (
推荐问题:
{questions.map((question, index) => (
{ onSelectQuestion(question); }} > {question}
))}
) : ( 您好,请问有什么我可以帮您吗? )}
); }; export default RecommendQuestions;