Commit 56c01b80ae8ff30d1e071f8662ef553bfc881423

Authored by 史婷婷
1 parent 744273b7

feat: 徽智制联-deepSeek-chatui引入+测试

... ... @@ -10,36 +10,37 @@
10 10 "preview": "vite preview"
11 11 },
12 12 "dependencies": {
  13 + "@chatui/core": "^2.4.2",
13 14 "antd": "^5.22.3",
14 15 "axios": "^1.7.3",
15 16 "cesium": "^1.124.0",
16 17 "echarts": "^5.5.1",
17 18 "echarts-for-react": "^3.0.2",
  19 + "js-cookie": "^3.0.5",
18 20 "lodash": "^4.17.11",
  21 + "lodash-es": "^4.17.21",
19 22 "normalize.css": "^8.0.1",
20 23 "rc-pagination": "^4.2.0",
21   - "rc-tooltip": "^6.2.0",
22 24 "react": "^18.3.1",
23   - "js-cookie": "^3.0.5",
24 25 "react-dom": "^18.3.1",
25 26 "react-echarts": "^0.1.1",
26   - "react-router-dom": "^6.26.0",
27   - "swiper": "^8.4.4",
28 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 30 "rehype-katex": "^7.0.1",
  31 + "rehype-raw": "^7.0.0",
33 32 "remark-breaks": "^4.0.0",
  33 + "remark-gfm": "^4.0.0",
34 34 "remark-math": "^6.0.0",
35   - "react-syntax-highlighter": "^15.6.1"
  35 + "swiper": "^8.4.4"
36 36 },
37 37 "devDependencies": {
38   - "@types/js-cookie": "^3.0.6",
39 38 "@types/echarts": "^4.9.22",
  39 + "@types/js-cookie": "^3.0.6",
40 40 "@types/lodash": "^4.17.7",
41 41 "@types/react": "^18.3.3",
42 42 "@types/react-dom": "^18.3.0",
  43 + "@types/react-syntax-highlighter": "^15.5.13",
43 44 "@typescript-eslint/eslint-plugin": "^7.15.0",
44 45 "@typescript-eslint/parser": "^7.15.0",
45 46 "@vitejs/plugin-react": "^4.3.1",
... ... @@ -48,9 +49,8 @@
48 49 "eslint-plugin-react-refresh": "^0.4.7",
49 50 "less": "^4.2.0",
50 51 "less-loader": "^12.2.0",
  52 + "postcss-px-to-viewport": "^1.1.1",
51 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 1 import ReactDOM from 'react-dom/client'
2 2 import "normalize.css"
3   -import 'rc-tooltip/assets/bootstrap.css';
4 3 import './index.less'
  4 +import '@chatui/core/es/styles/index.less';
  5 +// 引入样式
  6 +import '@chatui/core/dist/index.css';
5 7 import router from './router'
6 8
7 9 import {
... ...
1 1 import React, {useState, useEffect, useRef} from "react";
2   -import '../../components/deepSeekIndex/base.less'
3 2 import './style.less'
4 3 import { Button, Input } from 'antd';
5 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 8 const [searchValue, setSearchValue] = useState<any>();
10 9
11 10 const [chatHistory, setChatHistory] = useState<any[]>([]);
... ... @@ -89,13 +88,13 @@ const LaTest: React.FC = () => {
89 88 }, [chatHistory])
90 89
91 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 93 <img src={laBanner} alt=""/>
95 94 </div>
96 95 <div
97 96 ref={chatRef}
98   - className={'la-test_content'}
  97 + className={'deep-seek_content'}
99 98 >
100 99 {chatHistory?.map((msg, index) => (
101 100 <p key={index} className={`mb-2 ${msg.role === 'user' ? 'text-right' : 'text-left'}`}>
... ... @@ -114,7 +113,7 @@ const LaTest: React.FC = () => {
114 113 </p>
115 114 )}
116 115 </div>
117   - <div className={'la-test_footer'}>
  116 + <div className={'deep-seek_footer'}>
118 117 <Input
119 118 type="text"
120 119 value={searchValue}
... ... @@ -130,4 +129,4 @@ const LaTest: React.FC = () => {
130 129 );
131 130 };
132 131
133   -export default LaTest;
  132 +export default DeepSeekIndex;
... ...
1   -.la-test {
  1 +.deep-seek {
2 2 background: #f1f1f1;
3 3 height: 100%;
4 4 width: 100%;
... ...
  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 1 import {createHashRouter} from 'react-router-dom';
2 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 6 const routers = [
6 7 {
... ... @@ -13,6 +14,11 @@ const routers = [
13 14 element: <DeepSeekIndex />,
14 15 errorElement: <ErrorPage />,
15 16 },
  17 + {
  18 + path: '/test',
  19 + element: <Test />,
  20 + errorElement: <ErrorPage />,
  21 + },
16 22 ];
17 23
18 24 export default createHashRouter(routers)
\ No newline at end of file
... ...