sidebar.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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 } 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 是数组,如果不是则设为空数组
  209. const data = Array.isArray(res.data) ? res.data : [];
  210. if (type === 'all') {
  211. setList(data);
  212. } else {
  213. setList(data.filter((item: any) => item.isCollect));
  214. }
  215. } catch (error) {
  216. console.error(error);
  217. // 出错时设置为空数组,避免渲染错误
  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. Array.isArray(list) && list.length > 0 ?
  261. list.map((item, index) => {
  262. return <div
  263. style={{
  264. padding: 20,
  265. border: '1px solid #f0f0f0',
  266. borderRadius: 4,
  267. marginBottom: 20,
  268. cursor: 'pointer',
  269. }}
  270. key={index}
  271. >
  272. <div style={{ display: 'flex', marginBottom: 10 }}>
  273. <AppstoreOutlined style={{ fontSize: 40, color: '#3875f6', marginRight: 20 }} />
  274. <div>
  275. <div style={{ fontSize: 16, fontWeight: 'bold', marginBottom: 5 }}>
  276. {item.name}
  277. </div>
  278. <div style={{ color: '#d4d7de' }}>
  279. ID:{item.appId}
  280. </div>
  281. </div>
  282. </div>
  283. <div style={{ color: '#8f949e', marginBottom: 10 }}>
  284. {item.desc}
  285. </div>
  286. <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
  287. <div style={{ color: '#747a86' }}>
  288. {dayjs(item.createTime).format('YYYY-MM-DD')} 发布
  289. </div>
  290. <div>
  291. <Tag style={{ margin: 0 }} color="blue">
  292. {item.typeName}
  293. </Tag>
  294. </div>
  295. </div>
  296. <div
  297. style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
  298. <div onClick={async () => {
  299. if (item.isCollect) {
  300. await cancelCollectApp(item.appId);
  301. } else {
  302. await collectApp(item.appId);
  303. }
  304. }}>
  305. {
  306. item.isCollect ?
  307. <Rate count={1} value={1} />
  308. :
  309. <Rate count={1} />
  310. }
  311. </div>
  312. <Button type='primary' size="small" onClick={() => {
  313. const search = `?showMenu=false&chatMode=${item.chatMode}&appId=${item.appId}`;
  314. navigate({
  315. pathname: '/knowledgeChat',
  316. search: search,
  317. })
  318. location.reload();
  319. }}>
  320. 使用
  321. </Button>
  322. </div>
  323. </div>
  324. })
  325. :
  326. <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
  327. }
  328. </Drawer>
  329. )
  330. }
  331. export const SideBar = (props: { className?: string }) => {
  332. // useHotKey();
  333. const { onDragStart, shouldNarrow } = useDragSideBar();
  334. const [showPluginSelector, setShowPluginSelector] = useState(false);
  335. const navigate = useNavigate();
  336. const location = useLocation();
  337. const chatStore = useChatStore();
  338. const globalStore = useGlobalStore();
  339. const [menuList, setMenuList] = useState([])
  340. const [modalOpen, setModalOpen] = useState(false)
  341. const [form] = Form.useForm();
  342. const getType = (): 'bigModel' | 'deepSeek' => {
  343. if (['/knowledgeChat', '/newChat'].includes(location.pathname)) {
  344. return 'bigModel';
  345. } else if (['/deepseekChat', '/newDeepseekChat'].includes(location.pathname)) {
  346. return 'deepSeek';
  347. } else {
  348. return 'bigModel';
  349. }
  350. }
  351. // 获取聊天列表
  352. const fetchChatList = async (chatMode?: 'ONLINE' | 'LOCAL') => {
  353. try {
  354. let url = '';
  355. if (getType() === 'bigModel') {
  356. const appId = globalStore.selectedAppId;
  357. if (appId) {
  358. if (chatMode === 'LOCAL') {
  359. url = `/deepseek/api/dialog/list/${appId}`;
  360. } else {
  361. url = `/bigmodel/api/dialog/list/${appId}`;
  362. }
  363. }
  364. } else {
  365. const appId = '1881269958412521255';
  366. url = `/bigmodel/api/dialog/list/${appId}`;
  367. }
  368. const res = await api.get(url);
  369. const list = res.data.map((item: any) => {
  370. return {
  371. ...item,
  372. children: item.children.map((child: any) => {
  373. const items = [
  374. {
  375. key: '1',
  376. label: (
  377. <a onClick={() => {
  378. setModalOpen(true);
  379. form.setFieldsValue({
  380. dialogId: child.key,
  381. dialogName: child.label
  382. });
  383. }}>
  384. 重命名
  385. </a>
  386. ),
  387. },
  388. {
  389. key: '2',
  390. label: (
  391. <a onClick={async () => {
  392. try {
  393. let blob = null;
  394. if (getType() === 'bigModel') {
  395. if (chatMode === 'LOCAL') {
  396. blob = await api.post(`/deepseek/api/dialog/export/${child.key}`, {}, { responseType: 'blob' });
  397. } else {
  398. blob = await api.post(`/bigmodel/api/dialog/export/${child.key}`, {}, { responseType: 'blob' });
  399. }
  400. } else {
  401. blob = await api.post(`/bigmodel/api/dialog/export/${child.key}`, {}, { responseType: 'blob' });
  402. }
  403. const fileName = `${child.label}.xlsx`;
  404. downloadFile(blob, fileName);
  405. } catch (error) {
  406. console.error(error);
  407. }
  408. }}>
  409. 导出
  410. </a>
  411. ),
  412. },
  413. {
  414. key: '3',
  415. label: (
  416. <a onClick={async () => {
  417. try {
  418. if (getType() === 'bigModel') {
  419. if (chatMode === 'LOCAL') {
  420. await api.delete(`/deepseek/api/dialog/del/${child.key}`);
  421. await fetchChatList(chatMode);
  422. } else {
  423. await api.delete(`/bigmodel/api/dialog/del/${child.key}`);
  424. await fetchChatList();
  425. }
  426. } else {
  427. await api.delete(`/bigmodel/api/dialog/del/${child.key}`);
  428. await fetchChatList();
  429. }
  430. chatStore.clearSessions();
  431. useChatStore.setState({
  432. message: {
  433. content: '',
  434. role: 'assistant',
  435. }
  436. });
  437. } catch (error) {
  438. console.error(error);
  439. }
  440. }}>
  441. 删除
  442. </a>
  443. ),
  444. },
  445. ];
  446. return {
  447. ...child,
  448. label: <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
  449. <div style={{ flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', marginRight: 10 }}>
  450. {child.label}
  451. </div>
  452. <div style={{ width: 20 }}>
  453. <Dropdown menu={{ items }} trigger={['click']} placement="bottomRight">
  454. <EditOutlined onClick={(e) => e.stopPropagation()} />
  455. </Dropdown>
  456. </div>
  457. </div>
  458. }
  459. })
  460. }
  461. })
  462. setMenuList(list);
  463. } catch (error) {
  464. console.error(error)
  465. }
  466. }
  467. useEffect(() => {
  468. if (getType() === 'bigModel') {
  469. if (globalStore.selectedAppId) {
  470. fetchChatList(chatStore.chatMode);
  471. }
  472. }
  473. }, [globalStore.selectedAppId]);
  474. useEffect(() => {
  475. chatStore.clearSessions();
  476. useChatStore.setState({
  477. message: {
  478. content: '',
  479. role: 'assistant',
  480. }
  481. });
  482. }, []);
  483. useEffect(() => {
  484. fetchChatList(chatStore.chatMode);
  485. }, [chatStore.chatMode]);
  486. const isMobileScreen = useMobileScreen();
  487. const [drawerOpen, setDrawerOpen] = useState(false);
  488. const [drawerType, setDrawerType] = useState<'all' | 'collect'>('all');
  489. return (
  490. <>
  491. {
  492. globalStore.showMenu &&
  493. <SideBarContainer
  494. onDragStart={onDragStart}
  495. shouldNarrow={shouldNarrow}
  496. {...props}
  497. >
  498. {
  499. getType() === 'deepSeek' &&
  500. <div>
  501. <img style={{ width: '100%' }} src={deepSeekSrc.src} />
  502. </div>
  503. }
  504. <SideBarHeader
  505. title={getType() === 'bigModel' ?
  506. <div style={{ display: 'flex', alignItems: 'center' }}>
  507. {
  508. isMobileScreen && <div>
  509. <Button
  510. type='text'
  511. icon={<MenuOutlined />}
  512. onClick={() => {
  513. globalStore.setShowMenu(!globalStore.showMenu);
  514. }}
  515. />
  516. </div>
  517. }
  518. 问答历史
  519. </div>
  520. :
  521. ''
  522. }
  523. logo={getType() === 'bigModel' ? <img style={{ height: 40 }} src={faviconSrc.src} /> : ''}
  524. >
  525. <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 10 }}>
  526. <Button
  527. style={{ width: '48%' }}
  528. onClick={() => {
  529. navigate({ pathname: '/' });
  530. }}
  531. >
  532. 回到首页
  533. </Button>
  534. <Button
  535. style={{ width: '48%' }}
  536. onClick={async () => {
  537. chatStore.clearSessions();
  538. chatStore.updateCurrentSession((value) => {
  539. value.appId = globalStore.selectedAppId;
  540. });
  541. if (isMobileScreen) {
  542. globalStore.setShowMenu(false);
  543. }
  544. if (getType() === 'bigModel') {
  545. navigate({ pathname: '/newChat' });
  546. } else {
  547. navigate({ pathname: '/newDeepseekChat' });
  548. }
  549. if (getType() === 'bigModel') {
  550. if (chatStore.chatMode === 'LOCAL') {
  551. await fetchChatList(chatStore.chatMode);
  552. } else {
  553. await fetchChatList();
  554. }
  555. } else {
  556. await fetchChatList();
  557. }
  558. }}
  559. >
  560. 新建对话
  561. </Button>
  562. </div>
  563. <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 10 }}>
  564. <Button
  565. style={{ width: '48%' }}
  566. type="primary"
  567. onClick={() => {
  568. setDrawerType('all');
  569. setDrawerOpen(true);
  570. }}
  571. >
  572. 我的应用
  573. </Button>
  574. <Button
  575. style={{ width: '48%' }}
  576. type="primary"
  577. onClick={() => {
  578. setDrawerType('collect');
  579. setDrawerOpen(true);
  580. }}
  581. >
  582. 我的收藏
  583. </Button>
  584. </div>
  585. </SideBarHeader>
  586. <Menu
  587. style={{ border: 'none' }}
  588. onClick={async (info) => {
  589. const key = info.key;
  590. // @ts-ignore
  591. const props = info.item.props;
  592. const { showMenu, chatMode, appId } = props;
  593. if (isMobileScreen) {
  594. globalStore.setShowMenu(false);
  595. }
  596. let url = ``;
  597. if (getType() === 'bigModel') {
  598. if (chatStore.chatMode === 'LOCAL') {
  599. url = `/deepseek/api/dialog/detail/${key}`;
  600. } else {
  601. url = `/bigmodel/api/dialog/detail/${key}`;
  602. }
  603. } else {
  604. url = `/bigmodel/api/dialog/detail/${key}`;
  605. }
  606. const res = await api.get(url);
  607. const list = res.data.map(((item: any) => {
  608. return {
  609. id: item.did,
  610. role: item.type,
  611. date: item.create_time,
  612. content: item.content,
  613. document: item.document ? item.document : undefined,
  614. sliceInfo: item.sliceInfo ? item.sliceInfo : undefined,
  615. networkInfo: item.networkInfo ? item.networkInfo : undefined,
  616. }
  617. }))
  618. const session = {
  619. appId: res.data.length ? res.data[0].appId : '',
  620. dialogName: res.data.length ? res.data[0].dialog_name : '',
  621. id: res.data.length ? res.data[0].id : '',
  622. messages: list,
  623. }
  624. globalStore.setCurrentSession(session);
  625. chatStore.clearSessions();
  626. chatStore.updateCurrentSession((value) => {
  627. value.appId = session.appId;
  628. value.topic = session.dialogName;
  629. value.id = session.id;
  630. value.messages = list;
  631. });
  632. if (getType() === 'bigModel') {
  633. const search = `?showMenu=${showMenu}&chatMode=${chatMode}&appId=${appId}`;
  634. if (appId) {
  635. navigate({
  636. pathname: '/knowledgeChat',
  637. search: search,
  638. })
  639. }
  640. } else {
  641. navigate({ pathname: '/newDeepseekChat' });
  642. }
  643. }}
  644. mode="inline"
  645. items={menuList}
  646. />
  647. <Modal
  648. title="重命名"
  649. open={modalOpen}
  650. width={300}
  651. maskClosable={false}
  652. onOk={() => {
  653. form.validateFields().then(async (values) => {
  654. setModalOpen(false);
  655. try {
  656. if (getType() === 'bigModel') {
  657. if (chatStore.chatMode === 'LOCAL') {
  658. await api.put(`/deepseek/api/dialog/update`, {
  659. id: values.dialogId,
  660. dialogName: values.dialogName
  661. });
  662. await fetchChatList(chatStore.chatMode);
  663. } else {
  664. await api.put(`/bigmodel/api/dialog/update`, {
  665. id: values.dialogId,
  666. dialogName: values.dialogName
  667. });
  668. await fetchChatList();
  669. }
  670. } else {
  671. await api.put(`/bigmodel/api/dialog/update`, {
  672. id: values.dialogId,
  673. dialogName: values.dialogName
  674. });
  675. await fetchChatList();
  676. }
  677. chatStore.updateCurrentSession((value) => {
  678. value.topic = values.dialogName;
  679. });
  680. } catch (error) {
  681. console.error(error);
  682. }
  683. }).catch((error) => {
  684. console.error(error);
  685. });
  686. }}
  687. onCancel={() => {
  688. setModalOpen(false);
  689. }}
  690. >
  691. <Form form={form} layout='inline'>
  692. <FormItem name='dialogId' noStyle />
  693. <FormItem
  694. label='名称'
  695. name='dialogName'
  696. rules={[{ required: true, message: '名称不能为空', whitespace: true }]}
  697. >
  698. <Input
  699. style={{ width: 300 }}
  700. placeholder='请输入'
  701. maxLength={20}
  702. />
  703. </FormItem>
  704. </Form>
  705. </Modal>
  706. </SideBarContainer>
  707. }
  708. {
  709. drawerOpen &&
  710. <AppDrawer
  711. isMobileScreen={isMobileScreen}
  712. selectedAppId={globalStore.selectedAppId}
  713. type={drawerType}
  714. open={drawerOpen}
  715. onClose={() => {
  716. setDrawerOpen(false);
  717. }}
  718. />
  719. }
  720. </>
  721. );
  722. }