feat: document

This commit is contained in:
wangdan-fit2cloud 2025-06-19 21:32:14 +08:00
parent 73df001e41
commit 7acdd887bf
10 changed files with 82 additions and 105 deletions

View File

@ -54,11 +54,14 @@ const getDocumentPage: (
*
* @param knowledge_id
*/
const getDocumentDetail: (knowledge_id: string, document_id: string) => Promise<Result<any>> = (
knowledge_id,
document_id,
) => {
return get(`${prefix.value}/${knowledge_id}/document/${document_id}`)
const getDocumentDetail: (
knowledge_id: string,
document_id: string,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (knowledge_id, document_id, loading) => {
return get(`${prefix.value}/${knowledge_id}/document/${document_id}`,
{},
loading,)
}
/**
@ -108,12 +111,7 @@ const putBatchCancelTask: (
data: any,
loading?: Ref<boolean>,
) => Promise<Result<boolean>> = (knowledge_id, data, loading) => {
return put(
`${prefix.value}/${knowledge_id}/document/batch_cancel_task`,
data,
undefined,
loading,
)
return put(`${prefix.value}/${knowledge_id}/document/batch_cancel_task`, data, undefined, loading)
}
/**
@ -560,12 +558,11 @@ const putMulLarkSyncDocument: (
const importLarkDocument: (
knowledge_id: string,
data: any,
loading?: Ref<boolean>
loading?: Ref<boolean>,
) => Promise<Result<Array<any>>> = (knowledge_id, data, loading) => {
return post(`${prefix.value}/lark/${knowledge_id}/import`, data, null, loading)
}
export default {
getDocumentList,
getDocumentPage,
@ -596,5 +593,5 @@ export default {
getLarkDocumentList,
putLarkDocumentSync,
putMulLarkSyncDocument,
importLarkDocument
importLarkDocument,
}

View File

@ -300,5 +300,6 @@ export default {
putMulParagraph,
putBatchGenerateRelated,
putMigrateMulParagraph,
putDisassociationProblem
putDisassociationProblem,
putAdjustPosition
}

View File

@ -27,15 +27,19 @@ const getDocument: (
)
}
/**
*
* @param knowledge_id
*/
const getDocumentDetail: (knowledge_id: string, document_id: string) => Promise<Result<any>> = (
knowledge_id,
document_id,
) => {
return get(`${prefix}/${knowledge_id}/document/${document_id}`)
const getDocumentDetail: (
knowledge_id: string,
document_id: string,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (knowledge_id, document_id, loading) => {
return get(`${prefix}/${knowledge_id}/document/${document_id}`,
{},
loading,)
}
/**

View File

@ -26,16 +26,16 @@ const getDocumentPage: (
loading,
)
}
/**
*
* @param knowledge_id
*/
const getDocumentDetail: (knowledge_id: string, document_id: string) => Promise<Result<any>> = (
knowledge_id,
document_id,
) => {
return get(`${prefix}/${knowledge_id}/document/${document_id}`)
const getDocumentDetail: (
knowledge_id: string,
document_id: string,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (knowledge_id, document_id, loading) => {
return get(`${prefix}/${knowledge_id}/document/${document_id}`, {}, loading)
}
/**
@ -85,12 +85,7 @@ const putBatchCancelTask: (
data: any,
loading?: Ref<boolean>,
) => Promise<Result<boolean>> = (knowledge_id, data, loading) => {
return put(
`${prefix}/${knowledge_id}/document/batch_cancel_task`,
data,
undefined,
loading,
)
return put(`${prefix}/${knowledge_id}/document/batch_cancel_task`, data, undefined, loading)
}
/**
@ -470,12 +465,7 @@ const getLarkDocumentList: (
data: any,
loading?: Ref<boolean>,
) => Promise<Result<any>> = (knowledge_id, folder_token, data, loading) => {
return post(
`${prefix}/lark/${knowledge_id}/${folder_token}/doc_list`,
data,
undefined,
loading,
)
return post(`${prefix}/lark/${knowledge_id}/${folder_token}/doc_list`, data, undefined, loading)
}
/**

View File

@ -5,6 +5,7 @@
@mouseenter="cardEnter()"
@mouseleave="cardLeave()"
@click.stop="editParagraph(data)"
v-loading="loading"
>
<h2 class="mb-16">{{ data.title || '-' }}</h2>
<div v-show="show" class="mk-sticky" v-if="!disabled">
@ -30,7 +31,7 @@
</el-button>
</span>
<span class="mr-8">
<el-button link>
<el-button link @click.stop="addParagraph(data)">
<el-icon :size="16" :title="$t('views.applicationWorkflow.control.zoomOut')">
<el-icon><CirclePlus /></el-icon>
</el-icon>
@ -154,6 +155,11 @@ function editParagraph(row: any) {
}
}
function addParagraph(row: any) {
title.value = t('views.paragraph.addParagraph')
ParagraphDialogRef.value.open(row, 'add')
}
const SelectDocumentDialogRef = ref()
function openSelectDocumentDialog(row?: any) {
SelectDocumentDialogRef.value.open([row.id])

View File

@ -7,13 +7,14 @@
destroy-on-close
:close-on-click-modal="false"
:close-on-press-escape="false"
@click.stop
>
<el-row v-loading="loading">
<el-col :span="18">
<el-scrollbar height="500" wrap-class="paragraph-scrollbar">
<div class="p-24" style="padding-bottom: 8px">
<div style="position: absolute; right: 20px; top: 20px">
<el-button text @click="isEdit = true" v-if="problemId && !isEdit">
<el-button text @click="isEdit = true" v-if="paragraphId && !isEdit">
<el-icon><EditPen /></el-icon>
</el-button>
</div>
@ -21,7 +22,7 @@
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" />
</div>
</el-scrollbar>
<div class="text-right p-24 pt-0" v-if="problemId && isEdit">
<div class="text-right p-24 pt-0" v-if="paragraphId && isEdit">
<el-button @click.prevent="cancelEdit"> {{ $t('common.cancel') }} </el-button>
<el-button type="primary" :disabled="loading" @click="handleDebounceClick">
{{ $t('common.save') }}
@ -31,14 +32,14 @@
<el-col :span="6" class="border-l" style="width: 300px">
<!-- 关联问题 -->
<ProblemComponent
:problemId="problemId"
:paragraphId="paragraphId"
:docId="document_id"
:knowledgeId="dataset_id"
ref="ProblemRef"
/>
</el-col>
</el-row>
<template #footer v-if="!problemId">
<template #footer v-if="!paragraphId">
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button>
<el-button :disabled="loading" type="primary" @click="handleDebounceClick">
@ -76,16 +77,17 @@ const paragraphFormRef = ref<any>()
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
const problemId = ref('')
const paragraphId = ref('')
const detail = ref<any>({})
const isEdit = ref(false)
const document_id = ref('')
const dataset_id = ref('')
const cloneData = ref(null)
const position = ref(null)
watch(dialogVisible, (bool) => {
if (!bool) {
problemId.value = ''
paragraphId.value = ''
detail.value = {}
isEdit.value = false
document_id.value = ''
@ -99,28 +101,31 @@ const cancelEdit = () => {
detail.value = cloneDeep(cloneData.value)
}
const open = (data: any) => {
if (data) {
const open = (data: any, str: any) => {
if (data && !str) {
detail.value.title = data.title
detail.value.content = data.content
cloneData.value = cloneDeep(detail.value)
problemId.value = data.id
paragraphId.value = data.id
document_id.value = data.document_id
dataset_id.value = data.dataset_id || id
} else {
isEdit.value = true
if (str === 'add') {
position.value = data.position
}
}
dialogVisible.value = true
}
const submitHandle = async () => {
if (await paragraphFormRef.value?.validate()) {
loading.value = true
if (problemId.value) {
if (paragraphId.value) {
paragraph
.asyncPutParagraph(
dataset_id.value,
documentId || document_id.value,
problemId.value,
paragraphId.value,
paragraphFormRef.value?.form,
loading,
)
@ -132,10 +137,14 @@ const submitHandle = async () => {
const obj =
ProblemRef.value.problemList.length > 0
? {
position: String(position.value) ? position.value : null,
problem_list: ProblemRef.value.problemList,
...paragraphFormRef.value?.form,
}
: paragraphFormRef.value?.form
: {
position: String(position.value) ? position.value : null,
...paragraphFormRef.value?.form,
}
paragraphApi.postParagraph(id, documentId, obj, loading).then((res) => {
dialogVisible.value = false
emit('refresh')

View File

@ -61,7 +61,7 @@ import paragraphApi from '@/api/knowledge/paragraph'
import useStore from '@/stores'
const props = defineProps({
problemId: String,
paragraphId: String,
docId: String,
knowledgeId: String,
})
@ -83,7 +83,7 @@ const problemOptions = ref<any[]>([])
const optionLoading = ref(false)
watch(
() => props.problemId,
() => props.paragraphId,
(value) => {
if (value) {
getProblemList()
@ -100,7 +100,7 @@ function delProblemHandle(item: any, index: number) {
.asyncDisassociationProblem(
props.knowledgeId || id,
documentId || props.docId,
props.problemId || '',
props.paragraphId || '',
item.id,
loading,
)
@ -115,7 +115,7 @@ function delProblemHandle(item: any, index: number) {
function getProblemList() {
loading.value = true
paragraphApi
.getParagraphProblem(props.knowledgeId || id, documentId || props.docId, props.problemId || '')
.getParagraphProblem(props.knowledgeId || id, documentId || props.docId, props.paragraphId || '')
.then((res) => {
problemList.value = res.data
loading.value = false
@ -132,19 +132,19 @@ function addProblem() {
})
}
function addProblemHandle(val: string) {
if (props.problemId) {
if (props.paragraphId) {
const api = problemOptions.value.some((option) => option.id === val)
? paragraph.asyncAssociationProblem(
props.knowledgeId || id,
documentId || props.docId,
props.problemId,
props.paragraphId,
val,
loading,
)
: paragraphApi.postParagraphProblem(
props.knowledgeId || id,
documentId || props.docId,
props.problemId,
props.paragraphId,
{
content: val,
},

View File

@ -81,19 +81,14 @@
handle=".handle"
:animation="150"
ghostClass="ghost"
@end="onEnd"
>
<template v-for="(item, index) in paragraphDetail" :key="item.id">
<div :id="`m${item.id}`" class="flex mb-16">
<!-- 批量操作 -->
<div class="paragraph-card flex w-full" v-if="isBatch === true">
<el-checkbox :value="item.id" />
<ParagraphCard
:data="item"
class="mb-8 w-full"
@refresh="refresh"
@refreshMigrateParagraph="refreshMigrateParagraph"
:disabled="true"
/>
<ParagraphCard :data="item" class="mb-8 w-full" :disabled="true" />
</div>
<!-- 非批量操作 -->
<div class="handle paragraph-card flex w-full" :id="item.id" v-else>
@ -109,6 +104,8 @@
class="mb-8 w-full"
@changeState="changeState"
@deleteParagraph="deleteParagraph"
@refresh="refresh"
@refreshMigrateParagraph="refreshMigrateParagraph"
/>
</div>
</div>
@ -265,16 +262,9 @@ function addParagraph() {
}
function getDetail() {
loading.value = true
documentApi
.getDocumentDetail(id, documentId)
.then((res) => {
documentDetail.value = res.data
loading.value = false
})
.catch(() => {
loading.value = false
})
documentApi.getDocumentDetail(id, documentId, loading).then((res) => {
documentDetail.value = res.data
})
}
function getParagraphList() {
@ -320,17 +310,11 @@ function openGenerateDialog(row?: any) {
}
function onEnd(event?: any) {
const { oldIndex, newIndex } = event
if (oldIndex === undefined || newIndex === undefined) return
const list = cloneDeep(paragraphDetail.value)
if (oldIndex === list.length - 1 || newIndex === list.length - 1) {
return
const obj = {
paragraph_id: paragraphDetail.value[event.newIndex].id,
new_position: paragraphDetail.value[event.newIndex].position,
}
const newInstance = { ...list[oldIndex], type: list[newIndex].type, id: list[newIndex].id }
const oldInstance = { ...list[newIndex], type: list[oldIndex].type, id: list[oldIndex].id }
list[newIndex] = newInstance
list[oldIndex] = oldInstance
paragraphDetail.value = list
paragraphApi.putAdjustPosition(id, documentId, obj, loading)
}
onMounted(() => {

View File

@ -254,16 +254,9 @@ function addParagraph() {
}
function getDetail() {
loading.value = true
documentApi
.getDocumentDetail(id, documentId)
.then((res) => {
documentDetail.value = res.data
loading.value = false
})
.catch(() => {
loading.value = false
})
documentApi.getDocumentDetail(id, documentId, loading).then((res) => {
documentDetail.value = res.data
})
}
function getParagraphList() {

View File

@ -252,16 +252,9 @@ function addParagraph() {
}
function getDetail() {
loading.value = true
documentApi
.getDocumentDetail(id, documentId)
.then((res) => {
documentDetail.value = res.data
loading.value = false
})
.catch(() => {
loading.value = false
})
documentApi.getDocumentDetail(id, documentId, loading).then((res) => {
documentDetail.value = res.data
})
}
function getParagraphList() {