This commit is contained in:
zhangkai
2024-06-22 18:34:39 +08:00
parent fb39b66431
commit 1c07d4b9df
72 changed files with 4283 additions and 2158 deletions

View File

@@ -18,6 +18,10 @@ import robot3 from "../../assets/robot3.png";
import duihuaItemTop from "../../assets/chat/duihua-item-top.png";
import duihuaItemJia from "../../assets/chat/duihua-item-+.png";
import duihuaItemGuan from "../../assets/chat/duihua-item-x.png";
import SkillChatSheet from "@/components/bs-comp/sheets/SkillChatSheet";
import { TitleIconBg } from "@/components/bs-comp/cardComponent";
import npcIcon from "../../assets/npc/npcIcon.png";
import nengliIcon from "../../assets/npc/nengliIcon.png";
export default function SkillChatPage() {
@@ -25,6 +29,9 @@ export default function SkillChatPage() {
const [face, setFace] = useState(true);
const { t } = useTranslation()
const [selectChat, setSelelctChat] = useState<any>({
id: '', chatId: '', type: ''
})
const { flow: initFlow } = useContext(TabsContext);
const [flow, setFlow] = useState<FlowType>(null)
@@ -39,45 +46,33 @@ export default function SkillChatPage() {
);
// 对话列表
const { chatList, chatId, chatsRef, setChatId, addChat, deleteChat } = useChatList()
const chatIdRef = useRef('')
// select flow
const handlerSelectFlow = async (node: FlowType) => {
const handlerSelectFlow = async (card) => {
// 会话ID
chatIdRef.current = generateUUID(32)
setOpen(false)
const _chatId = generateUUID(32)
// setOpen(false)
// add list
addChat({
"flow_name": node.name,
"flow_description": node.description,
"flow_id": node.id,
"chat_id": chatIdRef.current,
"flow_name": card.name,
"flow_description": card.desc,
"flow_id": card.id,
"chat_id": _chatId,
"create_time": "-",
"update_time": "-"
"update_time": "-",
"flow_type": card.flow_type
})
const flow = await getFlowApi(node.id)
setFlow(flow)
setChatId(chatIdRef.current)
setFace(false)
setSelelctChat({ id: card.id, chatId: _chatId, type: card.flow_type })
setChatId(_chatId)
}
// select chat
const handleSelectChat = useDebounce(async (chat) => {
console.log('chat.id :>> ', chat);
if (chat.chat_id === chatId) return
chatIdRef.current = chat.chat_id
const flow = initFlow?.id === chat.flow_id ? initFlow : await getFlowApi(chat.flow_id)
// if (!flow) {
// setInputState({ lock: true, errorCode: '1004' })
// clearHistory()
// return setFace(false)
// }
setFlow(flow)
setSelelctChat({ id: chat.flow_id, chatId: chat.chat_id, type: chat.flow_type })
setChatId(chat.chat_id)
setFace(false)
}, 100, false)
@@ -88,7 +83,7 @@ export default function SkillChatPage() {
desc: t('chat.confirmDeleteChat'),
onOk(next) {
deleteChat(id);
setFace(true)
setSelelctChat({ id: '', chatId: '', type: '' })
next()
}
})
@@ -96,9 +91,16 @@ export default function SkillChatPage() {
return <div className="flex">
<div className="h-screen w-[288px] border-r xinDuiHua-box relative">
<div className="h-screen w-[288px] relative">
<div className="xinDuiHua absolute">
<div className="xinDuiHua-btn cursor-pointer" onClick={() => setOpen(true)}>{t('chat.newChat')}</div>
<SkillChatSheet onSelect={handlerSelectFlow}>
<div id="newchat" className="xinDuiHua-btn cursor-pointer">
{/* <PlusBoxIcon className="dark:hidden"></PlusBoxIcon> */}
{/* <PlusBoxIconDark className="hidden dark:block"></PlusBoxIconDark> */}
{t('chat.newChat')}
</div>
</SkillChatSheet>
{/* <div className="xinDuiHua-btn cursor-pointer" onClick={() => setOpen(true)}>{t('chat.newChat')}</div> */}
{/* <div className="xinDuiHua-del cursor-pointer">
<img src={duihuaDel} alt=""/>
</div> */}
@@ -110,9 +112,10 @@ export default function SkillChatPage() {
className={` group item xinDuiHua-list-item relative hover:xinDuiHua-list-active cursor-pointer dark:hover:xinDuiHua-list-active ${chatId === chat.chat_id && 'xinDuiHua-list-active dark:xinDuiHua-list-active'}`}
onClick={() => handleSelectChat(chat)}>
<div>
{(chat.flow_id == "06b1d374-ba97-46e6-8782-c56dec8dcc17" || chat.flow_id == "ed8e21f6-9757-43d0-b076-8c6e81bb0580") && <img src={robot2} alt=""/>}
{/* {(chat.flow_id == "06b1d374-ba97-46e6-8782-c56dec8dcc17" || chat.flow_id == "ed8e21f6-9757-43d0-b076-8c6e81bb0580") && <img src={robot2} alt=""/>}
{chat.flow_id == "ca214b41-2b73-4585-b172-bf1e546cf6ec" && <img src={robot3} alt=""/>}
{(chat.flow_id != "06b1d374-ba97-46e6-8782-c56dec8dcc17" && chat.flow_id != "ed8e21f6-9757-43d0-b076-8c6e81bb0580" && chat.flow_id != "ca214b41-2b73-4585-b172-bf1e546cf6ec") && <img src={robot} alt=""/>}
{(chat.flow_id != "06b1d374-ba97-46e6-8782-c56dec8dcc17" && chat.flow_id != "ed8e21f6-9757-43d0-b076-8c6e81bb0580" && chat.flow_id != "ca214b41-2b73-4585-b172-bf1e546cf6ec") && <img src={robot} alt=""/>} */}
<TitleIconBg className="w-[40px] h-[40px]" img={chat.avatar_img} id={chat.avatar_color ? chat.avatar_color : chat.flow_id} ><img src={chat.avatar_img ? chat.avatar_img : (chat.flow_type == "assistant" ? npcIcon : nengliIcon)} alt="" /></TitleIconBg>
{/* <img src={robot} alt=""/> */}
<div>
<p>{chat.flow_name}</p>
@@ -132,13 +135,7 @@ export default function SkillChatPage() {
</div>
</div>
{/* chat */}
{face
? <div className="flex-1 chat-box h-screen overflow-hidden relative">
<p className="text-center mt-[100px] text-sm text-gray-600">{t('chat.selectChat')}</p>
</div>
: <div className="flex-1 chat-box h-screen relative">
{flow && <ChatPanne chatId={chatId} flow={flow} />}
</div>}
<ChatPanne data={selectChat}></ChatPanne>
{/* 选择对话技能 */}
<SkillTemps
flows={onlineFlows}