|
@@ -1,16 +1,25 @@
|
|
|
import * as React from 'react';
|
|
import * as React from 'react';
|
|
|
import { observer } from 'mobx-react';
|
|
import { observer } from 'mobx-react';
|
|
|
|
|
+import { Button, Table, TableColumnsType, Modal, TablePaginationConfig } from 'antd';
|
|
|
|
|
+import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
|
|
|
|
+import router from '@/router';
|
|
|
|
|
+import dayjs from 'dayjs';
|
|
|
import store from './store';
|
|
import store from './store';
|
|
|
|
|
+import { Record } from './types';
|
|
|
import './style.less';
|
|
import './style.less';
|
|
|
|
|
|
|
|
const KnowledgeLibList: React.FC = () => {
|
|
const KnowledgeLibList: React.FC = () => {
|
|
|
const {
|
|
const {
|
|
|
state,
|
|
state,
|
|
|
|
|
+ onChangePagination,
|
|
|
|
|
+ onClickDelete,
|
|
|
init,
|
|
init,
|
|
|
reset
|
|
reset
|
|
|
} = store;
|
|
} = store;
|
|
|
const {
|
|
const {
|
|
|
- pageLoading
|
|
|
|
|
|
|
+ listLoading,
|
|
|
|
|
+ list,
|
|
|
|
|
+ page
|
|
|
} = state;
|
|
} = state;
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
React.useEffect(() => {
|
|
@@ -18,9 +27,143 @@ const KnowledgeLibList: React.FC = () => {
|
|
|
return () => reset();
|
|
return () => reset();
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
+ const columns: TableColumnsType<Record> = [
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '序号',
|
|
|
|
|
+ dataIndex: 'index',
|
|
|
|
|
+ width: 80,
|
|
|
|
|
+ render: (text, record, index) => {
|
|
|
|
|
+ return index + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: 'ID',
|
|
|
|
|
+ dataIndex: 'id',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '知识库名称',
|
|
|
|
|
+ dataIndex: 'name',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '使用空间',
|
|
|
|
|
+ dataIndex: 'length',
|
|
|
|
|
+ render: (text) => {
|
|
|
|
|
+ const size = (text / 1024).toFixed(2);
|
|
|
|
|
+ return `${size}M`;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '字符数量',
|
|
|
|
|
+ dataIndex: 'word_num',
|
|
|
|
|
+ render: (text) => {
|
|
|
|
|
+ return `${text}字`;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '文件数量',
|
|
|
|
|
+ dataIndex: 'document_size',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '创建时间',
|
|
|
|
|
+ dataIndex: 'createTime',
|
|
|
|
|
+ width: 200,
|
|
|
|
|
+ render: (text) => {
|
|
|
|
|
+ if (text) {
|
|
|
|
|
+ return dayjs(text).format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return '--';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '更新时间',
|
|
|
|
|
+ dataIndex: 'updateTime',
|
|
|
|
|
+ width: 200,
|
|
|
|
|
+ render: (text) => {
|
|
|
|
|
+ if (text) {
|
|
|
|
|
+ return dayjs(text).format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return '--';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '操作',
|
|
|
|
|
+ dataIndex: 'operation',
|
|
|
|
|
+ width: 100,
|
|
|
|
|
+ fixed: 'right',
|
|
|
|
|
+ render: (text, record) => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <>
|
|
|
|
|
+ <a
|
|
|
|
|
+ style={{ marginRight: 16 }}
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ router.navigate({ pathname: '/knowledgeLib/modify' }, { state: { knowledgeId: record.id } });
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <EditOutlined />
|
|
|
|
|
+ </a >
|
|
|
|
|
+ <a
|
|
|
|
|
+ className='text-error'
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ Modal.confirm({
|
|
|
|
|
+ title: '删除',
|
|
|
|
|
+ content: `确定删除知识库名称${record.name}吗?`,
|
|
|
|
|
+ okType: 'danger',
|
|
|
|
|
+ onOk: async () => {
|
|
|
|
|
+ await onClickDelete(record.id);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <DeleteOutlined />
|
|
|
|
|
+ </a>
|
|
|
|
|
+ </>
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ const paginationConfig: TablePaginationConfig = {
|
|
|
|
|
+ // 显示数据总量
|
|
|
|
|
+ showTotal: (total: number) => {
|
|
|
|
|
+ return `共 ${total} 条`;
|
|
|
|
|
+ },
|
|
|
|
|
+ // 展示分页条数切换
|
|
|
|
|
+ showSizeChanger: true,
|
|
|
|
|
+ // 指定每页显示条数
|
|
|
|
|
+ pageSizeOptions: ['10', '20', '50', '100'],
|
|
|
|
|
+ // 快速跳转至某页
|
|
|
|
|
+ showQuickJumper: true,
|
|
|
|
|
+ current: page.pageNumber,
|
|
|
|
|
+ pageSize: page.pageSize,
|
|
|
|
|
+ total: page.total,
|
|
|
|
|
+ onChange: async (page, pageSize) => {
|
|
|
|
|
+ await onChangePagination(page, pageSize);
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className='knowledgeLibList'>
|
|
<div className='knowledgeLibList'>
|
|
|
- 知识库列表
|
|
|
|
|
|
|
+ <div className='knowledgeLibList-operation'>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type='primary'
|
|
|
|
|
+ icon={<PlusOutlined />}
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ router.navigate({ pathname: '/knowledgeLib/create' });
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ 创建知识库
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <Table
|
|
|
|
|
+ scroll={{ x: 'max-content' }}
|
|
|
|
|
+ rowKey={(record) => record.id}
|
|
|
|
|
+ loading={listLoading}
|
|
|
|
|
+ columns={columns}
|
|
|
|
|
+ dataSource={list}
|
|
|
|
|
+ pagination={paginationConfig}
|
|
|
|
|
+ />
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|