import { apiInterceptors, collectApp, unCollectApp } from '@/client/api'; import { ChatContentContext } from '@/pages/chat'; import { ExportOutlined, LoadingOutlined, StarFilled, StarOutlined } from '@ant-design/icons'; import { Spin, Tag, Typography, message } from 'antd'; import copy from 'copy-to-clipboard'; import React, { useContext, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { useRequest } from 'ahooks'; import AppDefaultIcon from '../../common/AppDefaultIcon'; const tagColors = ['magenta', 'orange', 'geekblue', 'purple', 'cyan', 'green']; const ChatHeader: React.FC<{ isScrollToTop: boolean }> = ({ isScrollToTop }) => { const { appInfo, refreshAppInfo, handleChat, scrollRef, temperatureValue, resourceValue, currentDialogue } = useContext(ChatContentContext); const { t } = useTranslation(); const appScene = useMemo(() => { return appInfo?.team_context?.chat_scene || 'chat_agent'; }, [appInfo]); // 应用收藏状态 const isCollected = useMemo(() => { return appInfo?.is_collected === 'true'; }, [appInfo]); const { run: operate, loading } = useRequest( async () => { const [error] = await apiInterceptors( isCollected ? unCollectApp({ app_code: appInfo.app_code }) : collectApp({ app_code: appInfo.app_code }), ); if (error) { return; } return await refreshAppInfo(); }, { manual: true, }, ); const paramKey: string[] = useMemo(() => { return appInfo.param_need?.map(i => i.type) || []; }, [appInfo.param_need]); if (!Object.keys(appInfo).length) { return null; } const shareApp = async () => { const success = copy(location.href); message[success ? 'success' : 'error'](success ? t('copy_success') : t('copy_failed')); }; // 正常header const headerContent = () => { return (
{appInfo?.app_name}
{appInfo?.team_mode && {appInfo?.team_mode}} {appInfo?.team_context?.chat_scene && {appInfo?.team_context?.chat_scene}}
{appInfo?.app_describe}
{ await operate(); }} className='flex items-center justify-center w-10 h-10 bg-[#ffffff99] dark:bg-[rgba(255,255,255,0.2)] border border-white dark:border-[rgba(255,255,255,0.2)] rounded-[50%] cursor-pointer' > {loading ? ( } /> ) : ( <> {isCollected ? ( ) : ( )} )}
{!!appInfo?.recommend_questions?.length && (
或许你想问: {appInfo.recommend_questions.map((item, index) => ( { handleChat(item?.question || '', { app_code: appInfo.app_code, ...(paramKey.includes('temperature') && { temperature: temperatureValue }), ...(paramKey.includes('resource') && { select_param: typeof resourceValue === 'string' ? resourceValue : JSON.stringify(resourceValue) || currentDialogue.select_param, }), }); setTimeout(() => { scrollRef.current?.scrollTo({ top: scrollRef.current?.scrollHeight, behavior: 'smooth', }); }, 0); }} > {item.question} ))}
)}
); }; // 吸顶header const topHeaderContent = () => { return (
{appInfo?.app_name}
{appInfo?.team_mode && {appInfo?.team_mode}} {appInfo?.team_context?.chat_scene && {appInfo?.team_context?.chat_scene}}
{ await operate(); }} > {loading ? ( } /> ) : ( <> {isCollected ? ( ) : ( )} )} { e.stopPropagation(); shareApp(); }} />
); }; return (
0 ? 'mb-6' : '' } sticky top-0 bg-transparent z-30 transition-all duration-400 ease-in-out`} > {isScrollToTop ? topHeaderContent() : headerContent()}
); }; export default ChatHeader;