瀏覽代碼

修复分享问题

李富豪 6 月之前
父節點
當前提交
86daef13af
共有 1 個文件被更改,包括 53 次插入40 次删除
  1. 53 40
      app/components/chat.tsx

+ 53 - 40
app/components/chat.tsx

@@ -1017,11 +1017,12 @@ function _Chat() {
   const [selectedFruit, setSelectedFruit] = React.useState(chatStore.chatMode);
 
   // 获取应用列表
-  const fetchApplicationList = async () => {
+  const fetchApplicationList = async (chatMode?: string) => {
+    let mode = chatMode || selectedFruit;
     setLoading(true);
     try {
       let url = null;
-      if (selectedFruit === 'LOCAL') {
+      if (mode === 'LOCAL') {
         url = '/deepseek/api/application/list';
       } else {
         url = '/bigmodel/api/application/list';
@@ -1035,25 +1036,14 @@ function _Chat() {
         }
       })
       setAppList(list);
-      let appValue = '';
       const search = location.search;
       const params = new URLSearchParams(search);
-      const appId = params.get('appId');
+      const appId = params.get('appId') || '';
       if (appId) {
-        const value = appId;
-        if (list.find((item: any) => item.value === value)) {
-          appValue = value;
-        } else {
-          appValue = list[0]?.value;
-        }
+        setAppValue(appId);
       } else {
-        appValue = list[0]?.value;
+        setAppValue(list[0]?.value);
       }
-      setAppValue(appValue);
-      globalStore.setSelectedAppId(appValue);
-      chatStore.updateCurrentSession((session) => {
-        session.appId = appValue;
-      });
     } catch (error) {
       console.error(error);
     } finally {
@@ -1079,10 +1069,19 @@ function _Chat() {
     }
   }
 
-  const init = async () => {
-    await fetchApplicationList();
+  const init = async (chatMode?: string) => {
+    await fetchApplicationList(chatMode);
   }
 
+  useEffect(() => {
+    const search = location.search;
+    const params = new URLSearchParams(search);
+    const chatMode = params.get('chatMode');
+    if (!chatMode) {
+      init();
+    }
+  }, [selectedFruit])
+
   useEffect(() => {
     const search = location.search;
     const params = new URLSearchParams(search);
@@ -1090,6 +1089,15 @@ function _Chat() {
 
     if (chatMode) {
       setSelectedFruit(chatMode as "ONLINE" | "LOCAL");
+      const appId = params.get('appId');
+      if (appId) {
+        setAppValue(appId);
+        globalStore.setSelectedAppId(appId);
+        chatStore.updateCurrentSession((session) => {
+          session.appId = appId;
+        });
+      }
+      init(chatMode);
     }
   }, [])
 
@@ -1099,20 +1107,6 @@ function _Chat() {
     }
   }, [appValue, chatStore.chatMode])
 
-  useEffect(() => {
-    init();
-    const search = location.search;
-    const params = new URLSearchParams(search);
-    const appId = params.get('appId');
-    if (appId) {
-      setAppValue(appId);
-      globalStore.setSelectedAppId(appId);
-      chatStore.updateCurrentSession((session) => {
-        session.appId = appId;
-      });
-    }
-  }, [chatStore.chatMode])
-
   const [inputRows, setInputRows] = useState(2);
   const measure = useDebouncedCallback(
     () => {
@@ -1607,15 +1601,37 @@ function _Chat() {
   }
 
   const getAppName = () => {
-    const item = appList.find(item => item.value === appValue);
+    const search = location.search;
+    const params = new URLSearchParams(search);
+    const chatMode = params.get('chatMode');
+    let appId = '';
+    if (chatMode) {
+      appId = globalStore.selectedAppId;
+    } else {
+      appId = appValue as string;
+    }
+    const item = appList.find(item => item.value === appId);
     if (!item) {
-      return
+      return '';
     }
     return item.label;
   }
 
-  const getDesc = (value: string) => {
-    return appList.find(item => item.value === value)?.desc;
+  const getDesc = () => {
+    const search = location.search;
+    const params = new URLSearchParams(search);
+    const chatMode = params.get('chatMode');
+    let appId = '';
+    if (chatMode) {
+      appId = globalStore.selectedAppId;
+    } else {
+      appId = appValue as string;
+    }
+    const item = appList.find(item => item.value === appId);
+    if (!item) {
+      return '';
+    }
+    return item.desc;
   }
 
   const couldStop = ChatControllerPool.hasPending();
@@ -2116,11 +2132,8 @@ function _Chat() {
                 <h1 style={{ textAlign: 'center' }}>
                   {getAppName()}
                 </h1>
-                {/* <p style={{ textAlign: 'center' }}>
-                  您好,欢迎使用建科·小智使用知识库创建的{getAppName()}
-                </p> */}
                 <p style={{ textAlign: 'center' }}>
-                  {appValue ? getDesc(appValue) : ''}
+                  {getDesc()}
                 </p>
                 <p>我猜您可能想问:</p>
                 {