DeekSeekHome.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import * as React from 'react';
  2. import { useNavigate } from "react-router-dom";
  3. import { Dropdown, Spin, Input, Button, Space, UploadProps } from 'antd';
  4. import { Chat } from './DeepSeekChat';
  5. import whiteLogo from "../icons/whiteLogo.png";
  6. import jkxz from "../icons/jkxz.png";
  7. import { useChatStore, useGlobalStore } from "../store";
  8. import { useMobileScreen } from '../utils';
  9. import api from "@/app/api/api";
  10. import './deepSeekHome.scss';
  11. import { message, Upload } from 'antd';
  12. import { InboxOutlined } from '@ant-design/icons';
  13. const { Dragger } = Upload;
  14. const DeekSeek: React.FC = () => {
  15. const chatStore = useChatStore();
  16. const globalStore = useGlobalStore();
  17. useGlobalStore((state) => state.setIsChatActive);
  18. const isMobileScreen = useMobileScreen();
  19. const navigate = useNavigate();
  20. const [listLoading, setListLoading] = React.useState(false);
  21. const [userInput, setUserInput] = React.useState(''); // 新增状态:用户输入
  22. type List = {
  23. title: string,
  24. children: {
  25. title: string,
  26. showMenu: string,
  27. chatMode: string,
  28. appId: string,
  29. children: List[number]['children'],
  30. }[],
  31. }[];
  32. const [list, setList] = React.useState<List>([]);
  33. const init = async () => {
  34. setListLoading(true);
  35. try {
  36. const res = await api.get('/deepseek/api/appType');
  37. setList(res.data);
  38. } catch (error) {
  39. console.error(error);
  40. } finally {
  41. setListLoading(false);
  42. }
  43. }
  44. React.useEffect(() => {
  45. chatStore.clearSessions();
  46. const userInfo = localStorage.getItem('userInfo');
  47. if (userInfo) {
  48. init();
  49. }
  50. }, []);
  51. React.useEffect(() => {
  52. globalStore.setDocuments([]);
  53. globalStore.setIsChatActive(false);
  54. setFileList([]);
  55. }, []);
  56. const [fileList, setFileList] = React.useState<any[]>([]);
  57. const props: UploadProps = {
  58. action: '/deepseek-api' + '/upload/file',
  59. method: 'POST',
  60. accept: ['.docx'].join(','),
  61. multiple: true,
  62. maxCount: 5,
  63. fileList: fileList,
  64. onChange(info) {
  65. const fileList = info.fileList.map((file) => {
  66. const data = file.response;
  67. return {
  68. ...file,
  69. documentId: data?.document_id || '',
  70. name: file.name,
  71. url: data?.document_url || file.url,
  72. }
  73. });
  74. setFileList(fileList);
  75. if (info.file.status === 'done') {// 上传成功
  76. const { code, message: msg } = info.file.response;
  77. if (code === 200) {
  78. message.success('上传成功');
  79. } else {
  80. message.error(msg);
  81. }
  82. } else if (info.file.status === 'error') {// 上传失败
  83. message.error('上传失败');
  84. }
  85. },
  86. onDrop(e) {
  87. console.log('Dropped files', e.dataTransfer.files);
  88. },
  89. };
  90. return (
  91. <Spin spinning={listLoading}>
  92. <div className='deekSeek'>
  93. {/* 主要区域 */}
  94. <div className='deekSeek-main'>
  95. {!globalStore.isChatActive ? (
  96. // 未交互状态:显示简化对话框
  97. <div className='deekSeek-content'>
  98. <div className='deekSeek-content-title'>
  99. <img src={jkxz.src} />
  100. </div>
  101. <div className='deekSeek-content-title-sm' style={{ marginBottom: 40 }}>
  102. 您好, 我是小智文件处理助手!
  103. </div>
  104. {/* 输入区域 */}
  105. <div className='deekSeek-input-section'>
  106. <Dragger {...props}>
  107. <p className="ant-upload-drag-icon">
  108. <InboxOutlined />
  109. </p>
  110. <p className="ant-upload-text">请上传.docx格式文件</p>
  111. </Dragger>
  112. </div>
  113. <div style={{ margin: 5 }}>
  114. <Button
  115. type='primary'
  116. onClick={() => {
  117. globalStore.setDocuments(fileList.map(item => {
  118. return {
  119. id: item.documentId,
  120. name: item.name,
  121. url: item.url,
  122. }
  123. }));
  124. globalStore.setIsChatActive(true);
  125. }}
  126. disabled={fileList.filter(item => item.documentId).length === 0}
  127. >
  128. 开始解析
  129. </Button>
  130. </div>
  131. {/* 底部提示 */}
  132. <div className='deekSeek-footer-text'>
  133. 内容由AI生成,仅供参考
  134. </div>
  135. </div>
  136. ) : (
  137. // 激活状态:显示完整对话界面
  138. <div className='deekSeek-content'>
  139. <div className='deekSeek-content-title'>
  140. <img src={jkxz.src} />
  141. </div>
  142. <div className='deekSeek-content-title-sm' style={{ marginBottom: isMobileScreen ? 14 : 20 }}>
  143. 智能问答助手
  144. </div>
  145. <div className={isMobileScreen ? 'deekSeek-content-mobile' : 'deekSeek-content-pc'}>
  146. <Chat />
  147. </div>
  148. </div>
  149. )}
  150. </div>
  151. </div>
  152. </Spin >
  153. );
  154. };
  155. export default DeekSeek;