sidebar.tsx 24 KB

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