sidebar.tsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. import React, { useEffect, useRef, useMemo, useState, Fragment } from "react";
  2. import styles from "./home.module.scss";
  3. import DragIcon from "../icons/drag.svg";
  4. import faviconSrc from "../icons/favicon.png";
  5. import deepSeekSrc from "../icons/deepSeek.png";
  6. import { AppstoreOutlined, EditOutlined, MenuOutlined, HomeOutlined, PlusOutlined, StarOutlined } from '@ant-design/icons';
  7. import { useAppConfig, useChatStore, useGlobalStore } from "../store";
  8. import {
  9. DEFAULT_SIDEBAR_WIDTH,
  10. MAX_SIDEBAR_WIDTH,
  11. MIN_SIDEBAR_WIDTH,
  12. NARROW_SIDEBAR_WIDTH,
  13. } from "../constant";
  14. import { useLocation, useNavigate } from "react-router-dom";
  15. import { isIOS, useMobileScreen } from "../utils";
  16. import api from "@/app/api/api";
  17. import { Button, Drawer, Dropdown, Empty, Form, Input, Menu, message, Modal, Rate, Tag } from "antd";
  18. import { downloadFile } from "../utils/index";
  19. import dayjs from "dayjs";
  20. const FormItem = Form.Item;
  21. export function useHotKey() {
  22. const chatStore = useChatStore();
  23. useEffect(() => {
  24. const onKeyDown = (e: KeyboardEvent) => {
  25. if (e.altKey || e.ctrlKey) {
  26. if (e.key === "ArrowUp") {
  27. chatStore.nextSession(-1);
  28. } else if (e.key === "ArrowDown") {
  29. chatStore.nextSession(1);
  30. }
  31. }
  32. };
  33. window.addEventListener("keydown", onKeyDown);
  34. return () => window.removeEventListener("keydown", onKeyDown);
  35. });
  36. }
  37. export function useDragSideBar() {
  38. const limit = (x: number) => Math.min(MAX_SIDEBAR_WIDTH, x);
  39. const config = useAppConfig();
  40. const startX = useRef(0);
  41. const startDragWidth = useRef(config.sidebarWidth ?? DEFAULT_SIDEBAR_WIDTH);
  42. const lastUpdateTime = useRef(Date.now());
  43. const toggleSideBar = () => {
  44. config.update((config) => {
  45. if (config.sidebarWidth < MIN_SIDEBAR_WIDTH) {
  46. config.sidebarWidth = DEFAULT_SIDEBAR_WIDTH;
  47. } else {
  48. config.sidebarWidth = NARROW_SIDEBAR_WIDTH;
  49. }
  50. });
  51. };
  52. const onDragStart = (e: MouseEvent) => {
  53. // Remembers the initial width each time the mouse is pressed
  54. startX.current = e.clientX;
  55. startDragWidth.current = config.sidebarWidth;
  56. const dragStartTime = Date.now();
  57. const handleDragMove = (e: MouseEvent) => {
  58. if (Date.now() < lastUpdateTime.current + 20) {
  59. return;
  60. }
  61. lastUpdateTime.current = Date.now();
  62. const d = e.clientX - startX.current;
  63. const nextWidth = limit(startDragWidth.current + d);
  64. config.update((config) => {
  65. if (nextWidth < MIN_SIDEBAR_WIDTH) {
  66. config.sidebarWidth = NARROW_SIDEBAR_WIDTH;
  67. } else {
  68. config.sidebarWidth = nextWidth;
  69. }
  70. });
  71. };
  72. const handleDragEnd = () => {
  73. // In useRef the data is non-responsive, so `config.sidebarWidth` can't get the dynamic sidebarWidth
  74. window.removeEventListener("pointermove", handleDragMove);
  75. window.removeEventListener("pointerup", handleDragEnd);
  76. // if user click the drag icon, should toggle the sidebar
  77. const shouldFireClick = Date.now() - dragStartTime < 300;
  78. if (shouldFireClick) {
  79. toggleSideBar();
  80. }
  81. };
  82. window.addEventListener("pointermove", handleDragMove);
  83. window.addEventListener("pointerup", handleDragEnd);
  84. };
  85. const isMobileScreen = useMobileScreen();
  86. const shouldNarrow =
  87. !isMobileScreen && config.sidebarWidth < MIN_SIDEBAR_WIDTH;
  88. useEffect(() => {
  89. const barWidth = shouldNarrow
  90. ? NARROW_SIDEBAR_WIDTH
  91. : limit(config.sidebarWidth ?? DEFAULT_SIDEBAR_WIDTH);
  92. const sideBarWidth = isMobileScreen ? "100vw" : `${barWidth}px`;
  93. document.documentElement.style.setProperty("--sidebar-width", sideBarWidth);
  94. }, [config.sidebarWidth, isMobileScreen, shouldNarrow]);
  95. return {
  96. onDragStart,
  97. shouldNarrow,
  98. };
  99. }
  100. export function SideBarContainer(props: {
  101. children: React.ReactNode;
  102. onDragStart: (e: MouseEvent) => void;
  103. shouldNarrow: boolean;
  104. className?: string;
  105. }) {
  106. const isMobileScreen = useMobileScreen();
  107. const isIOSMobile = useMemo(
  108. () => isIOS() && isMobileScreen,
  109. [isMobileScreen],
  110. );
  111. const { children, className, onDragStart, shouldNarrow } = props;
  112. return (
  113. <div
  114. className={`${styles.sidebar} ${className} ${shouldNarrow && styles["narrow-sidebar"]
  115. }`}
  116. style={{
  117. transition: isMobileScreen && isIOSMobile ? "none" : undefined,
  118. background: '#FFFFFF',
  119. overflowY: "auto",
  120. }}
  121. >
  122. {children}
  123. <div
  124. className={styles["sidebar-drag"]}
  125. onPointerDown={(e) => onDragStart(e as any)}
  126. >
  127. <DragIcon />
  128. </div>
  129. </div>
  130. );
  131. }
  132. export function SideBarHeader(props: {
  133. title?: string | React.ReactNode;
  134. subTitle?: string | React.ReactNode;
  135. logo?: React.ReactNode;
  136. children?: React.ReactNode;
  137. }) {
  138. const { title, subTitle, logo, children } = props;
  139. return (
  140. <Fragment>
  141. <div className={styles["sidebar-header"]} data-tauri-drag-region>
  142. <div className={styles["sidebar-title-container"]}>
  143. <div className={styles["sidebar-title"]} data-tauri-drag-region>
  144. {title}
  145. </div>
  146. <div className={styles["sidebar-sub-title"]}>{subTitle}</div>
  147. </div>
  148. <div className={styles["sidebar-logo"] + " no-dark"}>{logo}</div>
  149. </div>
  150. {children}
  151. </Fragment>
  152. );
  153. }
  154. export function SideBarBody(props: {
  155. children: React.ReactNode;
  156. onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
  157. }) {
  158. const { onClick, children } = props;
  159. return (
  160. <div className={styles["sidebar-body"]} onClick={onClick}>
  161. {children}
  162. </div>
  163. );
  164. }
  165. export function SideBarTail(props: {
  166. primaryAction?: React.ReactNode;
  167. secondaryAction?: React.ReactNode;
  168. }) {
  169. const { primaryAction, secondaryAction } = props;
  170. return (
  171. <div className={styles["sidebar-tail"]}>
  172. <div className={styles["sidebar-actions"]}>{primaryAction}</div>
  173. <div className={styles["sidebar-actions"]}>{secondaryAction}</div>
  174. </div>
  175. );
  176. }
  177. interface AppDrawerProps {
  178. isMobileScreen: boolean,
  179. selectedAppId: string,
  180. type: 'all' | 'collect',
  181. open: boolean,
  182. onClose: () => void,
  183. }
  184. const AppDrawer: React.FC<AppDrawerProps> = (props) => {
  185. const {
  186. isMobileScreen,
  187. selectedAppId,
  188. type,
  189. open,
  190. onClose,
  191. } = props;
  192. const navigate = useNavigate();
  193. const [listLoading, setListLoading] = useState(false);
  194. type List = {
  195. name: string,
  196. chatMode: string,
  197. appId: string,
  198. desc: string,
  199. createTime: string,
  200. typeName: string,
  201. isCollect: boolean,
  202. }[];
  203. const [list, setList] = useState<List>([]);
  204. const fetchAppList = async () => {
  205. setListLoading(true);
  206. try {
  207. const res = await api.get(`/deepseek/api/project/app`);
  208. // // 确保 res.data 是数组,如果不是则设为空数组 error
  209. // const data = Array.isArray(res.data) ? res.data : [];
  210. if (type === 'all') {
  211. setList(res.data);
  212. } else {
  213. setList(res.data.filter((item: any) => item.isCollect));
  214. }
  215. } catch (error) {
  216. console.error(error);
  217. // // 出错时设置为空数组,避免渲染错误 error
  218. // setList([]);
  219. } finally {
  220. setListLoading(false);
  221. }
  222. };
  223. // 收藏应用
  224. const collectApp = async (appId: string) => {
  225. try {
  226. await api.post('/deepseek/api/app/collect', {
  227. appId: appId
  228. });
  229. message.success('收藏成功');
  230. await fetchAppList();
  231. } catch (error: any) {
  232. message.error(error.msg);
  233. }
  234. };
  235. // 取消收藏应用
  236. const cancelCollectApp = async (appId: string) => {
  237. try {
  238. await api.delete(`/deepseek/api/app/collect/${appId}`);
  239. message.success('操作成功');
  240. await fetchAppList();
  241. } catch (error: any) {
  242. message.error(error.msg);
  243. }
  244. };
  245. const init = async () => {
  246. await fetchAppList();
  247. }
  248. useEffect(() => {
  249. init();
  250. }, [])
  251. return (
  252. <Drawer
  253. width={isMobileScreen ? '100%' : 400}
  254. title={type === 'all' ? '我的应用' : '我的收藏'}
  255. open={open}
  256. loading={listLoading}
  257. onClose={onClose}
  258. >
  259. {
  260. list.length > 0 ?
  261. // Array.isArray(list) && list.length > 0 ? //error
  262. list.map((item, index) => {
  263. return <div
  264. style={{
  265. padding: 20,
  266. border: '1px solid #f0f0f0',
  267. borderRadius: 4,
  268. marginBottom: 20,
  269. cursor: 'pointer',
  270. }}
  271. key={index}
  272. >
  273. <div style={{ display: 'flex', marginBottom: 10 }}>
  274. <AppstoreOutlined style={{ fontSize: 40, color: '#3875f6', marginRight: 20 }} />
  275. <div>
  276. <div style={{ fontSize: 16, fontWeight: 'bold', marginBottom: 5 }}>
  277. {item.name}
  278. </div>
  279. <div style={{ color: '#d4d7de' }}>
  280. ID:{item.appId}
  281. </div>
  282. </div>
  283. </div>
  284. <div style={{ color: '#8f949e', marginBottom: 10 }}>
  285. {item.desc}
  286. </div>
  287. <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
  288. <div style={{ color: '#747a86' }}>
  289. {dayjs(item.createTime).format('YYYY-MM-DD')} 发布
  290. </div>
  291. <div>
  292. <Tag style={{ margin: 0 }} color="blue">
  293. {item.typeName}
  294. </Tag>
  295. </div>
  296. </div>
  297. <div
  298. style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
  299. <div onClick={async () => {
  300. if (item.isCollect) {
  301. await cancelCollectApp(item.appId);
  302. } else {
  303. await collectApp(item.appId);
  304. }
  305. }}>
  306. {
  307. item.isCollect ?
  308. <Rate count={1} value={1} />
  309. :
  310. <Rate count={1} />
  311. }
  312. </div>
  313. <Button type='primary' size="small" onClick={() => {
  314. const search = `?showMenu=false&chatMode=${item.chatMode}&appId=${item.appId}`;
  315. navigate({
  316. pathname: '/knowledgeChat',
  317. search: search,
  318. })
  319. location.reload();
  320. }}>
  321. 使用
  322. </Button>
  323. </div>
  324. </div>
  325. })
  326. :
  327. <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
  328. }
  329. </Drawer>
  330. )
  331. }
  332. export const SideBar = (props: { className?: string }) => {
  333. // useHotKey();
  334. const { onDragStart, shouldNarrow } = useDragSideBar();
  335. const [showPluginSelector, setShowPluginSelector] = useState(false);
  336. const navigate = useNavigate();
  337. const location = useLocation();
  338. const chatStore = useChatStore();
  339. const globalStore = useGlobalStore();
  340. const [menuList, setMenuList] = useState([])
  341. const [modalOpen, setModalOpen] = useState(false)
  342. const [form] = Form.useForm();
  343. const getType = (): 'bigModel' | 'deepSeek' => {
  344. if (['/knowledgeChat', '/newChat'].includes(location.pathname)) {
  345. return 'bigModel';
  346. } else if (['/deepseekChat', '/newDeepseekChat'].includes(location.pathname)) {
  347. return 'deepSeek';
  348. } else {
  349. return 'bigModel';
  350. }
  351. }
  352. // 获取聊天列表
  353. const fetchChatList = async (chatMode?: 'ONLINE' | 'LOCAL') => {
  354. try {
  355. let url = '';
  356. if (getType() === 'bigModel') {
  357. const appId = globalStore.selectedAppId;
  358. if (appId) {
  359. if (chatMode === 'LOCAL') {
  360. url = `/deepseek/api/dialog/list/${appId}`;
  361. } else {
  362. url = `/bigmodel/api/dialog/list/${appId}`;
  363. }
  364. }
  365. } else {
  366. const appId = '1881269958412521255';
  367. url = `/bigmodel/api/dialog/list/${appId}`;
  368. }
  369. const res = await api.get(url);
  370. const list = res.data.map((item: any) => {
  371. return {
  372. ...item,
  373. children: item.children.map((child: any) => {
  374. const items = [
  375. {
  376. key: '1',
  377. label: (
  378. <a onClick={() => {
  379. setModalOpen(true);
  380. form.setFieldsValue({
  381. dialogId: child.key,
  382. dialogName: child.label
  383. });
  384. }}>
  385. 重命名
  386. </a>
  387. ),
  388. },
  389. {
  390. key: '2',
  391. label: (
  392. <a onClick={async () => {
  393. try {
  394. let blob = null;
  395. if (getType() === 'bigModel') {
  396. if (chatMode === 'LOCAL') {
  397. blob = await api.post(`/deepseek/api/dialog/export/${child.key}`, {}, { responseType: 'blob' });
  398. } else {
  399. blob = await api.post(`/bigmodel/api/dialog/export/${child.key}`, {}, { responseType: 'blob' });
  400. }
  401. } else {
  402. blob = await api.post(`/bigmodel/api/dialog/export/${child.key}`, {}, { responseType: 'blob' });
  403. }
  404. const fileName = `${child.label}.xlsx`;
  405. downloadFile(blob, fileName);
  406. } catch (error) {
  407. console.error(error);
  408. }
  409. }}>
  410. 导出
  411. </a>
  412. ),
  413. },
  414. {
  415. key: '3',
  416. label: (
  417. <a onClick={async () => {
  418. try {
  419. if (getType() === 'bigModel') {
  420. if (chatMode === 'LOCAL') {
  421. await api.delete(`/deepseek/api/dialog/del/${child.key}`);
  422. await fetchChatList(chatMode);
  423. } else {
  424. await api.delete(`/bigmodel/api/dialog/del/${child.key}`);
  425. await fetchChatList();
  426. }
  427. } else {
  428. await api.delete(`/bigmodel/api/dialog/del/${child.key}`);
  429. await fetchChatList();
  430. }
  431. chatStore.clearSessions();
  432. useChatStore.setState({
  433. message: {
  434. content: '',
  435. role: 'assistant',
  436. }
  437. });
  438. } catch (error) {
  439. console.error(error);
  440. }
  441. }}>
  442. 删除
  443. </a>
  444. ),
  445. },
  446. ];
  447. return {
  448. ...child,
  449. label: <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
  450. <div style={{ flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', marginRight: 10 }}>
  451. {child.label}
  452. </div>
  453. <div style={{ width: 20 }}>
  454. <Dropdown menu={{ items }} trigger={['click']} placement="bottomRight">
  455. <EditOutlined onClick={(e) => e.stopPropagation()} />
  456. </Dropdown>
  457. </div>
  458. </div>
  459. }
  460. })
  461. }
  462. })
  463. setMenuList(list);
  464. } catch (error) {
  465. console.error(error)
  466. }
  467. }
  468. useEffect(() => {
  469. if (getType() === 'bigModel') {
  470. if (globalStore.selectedAppId) {
  471. fetchChatList(chatStore.chatMode);
  472. }
  473. }
  474. }, [globalStore.selectedAppId]);
  475. useEffect(() => {
  476. chatStore.clearSessions();
  477. useChatStore.setState({
  478. message: {
  479. content: '',
  480. role: 'assistant',
  481. }
  482. });
  483. }, []);
  484. useEffect(() => {
  485. fetchChatList(chatStore.chatMode);
  486. }, [chatStore.chatMode]);
  487. const isMobileScreen = useMobileScreen();
  488. const [drawerOpen, setDrawerOpen] = useState(false);
  489. const [drawerType, setDrawerType] = useState<'all' | 'collect'>('all');
  490. return (
  491. <>
  492. {
  493. globalStore.showMenu &&
  494. <SideBarContainer
  495. onDragStart={onDragStart}
  496. shouldNarrow={shouldNarrow}
  497. {...props}
  498. >
  499. {
  500. getType() === 'deepSeek' &&
  501. <div>
  502. <img style={{ width: '100%' }} src={deepSeekSrc.src} />
  503. </div>
  504. }
  505. <SideBarHeader
  506. title={getType() === 'bigModel' ?
  507. <div style={{ display: 'flex', alignItems: 'center' }}>
  508. {
  509. isMobileScreen && <div>
  510. <Button
  511. type='text'
  512. icon={<MenuOutlined />}
  513. onClick={() => {
  514. globalStore.setShowMenu(!globalStore.showMenu);
  515. }}
  516. />
  517. </div>
  518. }
  519. 问答历史
  520. </div>
  521. :
  522. ''
  523. }
  524. logo={getType() === 'bigModel' ? <img style={{ height: 40 }} src={faviconSrc.src} /> : ''}
  525. >
  526. <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 10, gap: 8 }}>
  527. <Button
  528. style={{
  529. width: '48%',
  530. height: 36,
  531. borderRadius: 6,
  532. fontSize: 14,
  533. fontWeight: 500
  534. }}
  535. icon={<HomeOutlined />}
  536. onClick={() => {
  537. navigate({ pathname: '/' });
  538. }}
  539. >
  540. 回到首页
  541. </Button>
  542. <Button
  543. style={{
  544. width: '48%',
  545. height: 36,
  546. borderRadius: 6,
  547. fontSize: 14,
  548. fontWeight: 500
  549. }}
  550. icon={<PlusOutlined />}
  551. onClick={async () => {
  552. chatStore.clearSessions();
  553. chatStore.updateCurrentSession((value) => {
  554. value.appId = globalStore.selectedAppId;
  555. });
  556. if (isMobileScreen) {
  557. globalStore.setShowMenu(false);
  558. }
  559. if (getType() === 'bigModel') {
  560. navigate({ pathname: '/newChat' });
  561. } else {
  562. navigate({ pathname: '/newDeepseekChat' });
  563. }
  564. if (getType() === 'bigModel') {
  565. if (chatStore.chatMode === 'LOCAL') {
  566. await fetchChatList(chatStore.chatMode);
  567. } else {
  568. await fetchChatList();
  569. }
  570. } else {
  571. await fetchChatList();
  572. }
  573. }}
  574. >
  575. 新建对话
  576. </Button>
  577. </div>
  578. <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 10, gap: 8 }}>
  579. <Button
  580. style={{
  581. width: '48%',
  582. height: 36,
  583. borderRadius: 6,
  584. fontSize: 14,
  585. fontWeight: 500
  586. }}
  587. icon={<AppstoreOutlined />}
  588. onClick={() => {
  589. setDrawerType('all');
  590. setDrawerOpen(true);
  591. }}
  592. >
  593. 我的应用
  594. </Button>
  595. <Button
  596. style={{
  597. width: '48%',
  598. height: 36,
  599. borderRadius: 6,
  600. fontSize: 14,
  601. fontWeight: 500
  602. }}
  603. icon={<StarOutlined />}
  604. onClick={() => {
  605. setDrawerType('collect');
  606. setDrawerOpen(true);
  607. }}
  608. >
  609. 我的收藏
  610. </Button>
  611. </div>
  612. </SideBarHeader>
  613. <Menu
  614. style={{ border: 'none' }}
  615. onClick={async (info) => {
  616. const key = info.key;
  617. // @ts-ignore
  618. const props = info.item.props;
  619. const { showMenu, chatMode, appId } = props;
  620. if (isMobileScreen) {
  621. globalStore.setShowMenu(false);
  622. }
  623. let url = ``;
  624. if (getType() === 'bigModel') {
  625. if (chatStore.chatMode === 'LOCAL') {
  626. url = `/deepseek/api/dialog/detail/${key}`;
  627. } else {
  628. url = `/bigmodel/api/dialog/detail/${key}`;
  629. }
  630. } else {
  631. url = `/bigmodel/api/dialog/detail/${key}`;
  632. }
  633. const res = await api.get(url);
  634. const list = res.data.map(((item: any) => {
  635. if(item.sliceInfo){
  636. let allChunkNum = 0;
  637. item.sliceInfo.doc.forEach((doc: any) => {
  638. allChunkNum += doc.chunk_nums;
  639. });
  640. item.sliceInfo.allChunkNum = allChunkNum;
  641. }
  642. return {
  643. id: item.did,
  644. role: item.type,
  645. date: item.create_time,
  646. content: item.content,
  647. document: item.document ? item.document : undefined,
  648. sliceInfo: item.sliceInfo ? item.sliceInfo : undefined,
  649. networkInfo: item.networkInfo ? item.networkInfo : undefined,
  650. }
  651. }))
  652. const session = {
  653. appId: res.data.length ? res.data[0].appId : '',
  654. dialogName: res.data.length ? res.data[0].dialog_name : '',
  655. id: res.data.length ? res.data[0].id : '',
  656. messages: list,
  657. }
  658. globalStore.setCurrentSession(session);
  659. chatStore.clearSessions();
  660. chatStore.updateCurrentSession((value) => {
  661. value.appId = session.appId;
  662. value.topic = session.dialogName;
  663. value.id = session.id;
  664. value.messages = list;
  665. });
  666. if (getType() === 'bigModel') {
  667. const search = `?showMenu=${showMenu}&chatMode=${chatMode}&appId=${appId}`;
  668. if (appId) {
  669. navigate({
  670. pathname: '/knowledgeChat',
  671. search: search,
  672. })
  673. }
  674. } else {
  675. navigate({ pathname: '/newDeepseekChat' });
  676. }
  677. }}
  678. mode="inline"
  679. items={menuList}
  680. />
  681. <Modal
  682. title="重命名"
  683. open={modalOpen}
  684. width={300}
  685. maskClosable={false}
  686. onOk={() => {
  687. form.validateFields().then(async (values) => {
  688. setModalOpen(false);
  689. try {
  690. if (getType() === 'bigModel') {
  691. if (chatStore.chatMode === 'LOCAL') {
  692. await api.put(`/deepseek/api/dialog/update`, {
  693. id: values.dialogId,
  694. dialogName: values.dialogName
  695. });
  696. await fetchChatList(chatStore.chatMode);
  697. } else {
  698. await api.put(`/bigmodel/api/dialog/update`, {
  699. id: values.dialogId,
  700. dialogName: values.dialogName
  701. });
  702. await fetchChatList();
  703. }
  704. } else {
  705. await api.put(`/bigmodel/api/dialog/update`, {
  706. id: values.dialogId,
  707. dialogName: values.dialogName
  708. });
  709. await fetchChatList();
  710. }
  711. chatStore.updateCurrentSession((value) => {
  712. value.topic = values.dialogName;
  713. });
  714. } catch (error) {
  715. console.error(error);
  716. }
  717. }).catch((error) => {
  718. console.error(error);
  719. });
  720. }}
  721. onCancel={() => {
  722. setModalOpen(false);
  723. }}
  724. >
  725. <Form form={form} layout='inline'>
  726. <FormItem name='dialogId' noStyle />
  727. <FormItem
  728. label='名称'
  729. name='dialogName'
  730. rules={[{ required: true, message: '名称不能为空', whitespace: true }]}
  731. >
  732. <Input
  733. style={{ width: 300 }}
  734. placeholder='请输入'
  735. maxLength={20}
  736. />
  737. </FormItem>
  738. </Form>
  739. </Modal>
  740. </SideBarContainer>
  741. }
  742. {
  743. drawerOpen &&
  744. <AppDrawer
  745. isMobileScreen={isMobileScreen}
  746. selectedAppId={globalStore.selectedAppId}
  747. type={drawerType}
  748. open={drawerOpen}
  749. onClose={() => {
  750. setDrawerOpen(false);
  751. }}
  752. />
  753. }
  754. </>
  755. );
  756. }