diff --git a/src/components/Common/Playground/Data.tsx b/src/components/Common/Playground/Data.tsx index 89269fb..7dae897 100644 --- a/src/components/Common/Playground/Data.tsx +++ b/src/components/Common/Playground/Data.tsx @@ -11,8 +11,7 @@ const defaultData: IodRegistryEntry[] = [ { name: "固态电池固体电解质材料数据集", doId: "CSTR:16666.11.nbsdc.9bjqrscd", - description: - "国家基础学科公共科学数据中心" + description: "国家基础学科公共科学数据中心" }, { name: "固体颗粒物与流体耦合", @@ -98,31 +97,22 @@ type Props = { className?: string } export const PlaygroundData: React.FC = ({ className }) => { - const { messages, iodLoading, currentMessageId, iodSearch } = - useMessageOption() + const { iodLoading } = useMessageOption() - const { setShowPlayground, setDetailHeader, setDetailMain } = - useIodPlaygroundContext() + const { + setShowPlayground, + setDetailHeader, + setDetailMain, + currentIodMessage + } = useIodPlaygroundContext() const data = useMemo(() => { - // 确保loading状态时数据大于3 - if (iodLoading) { - return defaultData - } - - if (messages.length && iodSearch) { - const currentMessage = messages?.find( - (message) => message.id === currentMessageId - ) - return currentMessage?.iodSources.data.data ?? [] - } - - return defaultData - }, [currentMessageId, messages, iodLoading, iodSearch]) + return currentIodMessage ? currentIodMessage.data?.data ?? [] : defaultData + }, [currentIodMessage]) const title = useMemo(() => { - return messages.length > 0 ? "推荐数据" : "热点数据" - }, [messages]) + return currentIodMessage ? "推荐数据" : "热点数据" + }, [currentIodMessage]) const showMore = () => { setShowPlayground(false) @@ -133,7 +123,7 @@ export const PlaygroundData: React.FC = ({ className }) => { onClick={() => setShowPlayground(false)} /> ) - setDetailMain(
) + setDetailMain(
) } return ( @@ -142,7 +132,7 @@ export const PlaygroundData: React.FC = ({ className }) => { {/* 数据导航 */}
{/* 数据列表 */} -
+
) diff --git a/src/components/Common/Playground/IodRelevant.tsx b/src/components/Common/Playground/IodRelevant.tsx index 5b979b6..ca1e4f4 100644 --- a/src/components/Common/Playground/IodRelevant.tsx +++ b/src/components/Common/Playground/IodRelevant.tsx @@ -10,6 +10,7 @@ import { DatasetIcon } from "@/components/Icons/Dataset.tsx" import { TechCompanyIcon } from "@/components/Icons/TechCompany.tsx" import { ResearchInstitutesIcon } from "@/components/Icons/ResearchInstitutes.tsx" import { NSDCIcon } from "@/components/Icons/NSDC.tsx" +import { useIodPlaygroundContext } from "@/components/Option/Playground/PlaygroundIod.tsx" const rotate = keyframes` 0% { @@ -32,8 +33,8 @@ const breathe = keyframes` } ` -// 花瓣 -const CircleElement = styled.div<{ delay: number; playing: boolean }>` +// 花瓣 /* ${(props) => (props.playing ? "running" : "paused")}; */ +const CircleElement = styled.div<{ delay: number }>` position: absolute; width: 300px; height: 160px; @@ -46,7 +47,7 @@ const CircleElement = styled.div<{ delay: number; playing: boolean }>` ${rotate} 6s linear infinite, ${breathe} 2s infinite alternate; animation-delay: ${(props) => props.delay}s; - animation-play-state: ${(props) => (props.playing ? "running" : "paused")}; + animation-play-state: running; animation-duration: 3s; /* 添加动画总持续时间 */ animation-fill-mode: forwards; /* 保持动画结束时的状态 */ ` @@ -221,24 +222,19 @@ type Props = { className?: string } export const PlaygroundIodRelevant: React.FC = ({ className }) => { - const { messages, iodLoading, currentMessageId, iodSearch } = - useMessageOption() + const { iodLoading, iodSearch } = useMessageOption() + + const { currentIodMessage } = useIodPlaygroundContext() const showSearchData = useMemo(() => { - return iodSearch && messages.length > 0 && !iodLoading - }, [iodSearch, messages, iodLoading]) - - + return currentIodMessage && !iodLoading + }, [currentIodMessage, iodLoading]) const data = useMemo(() => { - const currentMessage = messages?.find( - (message) => message.id === currentMessageId - ) - - const loading = (iodSearch && iodLoading) - const text = loading ? '正' : '已' - const text2 = loading ? '进行' : '完成' - const text3 = loading ? '……' : '' + const loading = iodSearch && iodLoading + const text = loading ? "正" : "已" + const text2 = loading ? "进行" : "完成" + const text3 = loading ? "……" : "" const duration = loading ? 2.5 : 0 return [ @@ -256,7 +252,12 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => { 高等院校的 - + 万个 科学数据集中{text2}搜索{text3} @@ -268,7 +269,7 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => { {" "} @@ -288,9 +289,14 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => { 万篇 - 学术论文、 + 数据论文、 - + 万个 数据项目中{text2}搜索{text3} @@ -302,7 +308,7 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => { {" "} @@ -324,7 +330,13 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => { 高等院校和科研机构、 {" "} - 万 + + 万 家科技型企业、 @@ -340,7 +352,7 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => { {" "} @@ -353,7 +365,7 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => { ) } ] - }, [messages, iodLoading]) + }, [showSearchData, iodLoading]) return ( = ({ className }) => {
- - - + + +
@@ -376,16 +388,14 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => {

- {messages.length > 0 - ? "科创数联网深度搜索" - : "科创数联网连接资源"} + {currentIodMessage ? "科创数联网深度搜索" : "科创数联网连接资源"}
{/**/}

- {messages.length > 0 + {currentIodMessage ? "下面是在科创数联网上进行深度搜索得到的相关数据、场景和团队" : "下面是科创数联网连接的数据、场景和团队"}

@@ -393,7 +403,7 @@ export const PlaygroundIodRelevant: React.FC = ({ className }) => { {/* Content */}
- {messages.length ? ( + {currentIodMessage ? ( = ({ className }) => { /> )}
-

{item.title} -

+ {item.description && (
-

+

{item.description} -

+
)} diff --git a/src/components/Common/Playground/Message.tsx b/src/components/Common/Playground/Message.tsx index b857ecb..a2655a7 100644 --- a/src/components/Common/Playground/Message.tsx +++ b/src/components/Common/Playground/Message.tsx @@ -25,8 +25,10 @@ import { GenerationInfo } from "./GenerationInfo" import { parseReasoning } from "@/libs/reasoning" import { humanizeMilliseconds } from "@/utils/humanize-milliseconds" import { AllIodRegistryEntry } from "@/types/iod.ts" +import { PiNetwork } from "react-icons/pi" type Props = { + id?: string message: string message_type?: string hideCopy?: boolean @@ -50,9 +52,11 @@ type Props = { generationInfo?: any isStreaming: boolean reasoningTimeTaken?: number + iodSearch?: boolean + setCurrentMessageId: (id: string) => void } -export const PlaygroundMessage = (props: Props) => { +export const PlaygroundMessage: React.FC = (props) => { const [isBtnPressed, setIsBtnPressed] = React.useState(false) const [editMode, setEditMode] = React.useState(false) @@ -258,6 +262,18 @@ export const PlaygroundMessage = (props: Props) => { )} {props.isBot && ( <> + {/*数联网搜索*/} + {props.iodSearch && ( + + + + )} + {!props.hideCopy && ( )} @@ -420,12 +420,12 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { }} className={`flex items-center justify-center dark:text-gray-300 !px-[5px]`}> {!isListening ? ( - + ) : (
diff --git a/src/components/Option/Playground/PlaygroundIod.tsx b/src/components/Option/Playground/PlaygroundIod.tsx index e6ab985..c16773c 100644 --- a/src/components/Option/Playground/PlaygroundIod.tsx +++ b/src/components/Option/Playground/PlaygroundIod.tsx @@ -9,7 +9,7 @@ import { PlaygroundTeam } from "@/components/Common/Playground/Team.tsx" import { Card } from "antd" import { CloseOutlined } from "@ant-design/icons" import { useMessageOption } from "@/hooks/useMessageOption.tsx" -import { Message } from "@/types/message.ts" +import { AllIodRegistryEntry } from "@/types/iod.ts" // 定义 Context 类型 interface IodPlaygroundContextType { @@ -19,7 +19,7 @@ interface IodPlaygroundContextType { setDetailHeader: React.Dispatch> detailMain: React.ReactNode setDetailMain: React.Dispatch> - currentIodMessage: Message | null + currentIodMessage?: AllIodRegistryEntry } // 创建 Context @@ -41,36 +41,34 @@ export const useIodPlaygroundContext = () => { const PlaygroundIodProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { - const { messages, iodLoading, currentMessageId, iodSearch } = - useMessageOption() + const { messages, iodLoading, currentMessageId } = useMessageOption() const [showPlayground, setShowPlayground] = useState(true) const [detailHeader, setDetailHeader] = useState(<>) const [detailMain, setDetailMain] = useState(<>) - const currentIodMessage = useMemo(() => { - if (iodLoading) { - return null + const currentIodMessage = useMemo(() => { + console.log('messages', messages) + console.log("currentMessageId", currentMessageId) + console.log("iodLoading", iodLoading) + // loading 返回 undefined是为了避免,数据不足三个的情况 + if (iodLoading || !messages.length) { + return undefined } - if (messages.length && iodSearch) { - // 如果不存在currentMessageId默认返回最后一个message - if (!currentMessageId) { - return messages.at(-1) - } - - const currentMessage = messages?.find( - (message) => message.id === currentMessageId - ) - if (currentMessage) { - return currentMessage - } - // 如果当前message不存在最后一个message - return messages.at(-1) + // 如果不存在currentMessageId默认返回最后一个message + if (!currentMessageId) { + const lastMessage = messages.at(-1) + // 如果最后一次message没有开启数联网搜索,则返回undefined + return lastMessage?.iodSearch ? lastMessage.iodSources : undefined } - return null - }, [currentMessageId, messages, iodLoading, iodSearch]) + const currentMessage = messages?.find( + (message) => message.id === currentMessageId + ) + console.log("currentMessage", currentMessage) + return currentMessage?.iodSearch ? currentMessage.iodSources : undefined + }, [currentMessageId, messages, iodLoading]) return ( { ) } - export const PlaygroundIod = () => { return (
diff --git a/src/components/Option/Playground/PlaygroundNewChat.tsx b/src/components/Option/Playground/PlaygroundNewChat.tsx deleted file mode 100644 index d9816af..0000000 --- a/src/components/Option/Playground/PlaygroundNewChat.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { PencilIcon } from "lucide-react" -import { useMessage } from "../../../hooks/useMessage" -import { useTranslation } from 'react-i18next'; - -export const PlaygroundNewChat = () => { - const { setHistory, setMessages, setHistoryId } = useMessage() - const { t } = useTranslation('optionChat') - - const handleClick = () => { - setHistoryId(null) - setMessages([]) - setHistory([]) - } - - return ( - - ) -} diff --git a/src/components/Option/Settings/iod.tsx b/src/components/Option/Settings/iod.tsx index 70cf770..fb44d2e 100644 --- a/src/components/Option/Settings/iod.tsx +++ b/src/components/Option/Settings/iod.tsx @@ -1,41 +1,20 @@ import { useTranslation } from "react-i18next" import TextArea from "antd/es/input/TextArea" -import { useEffect, useState } from "react" +import { IodDb } from "@/db/iod.ts" +import { useState } from "react" export const IodApp = () => { const { t } = useTranslation("settings") + const db = IodDb.getInstance() - const [connectVal, setConnectVal] = useState('') + const [connection, setConnection] = useState(JSON.stringify(db.getIodConnection(), null, 2)) const setConnectValWrap = (val: string) => { - localStorage.setItem("iod-connect", val) - setConnectVal(val) + db.insertIodConnection(JSON.parse(val)) + setConnection(val) } - useEffect(() => { - const val = localStorage.getItem("iod-connect") - const defaultVal = { - gatewayUrl: "tcp://reg01.public.internetofdata.cn:21037", - registry: "data/Registry", - localRepository: "data/Repository", - doBrowser: "http://021.node.internetapi.cn:21030/SCIDE/SCManager" - } - if (!val) { - localStorage.setItem( - "iod-connect", - JSON.stringify(defaultVal) - ) - setConnectVal(JSON.stringify(defaultVal, null, 2)) - return - } - try { - const val = localStorage.getItem("iod-connect") - setConnectVal(JSON.stringify(JSON.parse(val), null, 2)) - } catch (e) { - setConnectVal(JSON.stringify(defaultVal, null, 2)) - } - }, []) return (
@@ -47,7 +26,7 @@ export const IodApp = () => {
连接配置 -