sidebar.tsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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 ? "60vw" : `${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. const closeSidebar = () => {
  491. globalStore.setShowMenu(false);
  492. };
  493. return (
  494. <>
  495. {
  496. isMobileScreen && globalStore.showMenu && (
  497. <div
  498. className={styles["sidebar-overlay"]}
  499. onClick={closeSidebar}
  500. />
  501. )
  502. }
  503. {
  504. globalStore.showMenu &&
  505. <SideBarContainer
  506. onDragStart={onDragStart}
  507. shouldNarrow={shouldNarrow}
  508. {...props}
  509. >
  510. {
  511. getType() === 'deepSeek' &&
  512. <div>
  513. <img style={{ width: '100%' }} src={deepSeekSrc.src} />
  514. </div>
  515. }
  516. <SideBarHeader
  517. title={getType() === 'bigModel' ?
  518. <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
  519. {
  520. isMobileScreen && <div>
  521. <Button
  522. type='text'
  523. icon={<MenuOutlined />}
  524. onClick={() => {
  525. globalStore.setShowMenu(!globalStore.showMenu);
  526. }}
  527. />
  528. </div>
  529. }
  530. <img style={{ height: 32 }} src={faviconSrc.src} />
  531. <span>建科•小智</span>
  532. </div>
  533. :
  534. ''
  535. }
  536. logo={getType() === 'bigModel' ? null : ''}
  537. >
  538. <div className={styles["sidebar-action-group"]}>
  539. <Button
  540. className={styles["sidebar-action-button"]}
  541. icon={<HomeOutlined />}
  542. onClick={() => {
  543. navigate({ pathname: '/' });
  544. }}
  545. >
  546. 回到首页
  547. </Button>
  548. <Button
  549. className={styles["sidebar-action-button"]}
  550. icon={<PlusOutlined />}
  551. onClick={async () => {
  552. chatStore.clearSessions();
  553. chatStore.updateCurrentSession((value) => {
  554. value.appId = globalStore.selectedAppId;
  555. });
  556. if (isMobileScreen) {
  557. closeSidebar();
  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 className={styles["sidebar-action-group"]}>
  579. <Button
  580. className={styles["sidebar-action-button"]}
  581. icon={<AppstoreOutlined />}
  582. onClick={() => {
  583. setDrawerType('all');
  584. setDrawerOpen(true);
  585. }}
  586. >
  587. 我的应用
  588. </Button>
  589. <Button
  590. className={styles["sidebar-action-button"]}
  591. icon={<StarOutlined />}
  592. onClick={() => {
  593. setDrawerType('collect');
  594. setDrawerOpen(true);
  595. }}
  596. >
  597. 我的收藏
  598. </Button>
  599. </div>
  600. </SideBarHeader>
  601. <div style={{
  602. fontSize: 12,
  603. color: '#999999',
  604. padding: '8px 0 4px',
  605. }}>
  606. 问答历史
  607. </div>
  608. <Menu
  609. style={{ border: 'none' }}
  610. onClick={async (info) => {
  611. const key = info.key;
  612. // @ts-ignore
  613. const props = info.item.props;
  614. const { showMenu, chatMode, appId } = props;
  615. if (isMobileScreen) {
  616. closeSidebar();
  617. }
  618. let url = ``;
  619. if (getType() === 'bigModel') {
  620. if (chatStore.chatMode === 'LOCAL') {
  621. url = `/deepseek/api/dialog/detail/${key}`;
  622. } else {
  623. url = `/bigmodel/api/dialog/detail/${key}`;
  624. }
  625. } else {
  626. url = `/bigmodel/api/dialog/detail/${key}`;
  627. }
  628. const res = await api.get(url);
  629. const list = res.data.map(((item: any) => {
  630. if(item.sliceInfo){
  631. let allChunkNum = 0;
  632. item.sliceInfo.doc.forEach((doc: any) => {
  633. allChunkNum += doc.chunk_nums;
  634. });
  635. item.sliceInfo.allChunkNum = allChunkNum;
  636. }
  637. return {
  638. id: item.did,
  639. role: item.type,
  640. date: item.create_time,
  641. content: item.content,
  642. document: item.document ? item.document : undefined,
  643. sliceInfo: item.sliceInfo ? item.sliceInfo : undefined,
  644. networkInfo: item.networkInfo ? item.networkInfo : undefined,
  645. }
  646. }))
  647. const session = {
  648. appId: res.data.length ? res.data[0].appId : '',
  649. dialogName: res.data.length ? res.data[0].dialog_name : '',
  650. id: res.data.length ? res.data[0].id : '',
  651. messages: list,
  652. }
  653. globalStore.setCurrentSession(session);
  654. chatStore.clearSessions();
  655. chatStore.updateCurrentSession((value) => {
  656. value.appId = session.appId;
  657. value.topic = session.dialogName;
  658. value.id = session.id;
  659. value.messages = list;
  660. });
  661. if (getType() === 'bigModel') {
  662. const search = `?showMenu=${showMenu}&chatMode=${chatMode}&appId=${appId}`;
  663. if (appId) {
  664. navigate({
  665. pathname: '/knowledgeChat',
  666. search: search,
  667. })
  668. }
  669. } else {
  670. navigate({ pathname: '/newDeepseekChat' });
  671. }
  672. }}
  673. mode="inline"
  674. items={menuList}
  675. />
  676. <Modal
  677. title="重命名"
  678. open={modalOpen}
  679. width={300}
  680. maskClosable={false}
  681. onOk={() => {
  682. form.validateFields().then(async (values) => {
  683. setModalOpen(false);
  684. try {
  685. if (getType() === 'bigModel') {
  686. if (chatStore.chatMode === 'LOCAL') {
  687. await api.put(`/deepseek/api/dialog/update`, {
  688. id: values.dialogId,
  689. dialogName: values.dialogName
  690. });
  691. await fetchChatList(chatStore.chatMode);
  692. } else {
  693. await api.put(`/bigmodel/api/dialog/update`, {
  694. id: values.dialogId,
  695. dialogName: values.dialogName
  696. });
  697. await fetchChatList();
  698. }
  699. } else {
  700. await api.put(`/bigmodel/api/dialog/update`, {
  701. id: values.dialogId,
  702. dialogName: values.dialogName
  703. });
  704. await fetchChatList();
  705. }
  706. chatStore.updateCurrentSession((value) => {
  707. value.topic = values.dialogName;
  708. });
  709. } catch (error) {
  710. console.error(error);
  711. }
  712. }).catch((error) => {
  713. console.error(error);
  714. });
  715. }}
  716. onCancel={() => {
  717. setModalOpen(false);
  718. }}
  719. >
  720. <Form form={form} layout='inline'>
  721. <FormItem name='dialogId' noStyle />
  722. <FormItem
  723. label='名称'
  724. name='dialogName'
  725. rules={[{ required: true, message: '名称不能为空', whitespace: true }]}
  726. >
  727. <Input
  728. style={{ width: 300 }}
  729. placeholder='请输入'
  730. maxLength={20}
  731. />
  732. </FormItem>
  733. </Form>
  734. </Modal>
  735. </SideBarContainer>
  736. }
  737. {
  738. drawerOpen &&
  739. <AppDrawer
  740. isMobileScreen={isMobileScreen}
  741. selectedAppId={globalStore.selectedAppId}
  742. type={drawerType}
  743. open={drawerOpen}
  744. onClose={() => {
  745. setDrawerOpen(false);
  746. }}
  747. />
  748. }
  749. </>
  750. );
  751. }