李富豪 11 månader sedan
förälder
incheckning
5fb037aee4
2 ändrade filer med 72 tillägg och 44 borttagningar
  1. 72 44
      app/components/chat.tsx
  2. BIN
      app/icons/avatar.png

+ 72 - 44
app/components/chat.tsx

@@ -43,6 +43,7 @@ import RobotIcon from "../icons/robot.svg";
 import AddIcon from "../icons/add.svg";
 import SizeIcon from "../icons/size.svg";
 import PluginIcon from "../icons/plugin.svg";
+import avatarSrc from "../icons/avatar.png";
 
 import {
   ChatMessage,
@@ -90,7 +91,7 @@ import {
   showPrompt,
   showToast,
 } from "./ui-lib";
-import { useNavigate } from "react-router-dom";
+import { useNavigate, useLocation } from "react-router-dom";
 import {
   CHAT_PAGE_SIZE,
   LAST_INPUT_KEY,
@@ -108,7 +109,7 @@ import { prettyObject } from "../utils/format";
 import { ExportMessageModal } from "./exporter";
 import { getClientConfig } from "../config/client";
 import { useAllModels } from "../utils/hooks";
-import { Select } from 'antd';
+import { Button, message, Popover, Select } from 'antd';
 import { RightOutlined } from '@ant-design/icons';
 import api from "@/app/api/api";
 
@@ -912,10 +913,7 @@ function _Chat() {
   const globalStore = useGlobalStore();
   type QuestionList = any[];
   const [questionList, setQuestionList] = useState<QuestionList>([]);
-
-  useEffect(() => {
-    console.log(questionList, 'questionList');
-  }, [questionList]);
+  const location = useLocation();
 
   // 获取应用列表
   const fetchApplicationList = async () => {
@@ -929,11 +927,23 @@ function _Chat() {
         }
       })
       setAppList(list);
-      let newAppValue = '';
-      setAppValue(list[0]?.value);
-      newAppValue = list[0]?.value;
-      globalStore.setSelectedAppId(newAppValue);
-      chatStore.updateCurrentSession((session) => (session.appId = newAppValue));
+      let appValue = '';
+      const search = location.search;
+      if (search.startsWith('?appId=')) {
+        const value = search.slice(7);
+        if (list.find((item: any) => item.value === value)) {
+          appValue = value;
+        } else {
+          appValue = list[0]?.value;
+        }
+      } else {
+        appValue = list[0]?.value;
+      }
+      setAppValue(appValue);
+      globalStore.setSelectedAppId(appValue);
+      chatStore.updateCurrentSession((session) => {
+        session.appId = appValue;
+      });
     } catch (error) {
       console.error(error);
     } finally {
@@ -1534,15 +1544,30 @@ function _Chat() {
             </div>
           )} */}
           <div className="window-action-button">
-            <IconButton
-              icon={<ExportIcon />}
-              bordered
-              title={Locale.Chat.Actions.Export}
-              onClick={() => {
-                // setShowExport(true);
-                console.log('分享聊天记录');
-              }}
-            />
+            <Popover
+              trigger="click"
+              title="分享"
+              content={() => {
+                const url = `${window.location.origin}/#/chat?appId=${appValue}`
+                return <div>
+                  <div style={{ marginBottom: 10 }}>
+                    {url}
+                  </div>
+                  <Button onClick={() => {
+                    navigator.clipboard.writeText(url);
+                    message.success('分享链接已复制到剪贴板');
+                  }}>
+                    复制
+                  </Button>
+                </div>
+              }
+              }>
+              <IconButton
+                icon={<ExportIcon />}
+                bordered
+                title={Locale.Chat.Actions.Export}
+              />
+            </Popover>
           </div>
           {/* {showMaxIcon && (
             <div className="window-action-button">
@@ -1791,35 +1816,39 @@ function _Chat() {
             </>
             :
             <>
-              <div style={{ position: 'absolute', width: '800px', height: '550px', top: '0', left: '0', right: '0', bottom: '0', margin: 'auto' }}>
-                <h1 style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
+              <div style={{ padding: '0 20px' }}>
+                <div style={{ display: 'flex', justifyContent: 'center' }}>
+                  <img style={{ width: 80, height: 80 }} src={avatarSrc.src} />
+                </div>
+                <h1 style={{ textAlign: 'center' }}>
                   {getAppName()}
                 </h1>
-                <p style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>创建人: admin</p>
-                <p style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
-                  您好,欢迎使用建科·小智使用知识库创建的
-                  <span>
-                    {getAppName()}
-                  </span>
+                <p style={{ textAlign: 'center' }}>创建人: admin</p>
+                <p style={{ textAlign: 'center' }}>
+                  您好,欢迎使用建科·小智使用知识库创建的{getAppName()}
                 </p>
-                <p style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>如果需要问本企业相关的其他问题请点击左上角,选中切换的知识库问答应用使用</p>
+                <p style={{ textAlign: 'center' }}>如果需要问本企业相关的其他问题请点击左上角,选中切换的知识库问答应用使用</p>
                 <p>我猜您可能想问:</p>
                 {
-                  questionList.map((item) => {
+                  questionList.map((item, index) => {
                     return (
-                      <div style={{
-                        padding: '10px',
-                        marginBottom: '10px',
-                        border: '1px solid #e6e8f1',
-                        borderRadius: '10px',
-                        fontSize: '16px',
-                        display: 'flex',
-                        justifyContent: 'space-between',
-                        alignItems: 'center',
-                        cursor: 'pointer'
-                      }} onClick={() => {
-                        setUserInput(item)
-                      }}>
+                      <div
+                        style={{
+                          padding: '10px',
+                          marginBottom: '10px',
+                          border: '1px solid #e6e8f1',
+                          borderRadius: '10px',
+                          fontSize: '16px',
+                          display: 'flex',
+                          justifyContent: 'space-between',
+                          alignItems: 'center',
+                          cursor: 'pointer'
+                        }}
+                        onClick={() => {
+                          setUserInput(item)
+                        }}
+                        key={index}
+                      >
                         <div>
                           {item}
                         </div>
@@ -1835,7 +1864,6 @@ function _Chat() {
 
       <div className={styles["chat-input-panel"]}>
         {/* <PromptHints prompts={promptHints} onPromptSelect={onPromptSelect} /> */}
-
         <ChatActions
           setUserInput={setUserInput}
           doSubmit={doSubmit}

BIN
app/icons/avatar.png