import IconFont from '@/components/icon-font'; import breakpoints from '@/config/breakpoints'; import HotKeys from '@/config/hotkeys'; import useWindowResize from '@/hooks/use-window-resize'; import { DiffOutlined, HighlightOutlined } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-components'; import { useIntl } from '@umijs/max'; import { Button, Segmented, Space, Tabs, TabsProps } from 'antd'; import classNames from 'classnames'; import _ from 'lodash'; import { useCallback, useEffect, useRef, useState } from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; import { queryModelsList } from './apis'; import GroundImages from './components/ground-images'; import ImageEdit from './components/image-edit'; import './style/play-ground.less'; const TabsValueMap = { Tab1: 'generate', Tab2: 'edit' }; const TextToImages: React.FC = () => { const intl = useIntl(); const { size } = useWindowResize(); const [activeKey, setActiveKey] = useState(TabsValueMap.Tab1); const groundTabRef1 = useRef(null); const groundTabRef2 = useRef(null); const [modelList, setModelList] = useState[]>([]); const [loaded, setLoaded] = useState(false); const optionsList = [ { label: 'Generate', value: TabsValueMap.Tab1, icon: }, { label: 'Edit', value: TabsValueMap.Tab2, icon: } ]; const handleViewCode = useCallback(() => { if (activeKey === TabsValueMap.Tab1) { groundTabRef1.current?.viewCode?.(); } else if (activeKey === TabsValueMap.Tab2) { groundTabRef2.current?.viewCode?.(); } }, [activeKey]); const handleToggleCollapse = useCallback(() => { if (activeKey === TabsValueMap.Tab1) { groundTabRef1.current?.setCollapse?.(); return; } groundTabRef2.current?.setCollapse?.(); }, [activeKey]); const items: TabsProps['items'] = [ { key: TabsValueMap.Tab1, label: 'Generate', children: ( ) }, { key: TabsValueMap.Tab2, label: 'Edit', children: } ]; useEffect(() => { if (size.width < breakpoints.lg) { if (!groundTabRef1.current?.collapse) { groundTabRef1.current?.setCollapse?.(); } } }, [size.width]); useEffect(() => { const getModelList = async () => { try { const params = { categories: 'image', with_meta: true }; const res = await queryModelsList(params); const list = _.map(res.data || [], (item: any) => { return { value: item.id, label: item.id, meta: item.meta }; }) as Global.BaseOption[]; return list; } catch (error) { console.error(error); return []; } }; const fetchData = async () => { try { const modelist = await getModelList(); setModelList(modelist); } catch (error) { setLoaded(true); } }; fetchData(); }, []); const renderExtra = () => { return ( ); }; useHotkeys( HotKeys.RIGHT.join(','), () => { groundTabRef1.current?.setCollapse?.(); }, { preventDefault: true } ); return ( {intl.formatMessage({ id: 'menu.playground.text2images' })} { setActiveKey(key)} > } ), breadcrumb: {} }} extra={renderExtra()} className={classNames('playground-container chat')} >
); }; export default TextToImages;