File size: 8,737 Bytes
7b71fb2 362ec6c f3dd131 362ec6c 7b71fb2 362ec6c f3dd131 362ec6c f3dd131 7b71fb2 362ec6c 7b71fb2 362ec6c f3dd131 7b71fb2 362ec6c f3dd131 362ec6c f3dd131 362ec6c 7b71fb2 f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 7b71fb2 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c 7b71fb2 f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c f3dd131 362ec6c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
import { useKnowledgeBaseId } from '@/hooks/knowledgeHook';
import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
import { api_host } from '@/utils/api';
import { DeleteOutlined, MinusSquareOutlined } from '@ant-design/icons';
import type { PaginationProps } from 'antd';
import {
Card,
Col,
Input,
Pagination,
Popconfirm,
Row,
Select,
Spin,
Switch,
} from 'antd';
import { debounce } from 'lodash';
import React, { useCallback, useEffect } from 'react';
import { useDispatch, useSelector } from 'umi';
import CreateModal from '../knowledge-chunk/components/createModal';
import styles from './index.less';
const KnowledgeSearching = () => {
const dispatch = useDispatch();
const kSearchModel = useSelector((state: any) => state.kSearchModel);
const chunkModel = useSelector((state: any) => state.chunkModel);
const loading = useOneNamespaceEffectsLoading('kSearchModel', [
'chunk_list',
'switch_chunk',
]);
const knowledgeBaseId = useKnowledgeBaseId();
const {
data = [],
total,
d_list = [],
question,
doc_ids,
pagination,
} = kSearchModel;
const { chunk_id, doc_id, isShowCreateModal } = chunkModel;
const getChunkList = () => {
dispatch({
type: 'kSearchModel/chunk_list',
payload: {
kb_id: knowledgeBaseId,
},
});
};
const confirm = (id: string) => {
dispatch({
type: 'kSearchModel/rm_chunk',
payload: {
chunk_ids: [id],
kb_id: knowledgeBaseId,
},
});
};
const handleEditchunk = (item: any) => {
const { chunk_id, doc_id } = item;
dispatch({
type: 'chunkModel/updateState',
payload: {
isShowCreateModal: true,
chunk_id,
doc_id,
},
});
getChunkList();
};
const onShowSizeChange: PaginationProps['onShowSizeChange'] = (
page,
size,
) => {
dispatch({
type: 'kSearchModel/updateState',
payload: {
pagination: { page, size },
},
});
};
useEffect(() => {
dispatch({
type: 'kSearchModel/updateState',
payload: {
doc_ids: [],
question: '',
},
});
dispatch({
type: 'kSearchModel/getKfList',
payload: {
kb_id: knowledgeBaseId,
},
});
}, []);
const switchChunk = (item: any, available_int: boolean) => {
const { chunk_id, doc_id } = item;
dispatch({
type: 'kSearchModel/switch_chunk',
payload: {
chunk_ids: [chunk_id],
doc_id,
available_int,
kb_id: knowledgeBaseId,
},
});
};
useEffect(() => {
getChunkList();
}, [doc_ids, pagination, question]);
const debounceChange = debounce((value) => {
dispatch({
type: 'kSearchModel/updateState',
payload: {
question: value,
},
});
}, 300);
const debounceCallback = useCallback(
(value: string) => debounceChange(value),
[],
);
const handleInputChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
) => {
const value = e.target.value;
debounceCallback(value);
};
const handleSelectChange = (value: any[]) => {
dispatch({
type: 'kSearchModel/updateState',
payload: {
doc_ids: value,
},
});
};
return (
<>
<div className={styles.chunkPage}>
<div className={styles.filter}>
<Select
showSearch
placeholder="文件列表"
optionFilterProp="children"
onChange={handleSelectChange}
style={{ width: 300, marginBottom: 20 }}
options={d_list}
fieldNames={{ label: 'name', value: 'id' }}
mode="multiple"
/>
<Input.TextArea
autoSize={{ minRows: 6, maxRows: 6 }}
placeholder="搜索"
style={{ width: 300 }}
allowClear
onChange={handleInputChange}
/>
</div>
<div className={styles.pageContainer}>
<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}
>
<Card
className={styles.card}
onClick={() => {
handleEditchunk(item);
}}
>
<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.doc_ids == '1'}
onChange={(checked: boolean, e: any) => {
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
switchChunk(item, 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>
</div>
</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>
</div>
</div>
<CreateModal
getChunkList={getChunkList}
isShowCreateModal={isShowCreateModal}
chunk_id={chunk_id}
doc_id={doc_id}
/>
</>
);
};
export default KnowledgeSearching;
|