mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:12:51 +00:00
feat: 导入文档
This commit is contained in:
parent
6103e64de8
commit
f3f667dce1
|
|
@ -154,6 +154,37 @@ const putDocumentRefresh: (
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量同步文档
|
||||
* @param 参数 dataset_id,
|
||||
*/
|
||||
const delMulSyncDocument: (
|
||||
dataset_id: string,
|
||||
data: any,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<boolean>> = (dataset_id, data, loading) => {
|
||||
return put(`${prefix}/${dataset_id}/document/_bach`, { id_list: data }, undefined, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Web站点文档
|
||||
* @param 参数
|
||||
* {
|
||||
"source_url_list": [
|
||||
"string"
|
||||
],
|
||||
"selector": "string"
|
||||
}
|
||||
}
|
||||
*/
|
||||
const postWebDocument: (
|
||||
dataset_id: string,
|
||||
data: any,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<any>> = (dataset_id, data, loading) => {
|
||||
return post(`${prefix}/${dataset_id}/document/web`, data, undefined, loading)
|
||||
}
|
||||
|
||||
export default {
|
||||
postSplitDocument,
|
||||
getDocument,
|
||||
|
|
@ -164,5 +195,7 @@ export default {
|
|||
delMulDocument,
|
||||
getDocumentDetail,
|
||||
listSplitPattern,
|
||||
putDocumentRefresh
|
||||
putDocumentRefresh,
|
||||
delMulSyncDocument,
|
||||
postWebDocument
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,36 @@
|
|||
<template>
|
||||
<el-dialog
|
||||
title="同步知识库"
|
||||
title="导入文档"
|
||||
v-model="dialogVisible"
|
||||
width="600px"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
:destroy-on-close="true"
|
||||
>
|
||||
<p class="mb-8">同步方式</p>
|
||||
<el-radio-group v-model="method" class="card__radio">
|
||||
<el-card shadow="never" class="mb-16" :class="method === 'replace' ? 'active' : ''">
|
||||
<el-radio label="replace" size="large">
|
||||
<p class="mb-4">替换同步</p>
|
||||
<el-text type="info">重新获取 Web 站点文档,覆盖替换本地知识库中的文档</el-text>
|
||||
</el-radio>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="mb-16" :class="method === 'complete' ? 'active' : ''">
|
||||
<el-radio label="complete" size="large">
|
||||
<p class="mb-4">整体同步</p>
|
||||
<el-text type="info">先删除本地知识库所有文档,重新获取 Web 站点文档</el-text>
|
||||
</el-radio>
|
||||
</el-card>
|
||||
</el-radio-group>
|
||||
<p class="danger">注意:所有同步都会删除已有数据重新获取新数据,请谨慎操作。</p>
|
||||
<el-form
|
||||
label-position="top"
|
||||
ref="webFormRef"
|
||||
:rules="rules"
|
||||
:model="form"
|
||||
require-asterisk-position="right"
|
||||
>
|
||||
<el-form-item label="文档地址" prop="source_url" v-if="isImport">
|
||||
<el-input
|
||||
v-model="form.source_url"
|
||||
placeholder="请输入文档地址,一行一个,地址不正确文档会导入失败。"
|
||||
:rows="10"
|
||||
type="textarea"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-else label="文档地址" prop="source_url">
|
||||
<el-input v-model="form.source_url" placeholder="请输入文档地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选择器">
|
||||
<el-input
|
||||
v-model="form.selector"
|
||||
placeholder="默认为 body,可输入 .classname/#idname/tagname"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
|
||||
|
|
@ -33,56 +40,61 @@
|
|||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
import { ref, reactive, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import documentApi from '@/api/document'
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
|
||||
import useStore from '@/stores'
|
||||
const { dataset } = useStore()
|
||||
const route = useRoute()
|
||||
const {
|
||||
params: { id }
|
||||
} = route as any
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
const loading = ref<boolean>(false)
|
||||
const method = ref('replace')
|
||||
const datasetId = ref('')
|
||||
const isImport = ref<boolean>(false)
|
||||
const form = ref<any>({
|
||||
source_url: '',
|
||||
selector: ''
|
||||
})
|
||||
|
||||
const rules = reactive({
|
||||
source_url: [{ required: true, message: '请输入 Web 根地址', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
const dialogVisible = ref<boolean>(false)
|
||||
|
||||
watch(dialogVisible, (bool) => {
|
||||
if (!bool) {
|
||||
method.value = 'replace'
|
||||
form.value = {
|
||||
source_url: '',
|
||||
selector: ''
|
||||
}
|
||||
isImport.value = false
|
||||
}
|
||||
})
|
||||
|
||||
const open = (id: string) => {
|
||||
datasetId.value = id
|
||||
const open = (row: any) => {
|
||||
if (row) {
|
||||
isImport.value = false
|
||||
} else {
|
||||
isImport.value = true
|
||||
}
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const submit = () => {
|
||||
dataset.asyncSyncDateset(datasetId.value, method.value, loading).then((res: any) => {
|
||||
// MsgSuccess('删除成功')
|
||||
emit('refresh', res.data)
|
||||
const obj = {
|
||||
source_url_list: form.value.source_url.split('\n'),
|
||||
selector: form.value.selector
|
||||
}
|
||||
documentApi.postWebDocument(id, obj, loading).then((res: any) => {
|
||||
MsgSuccess('导入成功')
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.select-provider {
|
||||
font-size: 16px;
|
||||
color: rgba(100, 106, 115, 1);
|
||||
font-weight: 400;
|
||||
line-height: 24px;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.active-breadcrumb {
|
||||
font-size: 16px;
|
||||
color: rgba(31, 35, 41, 1);
|
||||
font-weight: 500;
|
||||
line-height: 24px;
|
||||
}
|
||||
</style>
|
||||
<style lang="scss" scoped></style>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,16 @@
|
|||
@click="router.push({ path: '/dataset/upload', query: { id: id } })"
|
||||
>上传文档</el-button
|
||||
>
|
||||
<el-button v-if="datasetDetail.type === '1'" type="primary">导入文档</el-button>
|
||||
<!-- <el-button v-if="datasetDetail.type === '1'">批量同步</el-button> -->
|
||||
<el-button :disabled="multipleSelection.length === 0" @click="deleteMulDocument"
|
||||
<el-button v-if="datasetDetail.type === '1'" type="primary" @click="importDoc"
|
||||
>导入文档</el-button
|
||||
>
|
||||
<el-button
|
||||
@click="syncMulDocument"
|
||||
:disabled="multipleSelection.length === 0"
|
||||
v-if="datasetDetail.type === '1'"
|
||||
>批量同步</el-button
|
||||
>
|
||||
<el-button @click="deleteMulDocument" :disabled="multipleSelection.length === 0"
|
||||
>批量删除</el-button
|
||||
>
|
||||
</div>
|
||||
|
|
@ -126,7 +133,9 @@
|
|||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item icon="Setting">设置</el-dropdown-item>
|
||||
<el-dropdown-item icon="Setting" @click="settingDoc(row)"
|
||||
>设置</el-dropdown-item
|
||||
>
|
||||
<el-dropdown-item icon="Delete" @click.stop="deleteDocument(row)"
|
||||
>删除</el-dropdown-item
|
||||
>
|
||||
|
|
@ -139,6 +148,7 @@
|
|||
</el-table-column>
|
||||
</app-table>
|
||||
</div>
|
||||
<ImportDocumentDialog ref="ImportDocumentDialogRef" :title="title" @refresh="refresh" />
|
||||
</div>
|
||||
</LayoutContainer>
|
||||
</template>
|
||||
|
|
@ -147,6 +157,7 @@ import { ref, onMounted, reactive, onBeforeUnmount } from 'vue'
|
|||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElTable } from 'element-plus'
|
||||
import documentApi from '@/api/document'
|
||||
import ImportDocumentDialog from './component/ImportDocumentDialog.vue'
|
||||
import { numberFormat } from '@/utils/utils'
|
||||
import { datetimeFormat } from '@/utils/time'
|
||||
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
||||
|
|
@ -171,8 +182,19 @@ const paginationConfig = reactive({
|
|||
total: 0
|
||||
})
|
||||
|
||||
const ImportDocumentDialogRef = ref()
|
||||
const multipleTableRef = ref<InstanceType<typeof ElTable>>()
|
||||
const multipleSelection = ref<any[]>([])
|
||||
const title = ref('')
|
||||
|
||||
function importDoc() {
|
||||
title.value = '导入文档'
|
||||
ImportDocumentDialogRef.value.open()
|
||||
}
|
||||
function settingDoc(row: any) {
|
||||
title.value = '设置'
|
||||
ImportDocumentDialogRef.value.open(row)
|
||||
}
|
||||
|
||||
const handleSelectionChange = (val: any[]) => {
|
||||
multipleSelection.value = val
|
||||
|
|
@ -201,9 +223,22 @@ const closeInterval = () => {
|
|||
}
|
||||
}
|
||||
function refreshDocument(row: any) {
|
||||
documentApi.putDocumentRefresh(row.dataset_id, row.id).then((res) => {
|
||||
getList()
|
||||
})
|
||||
if (row.type === '1') {
|
||||
MsgConfirm(`确认同步文档?`, `同步将删除已有数据重新获取新数据,请谨慎操作。`, {
|
||||
confirmButtonText: '同步',
|
||||
confirmButtonClass: 'danger'
|
||||
})
|
||||
.then(() => {
|
||||
documentApi.putDocumentRefresh(row.dataset_id, row.id).then((res) => {
|
||||
getList()
|
||||
})
|
||||
})
|
||||
.catch(() => {})
|
||||
} else {
|
||||
documentApi.putDocumentRefresh(row.dataset_id, row.id).then((res) => {
|
||||
getList()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function rowClickHandle(row: any) {
|
||||
|
|
@ -227,6 +262,19 @@ function creatQuickHandle(val: string) {
|
|||
})
|
||||
}
|
||||
|
||||
function syncMulDocument() {
|
||||
const arr: string[] = []
|
||||
multipleSelection.value.map((v) => {
|
||||
if (v) {
|
||||
arr.push(v.id)
|
||||
}
|
||||
})
|
||||
documentApi.delMulSyncDocument(id, arr, loading).then(() => {
|
||||
MsgSuccess('批量同步成功')
|
||||
getList()
|
||||
})
|
||||
}
|
||||
|
||||
function deleteMulDocument() {
|
||||
const arr: string[] = []
|
||||
multipleSelection.value.map((v) => {
|
||||
|
|
@ -235,7 +283,7 @@ function deleteMulDocument() {
|
|||
}
|
||||
})
|
||||
documentApi.delMulDocument(id, arr, loading).then(() => {
|
||||
MsgSuccess('删除成功')
|
||||
MsgSuccess('批量删除成功')
|
||||
getList()
|
||||
})
|
||||
}
|
||||
|
|
@ -323,6 +371,11 @@ function getDetail() {
|
|||
})
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
paginationConfig.current_page = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
getList()
|
||||
|
|
|
|||
Loading…
Reference in New Issue