瀏覽代碼

知识库

CzRger 2 周之前
父節點
當前提交
5e34345fbc

+ 14 - 0
src/api/modules/knowledge/document.ts

@@ -15,3 +15,17 @@ export const documentUpdateFileName = (params) =>
 // 知识库文档添加分段
 export const documentAddSegment = (params) =>
   post(`/document/addSegment`, params, {})
+// 知识库文档分段分页
+export const documentGetSegmentsByPage = (params) =>
+  post(`/document/getSegmentsByPage`, params, {})
+// 知识库文档/问答迁移
+export const documentRemoveDataset = (params) =>
+  post(`/document/removeDataset`, params, {})
+// 知识库文档归档
+export const documentArchive = (params) => post(`/document/archive`, params, {})
+// 知识库文档撤销归档
+export const documentNoArchive = (params) =>
+  post(`/document/noArchive`, params, {})
+// 知识库文档删除
+export const documentDocsDelete = (params) =>
+  post(`/document/docs/delete`, params, {})

+ 2 - 0
src/api/modules/knowledge/qa.ts

@@ -8,3 +8,5 @@ export const qaRename = (params) => get(`/qa/rename`, params, {})
 export const qaDetail = (id) => get(`/qa/${id}`, {}, {})
 // 知识库问答新增
 export const qaCreatQa = (params) => post(`/qa/creatQa`, params, {})
+// 知识库问答删除
+export const qaQaDocsDelete = (params) => post(`/qa/qaDocs/delete`, params, {})

+ 100 - 12
src/views/manage/knowledge/documents/document/index.vue

@@ -82,15 +82,34 @@
           >
             <template #name-column-value="{ scope }">
               <div class="flex justify-center">
-                <CzrButton
-                  type="table"
-                  :title="scope.row.name"
-                  @click="onStage(scope.row)"
-                />
+                <template v-if="scope.row.indexingStatus === 'completed'">
+                  <CzrButton
+                    type="table"
+                    :title="scope.row.name"
+                    @click="onStage(scope.row)"
+                  />
+                </template>
+                <template v-else>
+                  {{ scope.row.name }}
+                </template>
               </div>
             </template>
             <template #caozuo-column-value="{ scope }">
               <div class="__czr-table-operations">
+                <template v-if="scope.row.indexingStatus === 'archived'">
+                  <CzrButton
+                    type="table"
+                    title="撤销归档"
+                    @click="onUnArchive(scope.row)"
+                  />
+                </template>
+                <template v-if="scope.row.indexingStatus === 'completed'">
+                  <CzrButton
+                    type="table"
+                    title="归档"
+                    @click="onArchive(scope.row)"
+                  />
+                </template>
                 <CzrButton
                   type="table"
                   title="重命名"
@@ -101,7 +120,6 @@
                   title="迁移"
                   @click="onKnowledge(scope.row)"
                 />
-                <CzrButton type="table" title="归档" />
                 <CzrButton type="table-del" @click="onDel(scope.row)" />
               </div>
             </template>
@@ -151,7 +169,12 @@ import detailCom from './detail.vue'
 import renameCom from './rename.vue'
 import knowledgeSelectCom from './knowledge-select.vue'
 import stageIndexCom from './stage-index.vue'
-import { documentGetDocumentsByPage } from '@/api/modules/knowledge/document'
+import {
+  documentArchive,
+  documentDocsDelete,
+  documentGetDocumentsByPage,
+  documentNoArchive,
+} from '@/api/modules/knowledge/document'
 
 const DialogStore = useDialogStore()
 const DictionaryStore = useDictionaryStore()
@@ -305,10 +328,16 @@ const onDel = (row: any = null) => {
   if (row) {
     DialogStore.confirm({
       title: '删除确认',
-      content: `是否删除文档:${row.p1}?<br/>此文档下的29个分段都会被删除,请谨慎操作。`,
+      content: `是否删除文档:${row.name}?<br/>此文档下的${row.p1 ? row.p1 + '个' : ''}分段都会被删除,请谨慎操作。`,
       onSubmit: () => {
-        ElMessage.success('删除成功!')
-        onSearch()
+        documentDocsDelete([row.id])
+          .then(() => {
+            ElMessage.success('删除成功!')
+          })
+          .catch(() => {})
+          .finally(() => {
+            onSearch()
+          })
       },
     })
   } else {
@@ -320,12 +349,71 @@ const onDel = (row: any = null) => {
       title: '删除确认',
       content: `是否批量删除${state.query.selected.length}个文档?<br/>所选文档中的分段会跟随删除,请谨慎操作。`,
       onSubmit: () => {
-        ElMessage.success('删除成功!')
-        onSearch()
+        documentDocsDelete(state.query.selected.map((v) => v.id))
+          .then(() => {
+            ElMessage.success('删除成功!')
+          })
+          .catch(() => {})
+          .finally(() => {
+            onSearch()
+          })
+      },
+    })
+  }
+}
+const onArchive = (row: any = null) => {
+  if (row) {
+    DialogStore.confirm({
+      title: '归档确认',
+      content: `是否归档文档:${row.name}?<br/>归档后的数据就只能查看或删除,无法重新编辑,请谨慎操作。`,
+      onSubmit: () => {
+        documentArchive([row.id])
+          .then(() => {
+            ElMessage.success('归档成功!')
+          })
+          .catch(() => {})
+          .finally(() => {
+            onSearch()
+          })
+      },
+    })
+  } else {
+    if (state.query.selected.length === 0) {
+      ElMessage.warning('请至少选择一条记录!')
+      return
+    }
+    DialogStore.confirm({
+      title: '归档确认',
+      content: `是否批量删除${state.query.selected.length}个文档?<br/>归档后的数据就只能查看或删除,无法重新编辑,请谨慎操作。`,
+      onSubmit: () => {
+        documentArchive(state.query.selected.map((v) => v.id))
+          .then(() => {
+            ElMessage.success('归档成功!')
+          })
+          .catch(() => {})
+          .finally(() => {
+            onSearch()
+          })
       },
     })
   }
 }
+const onUnArchive = (row: any = null) => {
+  DialogStore.confirm({
+    title: '撤销归档确认',
+    content: `是否撤销归档:${row.name}?<br/>撤销归档后的数据,可重新编辑,请谨慎操作。`,
+    onSubmit: () => {
+      documentNoArchive([row.id])
+        .then(() => {
+          ElMessage.success('撤销归档成功!')
+        })
+        .catch(() => {})
+        .finally(() => {
+          onSearch()
+        })
+    },
+  })
+}
 const onRename = (row) => {
   state.rename.transfer = {
     id: row.id,

+ 39 - 12
src/views/manage/knowledge/documents/document/knowledge-select.vue

@@ -33,12 +33,15 @@ import {
   watch,
 } from 'vue'
 import { ElMessage, ElMessageBox } from 'element-plus'
-import { useDialogStore, useDictionaryStore } from '@/stores'
+import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
 import { useRouter } from 'vue-router'
+import { datasetsGetAllByPage } from '@/api/modules/knowledge'
+import { documentRemoveDataset } from '@/api/modules/knowledge/document'
 
 const router = useRouter()
 const DictionaryStore = useDictionaryStore()
 const DialogStore = useDialogStore()
+const AppStore = useAppStore()
 const emit = defineEmits(['update:show', 'refresh'])
 const { proxy } = getCurrentInstance()
 const props = defineProps({
@@ -59,14 +62,19 @@ watch(
   },
 )
 const initDictionary = () => {
-  const arr: any = []
-  for (let i = 1; i <= 100; i++) {
-    arr.push({
-      id: i,
-      name: '部门知识库-新_' + i,
+  state.loading = true
+  datasetsGetAllByPage({
+    tenantId: AppStore.tenantInfo?.id,
+    page: 1,
+    size: 100000,
+  })
+    .then(({ data }: any) => {
+      state.list = data.content
+    })
+    .catch(() => {})
+    .finally(() => {
+      state.loading = false
     })
-  }
-  state.list = arr
 }
 const onSubmit = () => {
   let tips = '请确认是否将'
@@ -83,15 +91,34 @@ const onSubmit = () => {
     }
   }
   tips += `迁移至${state.active.name}?`
+  let documentType = ''
+  if (props.transfer.type === 'text') {
+    documentType = 'TEXT_FILE'
+  } else if (props.transfer.type === 'qa') {
+    documentType = 'QA_QUESTION'
+  } else if (props.transfer.type === 'stage') {
+  }
   if (state.active.id) {
     DialogStore.confirm({
       content: tips,
       onSubmit: () => {
         state.loading = true
-        ElMessage.success(`迁移成功!`)
-        emit('update:show', false)
-        emit('refresh')
-        state.loading = false
+        documentRemoveDataset({
+          datasetId: state.active.id,
+          docIds: props.transfer.row
+            ? [props.transfer.row.id]
+            : props.transfer.list.map((v) => v.id),
+          documentType: documentType,
+        })
+          .then(() => {
+            ElMessage.success(`迁移成功!`)
+            emit('update:show', false)
+            emit('refresh')
+          })
+          .catch(() => {})
+          .finally(() => {
+            state.loading = false
+          })
       },
     })
   } else {

+ 8 - 2
src/views/manage/knowledge/documents/document/stage-index.vue

@@ -6,7 +6,7 @@
         @click="$emit('update:show', false)"
       >
         <SvgIcon name="czr_arrow" :rotate="180" size="12" />
-        {{ document.p1 }}
+        {{ document.name }}
       </div>
       <div class="ml-auto flex gap-[0.5rem]">
         <template v-if="!state.isSelect">
@@ -160,6 +160,7 @@ const { proxy }: any = getCurrentInstance()
 const state: any = reactive({
   text: '',
   query: {
+    init: false,
     loading: false,
     page: {
       pageNum: 1,
@@ -191,11 +192,16 @@ watch(
 watch(
   () => state.query.form,
   (n) => {
-    onSearch()
+    if (state.query.init) {
+      onSearch()
+    }
   },
   { deep: true },
 )
 const onPage = (pageNum, pageSize) => {
+  setTimeout(() => {
+    state.query.init = true
+  }, 100)
   state.query.page = {
     pageNum: pageNum,
     pageSize: pageSize,

+ 18 - 6
src/views/manage/knowledge/documents/qa/index.vue

@@ -96,7 +96,7 @@ import { ElMessage } from 'element-plus'
 import detailCom from './detail.vue'
 import renameCom from './rename.vue'
 import knowledgeSelectCom from '../document/knowledge-select.vue'
-import { qaGetQaPage } from '@/api/modules/knowledge/qa'
+import { qaGetQaPage, qaQaDocsDelete } from '@/api/modules/knowledge/qa'
 
 const DialogStore = useDialogStore()
 const DictionaryStore = useDictionaryStore()
@@ -240,10 +240,16 @@ const onDel = (row: any = null) => {
   if (row) {
     DialogStore.confirm({
       title: '删除确认',
-      content: `是否删除问答:${row.p1}?<br/>请谨慎操作。`,
+      content: `是否删除问答:${row.name}?<br/>请谨慎操作。`,
       onSubmit: () => {
-        ElMessage.success('删除成功!')
-        onSearch()
+        qaQaDocsDelete([row.id])
+          .then(() => {
+            ElMessage.success('删除成功!')
+          })
+          .catch(() => {})
+          .finally(() => {
+            onSearch()
+          })
       },
     })
   } else {
@@ -255,8 +261,14 @@ const onDel = (row: any = null) => {
       title: '删除确认',
       content: `是否批量删除${state.query.selected.length}个问答?<br/>请谨慎操作。`,
       onSubmit: () => {
-        ElMessage.success('删除成功!')
-        onSearch()
+        qaQaDocsDelete(state.query.selected.map((v) => v.id))
+          .then(() => {
+            ElMessage.success('删除成功!')
+          })
+          .catch(() => {})
+          .finally(() => {
+            onSearch()
+          })
       },
     })
   }

+ 6 - 5
src/views/manage/knowledge/model-config.vue

@@ -570,7 +570,7 @@ const state: any = reactive({
       score: 0.5,
     },
     [SearchMethodType.Mix]: {
-      indexMethod: 1,
+      indexMethod: 'weightSetting',
       weight: 0.7,
       rerank: '',
       topK: 5,
@@ -620,7 +620,7 @@ const reset = () => {
       score: 0.5,
     },
     [SearchMethodType.Mix]: {
-      indexMethod: 1,
+      indexMethod: 'weightSetting',
       weight: 0.7,
       rerank: '',
       topK: 5,
@@ -684,9 +684,10 @@ const getData = () => {
           1 - state.searchMethod[SearchMethodType.Mix].weight
         result.indexConfig.rerankTypeId =
           state.searchMethod[SearchMethodType.Mix].rerank
-        result.indexConfig.rerankType = optionsRerankMapCpt.value.get(
-          state.searchMethod[SearchMethodType.Mix].rerank,
-        ).label
+        result.indexConfig.rerankType =
+          optionsRerankMapCpt.value.get(
+            state.searchMethod[SearchMethodType.Mix].rerank,
+          )?.label || ''
         result.indexConfig.topK = state.searchMethod[SearchMethodType.Mix].topK
         result.indexConfig.isScore =
           state.searchMethod[SearchMethodType.Mix].isScore

+ 0 - 1
src/views/manage/model/detail.vue

@@ -220,7 +220,6 @@ const onSubmit = () => {
     })
 }
 const getModelProvide = (obj) => {
-  console.log(obj)
   state.form.name = obj.name
   state.form.description = obj.description
   state.baseForms = obj.basicConfigAttr