import * as React from 'react'; import { observer } from 'mobx-react'; import { List, Button, Card, Space, Typography, Divider, Flex, Layout, Empty, Image, Modal } from 'antd'; import { PlusOutlined, FileOutlined, SettingOutlined, DeleteOutlined } from '@ant-design/icons'; import { apis } from '@/apis'; import './style.less'; import IconSvg from '@/assets/public/icon.svg'; import { PaginationConfig } from 'antd/es/pagination'; import router from '@/router'; const { Header, Footer, Sider, Content } = Layout; const headerStyle : React.CSSProperties = { textAlign: 'center', height: 24, paddingInline: 48, lineHeight: '30px', backgroundColor: '#fff', }; const contentStyle : React.CSSProperties = { textAlign: 'center', lineHeight: '40px', backgroundColor: '#fff', }; const siderStyle : React.CSSProperties = { paddingLeft: 30, paddingTop: 30, height: 80, backgroundColor: '#fff', }; const footerStyle : React.CSSProperties = { textAlign: 'center', color: '#fff', height: 24, backgroundColor: '#4096ff', }; const layoutStyle = { borderRadius: 8, overflow: 'hidden', width: 'calc(10% - 8px)', maxWidth: 'calc(20% - 8px)', }; const QuestionAnswerList : React.FC = () => { interface Item { name : string, desc : string, appId : number, createBy : string, }; interface PageInfo { pageNumber : number, pageSize : number, total : number, }; const [ listLoading, setListLoading ] = React.useState( false ); const [ list, setList ] = React.useState( [] ); const [ page, setPage ] = React.useState( { pageNumber: 1, pageSize: 10, total: 0, } ); const [ appCount, setAppCount ] = React.useState(); const [ knowCount, setKnowCount ] = React.useState(); const { Header, Footer, Sider, Content } = Layout; const appApi = { fetchList: async () => { setListLoading( true ); try { const res = await apis.fetchAppList( { pageSize: page.pageSize, pageNumber: page.pageNumber } ) setList( res.data.list ); setPage( { pageNumber: page.pageNumber, pageSize: page.pageSize, total: res.data.total, } ); console.log( page, 'res.data.total' ); } catch ( error ) { console.error( error ); } finally { setListLoading( false ); } } }; // 删除应用 const delApplication = async ( appId : string ) => { try { await apis.deleteApplicationApi( appId ); await appApi.fetchList(); } catch ( error ) { console.error( error ); } } const indexApi = { fetchIndex: async () => { try { const res = await apis.fetchIndexCount( { pageSize: page.pageSize, pageNumber: page.pageNumber } ) setAppCount( res.data.applicationCount ); setKnowCount( res.data.knowledgeCount ); // setPage({ // pageNumber: page.pageNumber, // pageSize: page.pageSize, // total: res.data.total, // }); } catch ( error ) { console.error( error ); } finally { setListLoading( false ); } } } const init = async () => { await appApi.fetchList(); await indexApi.fetchIndex(); } React.useEffect( () => { init(); }, [ page.pageSize, page.pageNumber ] ) const paginationConfig : PaginationConfig = { // 显示数据总量 showTotal: ( total : number ) => { return `共 ${ total } 条`; }, // 展示分页条数切换 showSizeChanger: true, // 指定每页显示条数 // pageSizeOptions: ['2', '20', '50', '100'], // 快速跳转至某页 showQuickJumper: true, current: page.pageNumber, pageSize: page.pageSize, total: page.total, onChange: ( pageNumber, pageSize ) => { setPage( { pageNumber: pageNumber, pageSize: pageSize, total: page.total, } ); }, }; return (
{ list.length ?
{/*
*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/* */} {/*
问答应用总数
*/} {/* { appCount }个*/} {/*
*/} {/*
*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/*
知识库总数
*/} {/* { knowCount } 个*/} {/*
*/} {/*
*/} {/*
*/} {/*
*/}
所有问答应用
(
{/*
*/ } {/* { item.name }*/ } {/*
*/ }
{ item.name }
ID:{ item.appId } {/*创建者 { item.createBy }*/ }
{ item.desc !== '' && item.desc.length > 40 ? item.desc.substring( 0, 40 ) + '...' : item.desc }
) } pagination={ paginationConfig } // 分页 />
: }
) }; export default observer( QuestionAnswerList );