2024-01-29 19:28:39 +08:00
|
|
|
import { formatDate } from '@/utils/date';
|
|
|
|
|
import {
|
|
|
|
|
DeleteOutlined,
|
|
|
|
|
MinusSquareOutlined,
|
|
|
|
|
PlusOutlined,
|
|
|
|
|
} from '@ant-design/icons';
|
|
|
|
|
import { Card, Col, FloatButton, Popconfirm, Row } from 'antd';
|
2024-01-30 19:26:29 +08:00
|
|
|
import { useCallback, useEffect } from 'react';
|
|
|
|
|
import { useDispatch, useNavigate, useSelector } from 'umi';
|
2024-01-29 19:28:39 +08:00
|
|
|
import styles from './index.less';
|
2024-01-30 19:26:29 +08:00
|
|
|
|
|
|
|
|
const Knowledge = () => {
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const knowledgeModel = useSelector((state: any) => state.knowledgeModel);
|
2024-01-29 19:28:39 +08:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const { data = [] } = knowledgeModel;
|
|
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
const fetchList = useCallback(() => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: 'knowledgeModel/getList',
|
|
|
|
|
payload: {},
|
|
|
|
|
});
|
|
|
|
|
}, []);
|
2024-01-29 19:28:39 +08:00
|
|
|
|
2024-01-18 18:27:38 +08:00
|
|
|
const confirm = (id: string) => {
|
2024-01-17 09:37:01 +08:00
|
|
|
dispatch({
|
|
|
|
|
type: 'knowledgeModel/rmKb',
|
|
|
|
|
payload: {
|
2024-01-29 19:28:39 +08:00
|
|
|
kb_id: id,
|
2024-01-17 09:37:01 +08:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
const handleAddKnowledge = () => {
|
|
|
|
|
navigate(`add/setting?activeKey=setting`);
|
2024-01-29 19:28:39 +08:00
|
|
|
};
|
2024-01-17 09:37:01 +08:00
|
|
|
const handleEditKnowledge = (id: string) => {
|
|
|
|
|
navigate(`add/setting?activeKey=file&id=${id}`);
|
2024-01-29 19:28:39 +08:00
|
|
|
};
|
2024-01-17 09:37:01 +08:00
|
|
|
useEffect(() => {
|
2024-01-30 19:26:29 +08:00
|
|
|
fetchList();
|
|
|
|
|
}, [fetchList]);
|
2024-01-29 19:28:39 +08:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className={styles.knowledge}>
|
|
|
|
|
<FloatButton
|
|
|
|
|
onClick={handleAddKnowledge}
|
|
|
|
|
icon={<PlusOutlined />}
|
|
|
|
|
type="primary"
|
|
|
|
|
style={{ right: 24, top: 100 }}
|
|
|
|
|
/>
|
|
|
|
|
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }}>
|
|
|
|
|
{data.map((item: any) => {
|
|
|
|
|
return (
|
|
|
|
|
<Col
|
|
|
|
|
className="gutter-row"
|
|
|
|
|
key={item.name}
|
|
|
|
|
xs={24}
|
|
|
|
|
sm={12}
|
|
|
|
|
md={8}
|
|
|
|
|
lg={6}
|
2024-01-17 09:37:01 +08:00
|
|
|
>
|
2024-01-29 19:28:39 +08:00
|
|
|
<Card
|
|
|
|
|
className={styles.card}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
handleEditKnowledge(item.id);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className={styles.container}>
|
|
|
|
|
<div className={styles.content}>
|
|
|
|
|
<span className={styles.context}>{item.name}</span>
|
|
|
|
|
<span className={styles.delete}>
|
|
|
|
|
<Popconfirm
|
|
|
|
|
title="Delete the task"
|
|
|
|
|
description="Are you sure to delete this task?"
|
|
|
|
|
onConfirm={(e: any) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
|
confirm(item.id);
|
|
|
|
|
}}
|
|
|
|
|
okText="Yes"
|
|
|
|
|
cancelText="No"
|
|
|
|
|
>
|
|
|
|
|
<DeleteOutlined
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.footer}>
|
|
|
|
|
<span className={styles.text}>
|
|
|
|
|
<MinusSquareOutlined />
|
|
|
|
|
{item.doc_num}文档
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.text}>
|
|
|
|
|
<MinusSquareOutlined />
|
|
|
|
|
{item.chunk_num}个
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.text}>
|
|
|
|
|
<MinusSquareOutlined />
|
|
|
|
|
{item.token_num}千字符
|
|
|
|
|
</span>
|
|
|
|
|
<span style={{ float: 'right' }}>
|
|
|
|
|
{formatDate(item.update_date)}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2024-01-17 09:37:01 +08:00
|
|
|
</div>
|
2024-01-29 19:28:39 +08:00
|
|
|
</Card>
|
|
|
|
|
</Col>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Row>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2024-01-17 09:37:01 +08:00
|
|
|
};
|
|
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
export default Knowledge;
|