2024-02-02 09:35:21 +08:00
|
|
|
import { KnowledgeRouteKey } from '@/constants/knowledge';
|
2024-01-30 19:26:29 +08:00
|
|
|
import { getOneNamespaceEffectsLoading } from '@/utils/stroreUtil';
|
|
|
|
|
import { DownOutlined } from '@ant-design/icons';
|
2024-01-17 09:37:01 +08:00
|
|
|
import type { MenuProps } from 'antd';
|
2024-01-30 19:26:29 +08:00
|
|
|
import { Button, Dropdown, Input, Space, Switch, Table } from 'antd';
|
2024-01-17 09:37:01 +08:00
|
|
|
import type { ColumnsType } from 'antd/es/table';
|
2024-01-30 19:26:29 +08:00
|
|
|
import { debounce } from 'lodash';
|
|
|
|
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
|
|
import { useDispatch, useNavigate, useSelector } from 'umi';
|
|
|
|
|
import CreateEPModal from './createEFileModal';
|
|
|
|
|
import styles from './index.less';
|
|
|
|
|
import SegmentSetModal from './segmentSetModal';
|
|
|
|
|
import UploadFile from './upload';
|
2024-01-17 09:37:01 +08:00
|
|
|
|
|
|
|
|
interface DataType {
|
2024-01-30 19:26:29 +08:00
|
|
|
name: string;
|
|
|
|
|
chunk_num: string;
|
|
|
|
|
token_num: number;
|
|
|
|
|
update_date: string;
|
|
|
|
|
size: string;
|
|
|
|
|
status: string;
|
|
|
|
|
id: string;
|
|
|
|
|
parser_id: string;
|
2024-01-17 09:37:01 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
interface KFProps {
|
|
|
|
|
kb_id: string;
|
2024-01-18 18:27:38 +08:00
|
|
|
}
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
const KnowledgeFile: React.FC<KFProps> = ({ kb_id }) => {
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const kFModel = useSelector((state: any) => state.kFModel);
|
|
|
|
|
const effects = useSelector((state: any) => state.loading.effects);
|
|
|
|
|
const { data } = kFModel;
|
|
|
|
|
const loading = getOneNamespaceEffectsLoading('kFModel', effects, [
|
|
|
|
|
'getKfList',
|
|
|
|
|
'updateDocumentStatus',
|
|
|
|
|
]);
|
|
|
|
|
const [inputValue, setInputValue] = useState('');
|
|
|
|
|
const [doc_id, setDocId] = useState('0');
|
|
|
|
|
const [parser_id, setParserId] = useState('0');
|
|
|
|
|
let navigate = useNavigate();
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
const getKfList = (keywords?: string) => {
|
|
|
|
|
const payload = {
|
|
|
|
|
kb_id,
|
|
|
|
|
keywords,
|
|
|
|
|
};
|
|
|
|
|
if (!keywords) {
|
|
|
|
|
delete payload.keywords;
|
2024-01-17 09:37:01 +08:00
|
|
|
}
|
2024-01-30 19:26:29 +08:00
|
|
|
dispatch({
|
|
|
|
|
type: 'kFModel/getKfList',
|
|
|
|
|
payload,
|
|
|
|
|
});
|
|
|
|
|
};
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (kb_id) {
|
|
|
|
|
getKfList();
|
2024-01-17 09:37:01 +08:00
|
|
|
}
|
2024-01-30 19:26:29 +08:00
|
|
|
}, [kb_id]);
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
const debounceChange = debounce(getKfList, 300);
|
|
|
|
|
const debounceCallback = useCallback(
|
|
|
|
|
(value: string) => debounceChange(value),
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
const handleInputChange = (
|
|
|
|
|
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
|
|
|
|
|
) => {
|
|
|
|
|
const value = e.target.value;
|
|
|
|
|
setInputValue(value);
|
|
|
|
|
debounceCallback(e.target.value);
|
|
|
|
|
};
|
|
|
|
|
const onChangeStatus = (e: boolean, doc_id: string) => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: 'kFModel/updateDocumentStatus',
|
|
|
|
|
payload: {
|
|
|
|
|
doc_id,
|
|
|
|
|
status: Number(e),
|
|
|
|
|
kb_id,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
const onRmDocument = () => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: 'kFModel/document_rm',
|
|
|
|
|
payload: {
|
|
|
|
|
doc_id,
|
|
|
|
|
kb_id,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
const showCEFModal = () => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: 'kFModel/updateState',
|
|
|
|
|
payload: {
|
|
|
|
|
isShowCEFwModal: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
const showSegmentSetModal = () => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: 'kFModel/updateState',
|
|
|
|
|
payload: {
|
|
|
|
|
isShowSegmentSetModal: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
const actionItems: MenuProps['items'] = useMemo(() => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
key: '1',
|
|
|
|
|
label: (
|
|
|
|
|
<div>
|
|
|
|
|
<UploadFile kb_id={kb_id} getKfList={getKfList} />
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: '2',
|
|
|
|
|
label: (
|
|
|
|
|
<div>
|
|
|
|
|
<Button type="link" onClick={showCEFModal}>
|
|
|
|
|
{' '}
|
|
|
|
|
导入虚拟文件
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
// disabled: true,
|
|
|
|
|
},
|
2024-01-17 09:37:01 +08:00
|
|
|
];
|
2024-01-30 19:26:29 +08:00
|
|
|
}, [kb_id]);
|
|
|
|
|
const chunkItems: MenuProps['items'] = [
|
|
|
|
|
{
|
|
|
|
|
key: '1',
|
|
|
|
|
label: (
|
|
|
|
|
<div>
|
|
|
|
|
<Button type="link" onClick={showSegmentSetModal}>
|
|
|
|
|
{' '}
|
|
|
|
|
分段设置
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: '2',
|
|
|
|
|
label: (
|
|
|
|
|
<div>
|
|
|
|
|
<Button type="link" onClick={onRmDocument}>
|
|
|
|
|
{' '}
|
|
|
|
|
删除
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
// disabled: true,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
const toChunk = (id: string) => {
|
2024-02-02 09:35:21 +08:00
|
|
|
navigate(
|
|
|
|
|
`/knowledge/${KnowledgeRouteKey.Dataset}?id=${kb_id}&doc_id=${id}`,
|
|
|
|
|
);
|
2024-01-30 19:26:29 +08:00
|
|
|
};
|
|
|
|
|
const columns: ColumnsType<DataType> = [
|
|
|
|
|
{
|
|
|
|
|
title: '名称',
|
|
|
|
|
dataIndex: 'name',
|
|
|
|
|
key: 'name',
|
|
|
|
|
render: (text: any, { id }) => (
|
|
|
|
|
<div className={styles.tochunks} onClick={() => toChunk(id)}>
|
|
|
|
|
<img
|
|
|
|
|
className={styles.img}
|
|
|
|
|
src="https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg"
|
|
|
|
|
alt=""
|
|
|
|
|
/>
|
|
|
|
|
{text}
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
className: `${styles.column}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '数据总量',
|
|
|
|
|
dataIndex: 'chunk_num',
|
|
|
|
|
key: 'chunk_num',
|
|
|
|
|
className: `${styles.column}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Tokens',
|
|
|
|
|
dataIndex: 'token_num',
|
|
|
|
|
key: 'token_num',
|
|
|
|
|
className: `${styles.column}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '文件大小',
|
|
|
|
|
dataIndex: 'size',
|
|
|
|
|
key: 'size',
|
|
|
|
|
className: `${styles.column}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '状态',
|
|
|
|
|
key: 'status',
|
|
|
|
|
dataIndex: 'status',
|
|
|
|
|
className: `${styles.column}`,
|
|
|
|
|
render: (_, { status: string, id }) => (
|
|
|
|
|
<>
|
|
|
|
|
<Switch
|
|
|
|
|
defaultChecked={status === '1'}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
onChangeStatus(e, id);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Action',
|
|
|
|
|
key: 'action',
|
|
|
|
|
className: `${styles.column}`,
|
|
|
|
|
render: (_, record) => (
|
|
|
|
|
<Space size="middle">
|
|
|
|
|
<Dropdown menu={{ items: chunkItems }} trigger={['click']}>
|
|
|
|
|
<a
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setDocId(record.id);
|
|
|
|
|
setParserId(record.parser_id);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
分段设置 <DownOutlined />
|
|
|
|
|
</a>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</Space>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className={styles.filter}>
|
|
|
|
|
<div className="search">
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="搜索"
|
|
|
|
|
value={inputValue}
|
|
|
|
|
style={{ width: 220 }}
|
|
|
|
|
allowClear
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="operate">
|
|
|
|
|
<Dropdown menu={{ items: actionItems }} trigger={['click']}>
|
|
|
|
|
<a>
|
|
|
|
|
导入文件 <DownOutlined />
|
|
|
|
|
</a>
|
|
|
|
|
</Dropdown>
|
2024-01-17 09:37:01 +08:00
|
|
|
</div>
|
2024-01-30 19:26:29 +08:00
|
|
|
</div>
|
|
|
|
|
<Table
|
|
|
|
|
rowKey="id"
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={data}
|
|
|
|
|
loading={loading}
|
|
|
|
|
pagination={false}
|
|
|
|
|
scroll={{ scrollToFirstRowOnChange: true, x: true }}
|
|
|
|
|
/>
|
|
|
|
|
<CreateEPModal getKfList={getKfList} kb_id={kb_id} />
|
|
|
|
|
<SegmentSetModal
|
|
|
|
|
getKfList={getKfList}
|
|
|
|
|
parser_id={parser_id}
|
|
|
|
|
doc_id={doc_id}
|
|
|
|
|
/>
|
2024-01-17 09:37:01 +08:00
|
|
|
</>
|
2024-01-30 19:26:29 +08:00
|
|
|
);
|
2024-01-17 09:37:01 +08:00
|
|
|
};
|
|
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
export default KnowledgeFile;
|