Showing
6 changed files
with
128 additions
and
23 deletions
@@ -10,36 +10,37 @@ | @@ -10,36 +10,37 @@ | ||
10 | "preview": "vite preview" | 10 | "preview": "vite preview" |
11 | }, | 11 | }, |
12 | "dependencies": { | 12 | "dependencies": { |
13 | + "@chatui/core": "^2.4.2", | ||
13 | "antd": "^5.22.3", | 14 | "antd": "^5.22.3", |
14 | "axios": "^1.7.3", | 15 | "axios": "^1.7.3", |
15 | "cesium": "^1.124.0", | 16 | "cesium": "^1.124.0", |
16 | "echarts": "^5.5.1", | 17 | "echarts": "^5.5.1", |
17 | "echarts-for-react": "^3.0.2", | 18 | "echarts-for-react": "^3.0.2", |
19 | + "js-cookie": "^3.0.5", | ||
18 | "lodash": "^4.17.11", | 20 | "lodash": "^4.17.11", |
21 | + "lodash-es": "^4.17.21", | ||
19 | "normalize.css": "^8.0.1", | 22 | "normalize.css": "^8.0.1", |
20 | "rc-pagination": "^4.2.0", | 23 | "rc-pagination": "^4.2.0", |
21 | - "rc-tooltip": "^6.2.0", | ||
22 | "react": "^18.3.1", | 24 | "react": "^18.3.1", |
23 | - "js-cookie": "^3.0.5", | ||
24 | "react-dom": "^18.3.1", | 25 | "react-dom": "^18.3.1", |
25 | "react-echarts": "^0.1.1", | 26 | "react-echarts": "^0.1.1", |
26 | - "react-router-dom": "^6.26.0", | ||
27 | - "swiper": "^8.4.4", | ||
28 | "react-markdown": "^9.0.1", | 27 | "react-markdown": "^9.0.1", |
29 | - "lodash-es": "^4.17.21", | ||
30 | - "rehype-raw": "^7.0.0", | ||
31 | - "remark-gfm": "^4.0.0", | 28 | + "react-router-dom": "^6.26.0", |
29 | + "react-syntax-highlighter": "^15.6.1", | ||
32 | "rehype-katex": "^7.0.1", | 30 | "rehype-katex": "^7.0.1", |
31 | + "rehype-raw": "^7.0.0", | ||
33 | "remark-breaks": "^4.0.0", | 32 | "remark-breaks": "^4.0.0", |
33 | + "remark-gfm": "^4.0.0", | ||
34 | "remark-math": "^6.0.0", | 34 | "remark-math": "^6.0.0", |
35 | - "react-syntax-highlighter": "^15.6.1" | 35 | + "swiper": "^8.4.4" |
36 | }, | 36 | }, |
37 | "devDependencies": { | 37 | "devDependencies": { |
38 | - "@types/js-cookie": "^3.0.6", | ||
39 | "@types/echarts": "^4.9.22", | 38 | "@types/echarts": "^4.9.22", |
39 | + "@types/js-cookie": "^3.0.6", | ||
40 | "@types/lodash": "^4.17.7", | 40 | "@types/lodash": "^4.17.7", |
41 | "@types/react": "^18.3.3", | 41 | "@types/react": "^18.3.3", |
42 | "@types/react-dom": "^18.3.0", | 42 | "@types/react-dom": "^18.3.0", |
43 | + "@types/react-syntax-highlighter": "^15.5.13", | ||
43 | "@typescript-eslint/eslint-plugin": "^7.15.0", | 44 | "@typescript-eslint/eslint-plugin": "^7.15.0", |
44 | "@typescript-eslint/parser": "^7.15.0", | 45 | "@typescript-eslint/parser": "^7.15.0", |
45 | "@vitejs/plugin-react": "^4.3.1", | 46 | "@vitejs/plugin-react": "^4.3.1", |
@@ -48,9 +49,8 @@ | @@ -48,9 +49,8 @@ | ||
48 | "eslint-plugin-react-refresh": "^0.4.7", | 49 | "eslint-plugin-react-refresh": "^0.4.7", |
49 | "less": "^4.2.0", | 50 | "less": "^4.2.0", |
50 | "less-loader": "^12.2.0", | 51 | "less-loader": "^12.2.0", |
52 | + "postcss-px-to-viewport": "^1.1.1", | ||
51 | "typescript": "^5.2.2", | 53 | "typescript": "^5.2.2", |
52 | - "@types/react-syntax-highlighter": "^15.5.13", | ||
53 | - "vite": "^5.3.4", | ||
54 | - "postcss-px-to-viewport": "^1.1.1" | 54 | + "vite": "^5.3.4" |
55 | } | 55 | } |
56 | } | 56 | } |
1 | import ReactDOM from 'react-dom/client' | 1 | import ReactDOM from 'react-dom/client' |
2 | import "normalize.css" | 2 | import "normalize.css" |
3 | -import 'rc-tooltip/assets/bootstrap.css'; | ||
4 | import './index.less' | 3 | import './index.less' |
4 | +import '@chatui/core/es/styles/index.less'; | ||
5 | +// 引入样式 | ||
6 | +import '@chatui/core/dist/index.css'; | ||
5 | import router from './router' | 7 | import router from './router' |
6 | 8 | ||
7 | import { | 9 | import { |
1 | import React, {useState, useEffect, useRef} from "react"; | 1 | import React, {useState, useEffect, useRef} from "react"; |
2 | -import '../../components/deepSeekIndex/base.less' | ||
3 | import './style.less' | 2 | import './style.less' |
4 | import { Button, Input } from 'antd'; | 3 | import { Button, Input } from 'antd'; |
5 | import Markdown from '@/components/deepSeekIndex/Markdown' | 4 | import Markdown from '@/components/deepSeekIndex/Markdown' |
6 | -import laBanner from "./laBanner.png"; | 5 | +import laBanner from "./laBanner.png";ch |
7 | 6 | ||
8 | -const LaTest: React.FC = () => { | 7 | +const DeepSeekIndex: React.FC = () => { |
9 | const [searchValue, setSearchValue] = useState<any>(); | 8 | const [searchValue, setSearchValue] = useState<any>(); |
10 | 9 | ||
11 | const [chatHistory, setChatHistory] = useState<any[]>([]); | 10 | const [chatHistory, setChatHistory] = useState<any[]>([]); |
@@ -89,13 +88,13 @@ const LaTest: React.FC = () => { | @@ -89,13 +88,13 @@ const LaTest: React.FC = () => { | ||
89 | }, [chatHistory]) | 88 | }, [chatHistory]) |
90 | 89 | ||
91 | return ( | 90 | return ( |
92 | - <div className={'la-test'}> | ||
93 | - <div className={'la-test_header'}> | 91 | + <div className={'deep-seek'}> |
92 | + <div className={'deep-seek_header'}> | ||
94 | <img src={laBanner} alt=""/> | 93 | <img src={laBanner} alt=""/> |
95 | </div> | 94 | </div> |
96 | <div | 95 | <div |
97 | ref={chatRef} | 96 | ref={chatRef} |
98 | - className={'la-test_content'} | 97 | + className={'deep-seek_content'} |
99 | > | 98 | > |
100 | {chatHistory?.map((msg, index) => ( | 99 | {chatHistory?.map((msg, index) => ( |
101 | <p key={index} className={`mb-2 ${msg.role === 'user' ? 'text-right' : 'text-left'}`}> | 100 | <p key={index} className={`mb-2 ${msg.role === 'user' ? 'text-right' : 'text-left'}`}> |
@@ -114,7 +113,7 @@ const LaTest: React.FC = () => { | @@ -114,7 +113,7 @@ const LaTest: React.FC = () => { | ||
114 | </p> | 113 | </p> |
115 | )} | 114 | )} |
116 | </div> | 115 | </div> |
117 | - <div className={'la-test_footer'}> | 116 | + <div className={'deep-seek_footer'}> |
118 | <Input | 117 | <Input |
119 | type="text" | 118 | type="text" |
120 | value={searchValue} | 119 | value={searchValue} |
@@ -130,4 +129,4 @@ const LaTest: React.FC = () => { | @@ -130,4 +129,4 @@ const LaTest: React.FC = () => { | ||
130 | ); | 129 | ); |
131 | }; | 130 | }; |
132 | 131 | ||
133 | -export default LaTest; | 132 | +export default DeepSeekIndex; |
src/pages/test.tsx
0 → 100644
1 | +import React from "react"; | ||
2 | +// 引入组件 | ||
3 | +import Chat, { Bubble, useMessages } from '@chatui/core'; | ||
4 | +// 默认快捷短语,可选 | ||
5 | +const defaultQuickReplies = [ | ||
6 | + { | ||
7 | + icon: 'message', | ||
8 | + name: '联系人工服务', | ||
9 | + isNew: true, | ||
10 | + isHighlight: true, | ||
11 | + }, | ||
12 | + { | ||
13 | + name: '短语1', | ||
14 | + isNew: true, | ||
15 | + }, | ||
16 | + { | ||
17 | + name: '短语2', | ||
18 | + isHighlight: true, | ||
19 | + }, | ||
20 | + { | ||
21 | + name: '短语3', | ||
22 | + }, | ||
23 | +]; | ||
24 | + | ||
25 | +const initialMessages = [ | ||
26 | + { | ||
27 | + type: 'text', | ||
28 | + content: { text: '主人好,我是智能助理,你的贴心小助手~' }, | ||
29 | + user: { avatar: '//gw.alicdn.com/tfs/TB1DYHLwMHqK1RjSZFEXXcGMXXa-56-62.svg' }, | ||
30 | + }, | ||
31 | + { | ||
32 | + type: 'image', | ||
33 | + content: { | ||
34 | + picUrl: '//img.alicdn.com/tfs/TB1p_nirYr1gK0jSZR0XXbP8XXa-300-300.png', | ||
35 | + }, | ||
36 | + }, | ||
37 | +]; | ||
38 | + | ||
39 | +const Test: React.FC = () => { | ||
40 | + // 消息列表 | ||
41 | + const { messages, appendMsg, setTyping } = useMessages(initialMessages); | ||
42 | +// 发送回调 | ||
43 | + function handleSend(type, val) { | ||
44 | + if (type === 'text' && val.trim()) { | ||
45 | + // TODO: 发送请求 | ||
46 | + appendMsg({ | ||
47 | + type: 'text', | ||
48 | + content: { text: val }, | ||
49 | + position: 'right', | ||
50 | + }); | ||
51 | + | ||
52 | + setTyping(true); | ||
53 | + | ||
54 | + // 模拟回复消息 | ||
55 | + setTimeout(() => { | ||
56 | + appendMsg({ | ||
57 | + type: 'text', | ||
58 | + content: { text: '亲,您遇到什么问题啦?请简要描述您的问题~' }, | ||
59 | + }); | ||
60 | + }, 1000); | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + // 快捷短语回调,可根据 item 数据做出不同的操作,这里以发送文本消息为例 | ||
65 | + function handleQuickReplyClick(item) { | ||
66 | + handleSend('text', item.name); | ||
67 | + } | ||
68 | + | ||
69 | + function renderMessageContent(msg) { | ||
70 | + const { type, content } = msg; | ||
71 | + | ||
72 | + // 根据消息类型来渲染 | ||
73 | + switch (type) { | ||
74 | + case 'text': | ||
75 | + return <Bubble content={content.text} />; | ||
76 | + case 'image': | ||
77 | + return ( | ||
78 | + <Bubble type="image"> | ||
79 | + <img src={content.picUrl} alt="" /> | ||
80 | + </Bubble> | ||
81 | + ); | ||
82 | + default: | ||
83 | + return null; | ||
84 | + } | ||
85 | + } | ||
86 | + return( | ||
87 | + <Chat | ||
88 | + navbar={{ title: '智能助理' }} | ||
89 | + messages={messages} | ||
90 | + renderMessageContent={renderMessageContent} | ||
91 | + quickReplies={defaultQuickReplies} | ||
92 | + onQuickReplyClick={handleQuickReplyClick} | ||
93 | + onSend={handleSend} | ||
94 | + /> | ||
95 | + ); | ||
96 | +}; | ||
97 | + | ||
98 | +export default Test; |
1 | import {createHashRouter} from 'react-router-dom'; | 1 | import {createHashRouter} from 'react-router-dom'; |
2 | import ErrorPage from "./pages/errorPage"; | 2 | import ErrorPage from "./pages/errorPage"; |
3 | -import DeepSeekIndex from "@/pages/deep-seek-index"; | 3 | +import DeepSeekIndex from "./pages/deep-seek-index"; |
4 | +import Test from "./pages/test"; | ||
4 | 5 | ||
5 | const routers = [ | 6 | const routers = [ |
6 | { | 7 | { |
@@ -13,6 +14,11 @@ const routers = [ | @@ -13,6 +14,11 @@ const routers = [ | ||
13 | element: <DeepSeekIndex />, | 14 | element: <DeepSeekIndex />, |
14 | errorElement: <ErrorPage />, | 15 | errorElement: <ErrorPage />, |
15 | }, | 16 | }, |
17 | + { | ||
18 | + path: '/test', | ||
19 | + element: <Test />, | ||
20 | + errorElement: <ErrorPage />, | ||
21 | + }, | ||
16 | ]; | 22 | ]; |
17 | 23 | ||
18 | export default createHashRouter(routers) | 24 | export default createHashRouter(routers) |