import React, { useMemo, useState } from 'react'; import { AddIcon, ChatIcon } from '@chakra-ui/icons'; import { Box, Button, Flex, Divider, useDisclosure, useColorMode, useColorModeValue } from '@chakra-ui/react'; import { useUserStore } from '@/store/user'; import { useQuery } from '@tanstack/react-query'; import { useRouter } from 'next/router'; import MyIcon from '@/components/Icon'; import WxConcat from '@/components/WxConcat'; import { delChatHistoryById } from '@/api/chat'; import { useChatStore } from '@/store/chat'; import Avatar from '@/components/Avatar'; import Tabs from '@/components/Tabs'; enum TabEnum { app = 'app', history = 'history' } const PhoneSliderBar = ({ chatId, modelId, onClose }: { chatId: string; modelId: string; onClose: () => void; }) => { const router = useRouter(); const [currentTab, setCurrentTab] = useState(TabEnum.app); const { myModels, myCollectionModels, loadMyModels } = useUserStore(); const { isOpen: isOpenWx, onOpen: onOpenWx, onClose: onCloseWx } = useDisclosure(); const models = useMemo( () => [...myModels, ...myCollectionModels], [myCollectionModels, myModels] ); useQuery(['loadModels'], () => loadMyModels(false)); const { history, loadHistory } = useChatStore(); useQuery(['loadingHistory'], () => loadHistory({ pageNum: 1 })); const RenderButton = ({ onClick, children }: { onClick: () => void; children: JSX.Element | string; }) => ( {children} ); return ( setCurrentTab(e)} /> {/* 新对话 */} {currentTab === TabEnum.app && ( )} {/* 我的模型 & 历史记录 折叠框*/} {currentTab === TabEnum.app && ( <> {models.map((item) => ( { if (item._id === modelId) return; router.replace(`/chat?modelId=${item._id}`); onClose(); }} > {item.name} ))} )} {currentTab === TabEnum.history && ( <> {history.map((item) => ( { if (item._id === chatId) return; router.replace(`/chat?modelId=${item.modelId}&chatId=${item._id}`); onClose(); }} > {item.title} { e.stopPropagation(); console.log(111); await delChatHistoryById(item._id); loadHistory({ pageNum: 1, init: true }); if (item._id === chatId) { router.replace(`/chat?modelId=${modelId}`); } }} /> ))} )} router.push('/model')}> <> 退出聊天 <> 交流群 {/* wx 联系 */} {isOpenWx && } ); }; export default PhoneSliderBar;