2024-01-30 19:26:29 +08:00
|
|
|
import { api_host } from '@/utils/api';
|
|
|
|
import { getOneNamespaceEffectsLoading } from '@/utils/stroreUtil';
|
|
|
|
import { DeleteOutlined, MinusSquareOutlined } from '@ant-design/icons';
|
2024-01-18 18:27:38 +08:00
|
|
|
import type { PaginationProps } from 'antd';
|
2024-01-30 19:26:29 +08:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Card,
|
|
|
|
Col,
|
|
|
|
Input,
|
|
|
|
Pagination,
|
|
|
|
Popconfirm,
|
|
|
|
Row,
|
|
|
|
Select,
|
|
|
|
Spin,
|
|
|
|
Switch,
|
|
|
|
} from 'antd';
|
2024-02-02 18:49:54 +08:00
|
|
|
import { debounce } from 'lodash';
|
2024-01-30 19:26:29 +08:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
2024-02-02 18:49:54 +08:00
|
|
|
import { useDispatch, useSearchParams, useSelector } from 'umi';
|
2024-01-30 19:26:29 +08:00
|
|
|
import CreateModal from './components/createModal';
|
2024-01-18 18:27:38 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
import styles from './index.less';
|
|
|
|
|
|
|
|
interface PayloadType {
|
|
|
|
doc_id: string;
|
|
|
|
keywords?: string;
|
|
|
|
available_int?: number;
|
|
|
|
}
|
|
|
|
|
2024-02-02 18:49:54 +08:00
|
|
|
const Chunk = () => {
|
2024-01-30 19:26:29 +08:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
const chunkModel = useSelector((state: any) => state.chunkModel);
|
|
|
|
const [keywords, SetKeywords] = useState('');
|
|
|
|
const [available_int, setAvailableInt] = useState(-1);
|
2024-02-02 18:49:54 +08:00
|
|
|
const [searchParams] = useSearchParams();
|
2024-01-30 19:26:29 +08:00
|
|
|
const [pagination, setPagination] = useState({ page: 1, size: 30 });
|
|
|
|
const { data = [], total, chunk_id, isShowCreateModal } = chunkModel;
|
|
|
|
const effects = useSelector((state: any) => state.loading.effects);
|
|
|
|
const loading = getOneNamespaceEffectsLoading('chunkModel', effects, [
|
|
|
|
'create_hunk',
|
|
|
|
'chunk_list',
|
|
|
|
'switch_chunk',
|
|
|
|
]);
|
2024-02-02 18:49:54 +08:00
|
|
|
const documentId: string = searchParams.get('doc_id') || '';
|
2024-01-30 19:26:29 +08:00
|
|
|
|
2024-01-18 18:27:38 +08:00
|
|
|
const getChunkList = (value?: string) => {
|
2024-01-30 19:26:29 +08:00
|
|
|
const payload: PayloadType = {
|
2024-02-02 18:49:54 +08:00
|
|
|
doc_id: documentId,
|
2024-01-18 18:27:38 +08:00
|
|
|
keywords: value || keywords,
|
2024-01-30 19:26:29 +08:00
|
|
|
available_int,
|
|
|
|
};
|
2024-01-18 18:27:38 +08:00
|
|
|
if (payload.available_int === -1) {
|
2024-01-30 19:26:29 +08:00
|
|
|
delete payload.available_int;
|
2024-01-18 18:27:38 +08:00
|
|
|
}
|
|
|
|
dispatch({
|
|
|
|
type: 'chunkModel/chunk_list',
|
|
|
|
payload: {
|
|
|
|
...payload,
|
2024-01-30 19:26:29 +08:00
|
|
|
...pagination,
|
|
|
|
},
|
2024-01-18 18:27:38 +08:00
|
|
|
});
|
2024-01-30 19:26:29 +08:00
|
|
|
};
|
|
|
|
const confirm = async (id: string) => {
|
|
|
|
const retcode = await dispatch<any>({
|
2024-01-18 18:27:38 +08:00
|
|
|
type: 'chunkModel/rm_chunk',
|
|
|
|
payload: {
|
2024-01-30 19:26:29 +08:00
|
|
|
chunk_ids: [id],
|
2024-01-18 18:27:38 +08:00
|
|
|
},
|
|
|
|
});
|
2024-01-30 19:26:29 +08:00
|
|
|
|
|
|
|
retcode === 0 && getChunkList();
|
2024-01-18 18:27:38 +08:00
|
|
|
};
|
2024-01-30 19:26:29 +08:00
|
|
|
|
2024-01-18 18:27:38 +08:00
|
|
|
const handleEditchunk = (chunk_id?: string) => {
|
|
|
|
dispatch({
|
|
|
|
type: 'chunkModel/updateState',
|
|
|
|
payload: {
|
|
|
|
isShowCreateModal: true,
|
2024-01-19 18:35:24 +08:00
|
|
|
chunk_id,
|
2024-02-02 18:49:54 +08:00
|
|
|
doc_id: documentId,
|
2024-01-18 18:27:38 +08:00
|
|
|
},
|
|
|
|
});
|
2024-01-30 19:26:29 +08:00
|
|
|
getChunkList();
|
2024-01-18 18:27:38 +08:00
|
|
|
};
|
2024-01-30 19:26:29 +08:00
|
|
|
|
|
|
|
const onShowSizeChange: PaginationProps['onShowSizeChange'] = (
|
|
|
|
page,
|
|
|
|
size,
|
|
|
|
) => {
|
|
|
|
setPagination({ page, size });
|
|
|
|
};
|
|
|
|
|
|
|
|
const switchChunk = async (id: string, available_int: boolean) => {
|
|
|
|
const retcode = await dispatch<any>({
|
2024-01-18 18:27:38 +08:00
|
|
|
type: 'chunkModel/switch_chunk',
|
|
|
|
payload: {
|
|
|
|
chunk_ids: [id],
|
|
|
|
available_int: Number(available_int),
|
2024-02-02 18:49:54 +08:00
|
|
|
doc_id: documentId,
|
2024-01-18 18:27:38 +08:00
|
|
|
},
|
|
|
|
});
|
2024-01-30 19:26:29 +08:00
|
|
|
|
|
|
|
retcode === 0 && getChunkList();
|
|
|
|
};
|
2024-01-18 18:27:38 +08:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-01-30 19:26:29 +08:00
|
|
|
getChunkList();
|
2024-02-02 18:49:54 +08:00
|
|
|
}, [documentId, available_int, pagination]);
|
2024-01-30 19:26:29 +08:00
|
|
|
|
|
|
|
const debounceChange = debounce(getChunkList, 300);
|
|
|
|
const debounceCallback = useCallback(
|
|
|
|
(value: string) => debounceChange(value),
|
|
|
|
[],
|
|
|
|
);
|
2024-01-18 18:27:38 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
const handleInputChange = (
|
|
|
|
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
|
|
|
|
) => {
|
|
|
|
const value = e.target.value;
|
|
|
|
SetKeywords(value);
|
|
|
|
debounceCallback(value);
|
|
|
|
};
|
|
|
|
const handleSelectChange = (value: number) => {
|
|
|
|
setAvailableInt(value);
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className={styles.chunkPage}>
|
|
|
|
<div className={styles.filter}>
|
|
|
|
<div>
|
|
|
|
<Input
|
|
|
|
placeholder="搜索"
|
|
|
|
style={{ width: 220 }}
|
|
|
|
value={keywords}
|
|
|
|
allowClear
|
|
|
|
onChange={handleInputChange}
|
|
|
|
/>
|
|
|
|
<Select
|
|
|
|
showSearch
|
|
|
|
placeholder="是否启用"
|
|
|
|
optionFilterProp="children"
|
|
|
|
value={available_int}
|
|
|
|
onChange={handleSelectChange}
|
|
|
|
style={{ width: 220 }}
|
|
|
|
options={[
|
|
|
|
{
|
|
|
|
value: -1,
|
|
|
|
label: '全部',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 1,
|
|
|
|
label: '启用',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 0,
|
|
|
|
label: '未启用',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
handleEditchunk();
|
|
|
|
}}
|
|
|
|
type="link"
|
|
|
|
>
|
|
|
|
添加分段
|
|
|
|
</Button>
|
2024-01-18 18:27:38 +08:00
|
|
|
</div>
|
2024-01-30 19:26:29 +08:00
|
|
|
<div className={styles.pageContent}>
|
|
|
|
<Spin spinning={loading} className={styles.spin} size="large">
|
|
|
|
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 24 }}>
|
|
|
|
{data.map((item: any) => {
|
|
|
|
return (
|
|
|
|
<Col
|
|
|
|
className="gutter-row"
|
|
|
|
key={item.chunk_id}
|
|
|
|
xs={24}
|
|
|
|
sm={12}
|
|
|
|
md={12}
|
|
|
|
lg={8}
|
2024-01-18 18:27:38 +08:00
|
|
|
>
|
2024-01-30 19:26:29 +08:00
|
|
|
<Card
|
|
|
|
className={styles.card}
|
|
|
|
onClick={() => {
|
|
|
|
handleEditchunk(item.chunk_id);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
style={{ width: '50px' }}
|
|
|
|
src={`${api_host}/document/image/${item.img_id}`}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
<div className={styles.container}>
|
|
|
|
<div className={styles.content}>
|
|
|
|
<span className={styles.context}>
|
|
|
|
{item.content_ltks}
|
|
|
|
</span>
|
|
|
|
<span className={styles.delete}>
|
|
|
|
<Switch
|
|
|
|
size="small"
|
|
|
|
defaultValue={item.available_int == '1'}
|
|
|
|
onChange={(checked: boolean, e: any) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
switchChunk(item.chunk_id, checked);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</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' }}>
|
|
|
|
<Popconfirm
|
|
|
|
title="Delete the task"
|
|
|
|
description="Are you sure to delete this task?"
|
|
|
|
onConfirm={(e: any) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
console.log(confirm);
|
|
|
|
confirm(item.chunk_id);
|
|
|
|
}}
|
|
|
|
okText="Yes"
|
|
|
|
cancelText="No"
|
|
|
|
>
|
|
|
|
<DeleteOutlined
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Popconfirm>
|
|
|
|
</span>
|
|
|
|
</div>
|
2024-01-18 18:27:38 +08:00
|
|
|
</div>
|
2024-01-30 19:26:29 +08:00
|
|
|
</Card>
|
|
|
|
</Col>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Row>
|
|
|
|
</Spin>
|
|
|
|
</div>
|
|
|
|
<div className={styles.pageFooter}>
|
|
|
|
<Pagination
|
|
|
|
responsive
|
|
|
|
showLessItems
|
|
|
|
showQuickJumper
|
|
|
|
showSizeChanger
|
|
|
|
onChange={onShowSizeChange}
|
|
|
|
defaultPageSize={30}
|
|
|
|
pageSizeOptions={[30, 60, 90]}
|
|
|
|
defaultCurrent={pagination.page}
|
|
|
|
total={total}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-01-18 18:27:38 +08:00
|
|
|
</div>
|
2024-01-30 19:26:29 +08:00
|
|
|
<CreateModal
|
2024-02-02 18:49:54 +08:00
|
|
|
doc_id={documentId}
|
2024-01-30 19:26:29 +08:00
|
|
|
isShowCreateModal={isShowCreateModal}
|
|
|
|
chunk_id={chunk_id}
|
|
|
|
getChunkList={getChunkList}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
2024-01-18 18:27:38 +08:00
|
|
|
};
|
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
export default Chunk;
|