diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/createModal.tsx b/web/src/pages/add-knowledge/components/knowledge-chunk/components/createModal.tsx similarity index 91% rename from web/src/pages/add-knowledge/components/knowledge-chunk/createModal.tsx rename to web/src/pages/add-knowledge/components/knowledge-chunk/components/createModal.tsx index 8414bfc4e..b5f09d3bc 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/createModal.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/components/createModal.tsx @@ -14,10 +14,12 @@ interface kFProps { dispatch: Dispatch; chunkModel: chunkModelState; getChunkList: () => void; - doc_id: string + isShowCreateModal: boolean; + doc_id: string; + chunk_id: string } -const Index: React.FC = ({ chunkModel, dispatch, getChunkList, doc_id }) => { - const { isShowCreateModal, chunk_id, chunkInfo } = chunkModel +const Index: React.FC = ({ dispatch, getChunkList, doc_id, isShowCreateModal, chunk_id }) => { + // const { , chunkInfo } = chunkModel const [important_kwd, setImportantKwd] = useState(['Unremovable', 'Tag 2', 'Tag 3']); const { t } = useTranslation() const handleCancel = () => { @@ -29,6 +31,7 @@ const Index: React.FC = ({ chunkModel, dispatch, getChunkList, doc_id } }); }; useEffect(() => { + console.log(chunk_id, isShowCreateModal) if (chunk_id && isShowCreateModal) { dispatch({ type: 'chunkModel/get_chunk', diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/editTag.tsx b/web/src/pages/add-knowledge/components/knowledge-chunk/components/editTag.tsx similarity index 100% rename from web/src/pages/add-knowledge/components/knowledge-chunk/editTag.tsx rename to web/src/pages/add-knowledge/components/knowledge-chunk/components/editTag.tsx diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx b/web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx index 076820914..6f80e7f14 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx @@ -4,7 +4,7 @@ import { Card, Row, Col, Input, Select, Switch, Pagination, Spin, Button, Popcon import { MinusSquareOutlined, DeleteOutlined, } from '@ant-design/icons'; import type { PaginationProps } from 'antd'; import { api_host } from '@/utils/api' -import CreateModal from './createModal' +import CreateModal from './components/createModal' import styles from './index.less' @@ -21,7 +21,7 @@ const Index: React.FC = ({ chunkModel, dispatch, doc_id }) => { const navigate = useNavigate() const [pagination, setPagination] = useState({ page: 1, size: 30 }) // const [datas, setDatas] = useState(data) - const { data = [], total, loading } = chunkModel + const { data = [], total, loading, chunk_id, isShowCreateModal } = chunkModel console.log(chunkModel) const getChunkList = (value?: string) => { dispatch({ @@ -66,7 +66,8 @@ const Index: React.FC = ({ chunkModel, dispatch, doc_id }) => { type: 'chunkModel/updateState', payload: { isShowCreateModal: true, - chunk_id + chunk_id, + doc_id }, callback: getChunkList }); @@ -216,7 +217,7 @@ const Index: React.FC = ({ chunkModel, dispatch, doc_id }) => { - + ) }; diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts b/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts index b81b16922..9091c70dc 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/model.ts @@ -8,6 +8,7 @@ export interface chunkModelState { total: number; isShowCreateModal: boolean; chunk_id: string; + doc_id: string; chunkInfo: any } export interface chunkgModelType { @@ -33,6 +34,7 @@ const Model: chunkgModelType = { total: 0, isShowCreateModal: false, chunk_id: '', + doc_id: '', chunkInfo: {} }, subscriptions: { diff --git a/web/src/pages/add-knowledge/components/knowledge-search/index.less b/web/src/pages/add-knowledge/components/knowledge-search/index.less new file mode 100644 index 000000000..4f51079ac --- /dev/null +++ b/web/src/pages/add-knowledge/components/knowledge-search/index.less @@ -0,0 +1,79 @@ +.chunkPage { + padding: 24px; + display: flex; + height: calc(100vh - 112px); + // flex-direction: column; + + .filter { + margin-right: 20px; + display: flex; + height: 32px; + width: 300px; + flex-wrap: wrap; + justify-content: space-between; + } + + .pageContainer { + flex: 1; + display: flex; + flex-direction: column; + + .pageContent { + flex: 1; + width: 100%; + padding-right: 12px; + overflow-y: auto; + + .spin { + min-height: 400px; + } + } + + .pageFooter { + height: 32px; + float: right; + } + } + +} + +.container { + height: 100px; + display: flex; + flex-direction: column; + justify-content: space-between; + + .content { + display: flex; + justify-content: space-between; + + .context { + flex: 1; + // width: 207px; + height: 88px; + overflow: hidden; + } + } + + .footer { + height: 20px; + + .text { + margin-left: 10px; + } + } +} + +.card { + :global { + .ant-card-body { + padding: 10px; + margin: 0; + } + + margin-bottom: 10px; + } + + cursor: pointer; + +} \ No newline at end of file diff --git a/web/src/pages/add-knowledge/components/knowledge-search/index.tsx b/web/src/pages/add-knowledge/components/knowledge-search/index.tsx index 619f2ff8a..98b1891b4 100644 --- a/web/src/pages/add-knowledge/components/knowledge-search/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-search/index.tsx @@ -1,3 +1,241 @@ -export default () => { - return
知识库搜索
-} \ No newline at end of file +import React, { useEffect, useState, useCallback, } from 'react'; +import { useNavigate, connect, Dispatch } from 'umi' +import { Card, Row, Col, Input, Select, Switch, Pagination, Spin, Button, Popconfirm } from 'antd'; +import { MinusSquareOutlined, DeleteOutlined, } from '@ant-design/icons'; +import type { PaginationProps } from 'antd'; +import { api_host } from '@/utils/api' +import CreateModal from '../knowledge-chunk/components/createModal' + + +import styles from './index.less' +import { debounce } from 'lodash'; +import type { kSearchModelState } from './model' +import type { chunkModelState } from '../knowledge-chunk/model' +interface chunkProps { + dispatch: Dispatch; + kSearchModel: kSearchModelState; + chunkModel: chunkModelState; + kb_id: string +} +const Index: React.FC = ({ kSearchModel, chunkModel, dispatch, kb_id }) => { + + const { data = [], total, loading, d_list = [], question, doc_ids, pagination, } = kSearchModel + const { chunk_id, doc_id, isShowCreateModal } = chunkModel + const getChunkList = () => { + dispatch({ + type: 'kSearchModel/updateState', + payload: { + loading: true + } + }); + interface payloadType { + kb_id: string; + question?: string; + doc_ids: any[]; + similarity_threshold?: number + } + const payload: payloadType = { + kb_id, + question, + doc_ids, + similarity_threshold: 0.1 + } + dispatch({ + type: 'kSearchModel/chunk_list', + payload: { + ...payload, + ...pagination + } + }); + } + const confirm = (id: string) => { + console.log(id) + dispatch({ + type: 'kSearchModel/rm_chunk', + payload: { + chunk_ids: [id] + }, + callback: getChunkList + }); + }; + const handleEditchunk = (item: any) => { + const { chunk_id, doc_id } = item + dispatch({ + type: 'chunkModel/updateState', + payload: { + isShowCreateModal: true, + chunk_id, + doc_id + }, + callback: getChunkList + }); + } + const onShowSizeChange: PaginationProps['onShowSizeChange'] = (page, size) => { + dispatch({ + type: 'kSearchModel/updateState', + payload: { + pagination: { page, size } + } + }); + }; + const switchChunk = (item: any, available_int: boolean) => { + const { chunk_id, doc_id } = item + dispatch({ + type: 'kSearchModel/updateState', + payload: { + loading: true + } + }); + dispatch({ + type: 'kSearchModel/switch_chunk', + payload: { + chunk_ids: [chunk_id], + doc_id, + available_int + }, + callback: getChunkList + }); + } + + useEffect(() => { + if (kb_id) { + dispatch({ + type: 'kSearchModel/getKfList', + payload: { + kb_id + } + }); + } + }, [kb_id]) + + 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) => { + const value = e.target.value + debounceCallback(value) + } + const handleSelectChange = (value: + any[]) => { + dispatch({ + type: 'kSearchModel/updateState', + payload: { + doc_ids: value + } + }); + } + console.log('loading', loading) + return (<> +
+
+