import { ChatContext } from '@/app/chat-context'; import { apiInterceptors, getAppList, newDialogue, recommendApps } from '@/client/api'; import { getRecommendQuestions } from '@/client/api/chat'; import TabContent from '@/new-components/app/TabContent'; import ChatInput from '@/new-components/chat/input/ChatInput'; import { STORAGE_INIT_MESSAGE_KET } from '@/utils'; import { useRequest } from 'ahooks'; import { ConfigProvider, Segmented, SegmentedProps } from 'antd'; import { t } from 'i18next'; import Image from 'next/image'; import { useRouter } from 'next/router'; import { useContext, useEffect, useState } from 'react'; function ChatDefault() { const { setCurrentDialogInfo, model } = useContext(ChatContext); const router = useRouter(); const [apps, setApps] = useState({ app_list: [], total_count: 0, }); const [activeKey, setActiveKey] = useState('recommend'); const getAppListWithParams = (params: Record) => apiInterceptors( getAppList({ ...params, page_no: '1', page_size: '6', }), ); const getHotAppList = (params: Record) => apiInterceptors( recommendApps({ page_no: '1', page_size: '6', ...params, }), ); // 获取应用列表 const { run: getAppListFn, loading, refresh, } = useRequest( async (app_name?: string) => { switch (activeKey) { case 'recommend': return await getHotAppList({}); case 'used': return await getAppListWithParams({ is_recent_used: 'true', need_owner_info: 'true', ...(app_name && { app_name }), }); default: return []; } }, { manual: true, onSuccess: res => { const [_error, data] = res; if (activeKey === 'recommend') { return setApps({ app_list: data, total_count: data?.length || 0, }); } setApps(data || {}); }, debounceWait: 500, }, ); useEffect(() => { getAppListFn(); }, [activeKey, getAppListFn]); const items: SegmentedProps['options'] = [ { value: 'recommend', label: t('recommend_apps'), }, { value: 'used', label: t('used_apps'), }, ]; // 获取推荐问题 const { data: helps } = useRequest(async () => { const [, res] = await apiInterceptors(getRecommendQuestions({ is_hot_question: 'true' })); return res ?? []; }); return (
{ setActiveKey(value as string); }} /> {t('app_in_mind')} { router.push('/'); }} > construct_image {t('explore')} {t('Discover_more')}
{helps && helps.length > 0 && (

{t('help')}

{helps.map(help => ( { const [, res] = await apiInterceptors(newDialogue({ chat_mode: 'chat_knowledge', model })); if (res) { setCurrentDialogInfo?.({ chat_scene: res.chat_mode, app_code: help.app_code, }); localStorage.setItem( 'cur_dialog_info', JSON.stringify({ chat_scene: res.chat_mode, app_code: help.app_code, }), ); localStorage.setItem( STORAGE_INIT_MESSAGE_KET, JSON.stringify({ id: res.conv_uid, message: help.question }), ); router.push(`/chat/?scene=${res.chat_mode}&id=${res?.conv_uid}`); } }} > {help.question} construct_image ))}
)}
); } export default ChatDefault;