UnisKB/ui/src/views/paragraph/component/SelectDocumentDialog.vue

159 lines
4.2 KiB
Vue
Raw Normal View History

2025-05-30 06:34:24 +00:00
<template>
<el-dialog
2025-06-11 13:02:26 +00:00
:title="`${$t('views.chatLog.selectKnowledge')}/${$t('common.fileUpload.document')}`"
2025-05-30 06:34:24 +00:00
v-model="dialogVisible"
width="500"
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<el-form
ref="formRef"
:model="form"
label-position="top"
require-asterisk-position="right"
:rules="rules"
@submit.prevent
>
2025-06-11 13:02:26 +00:00
<el-form-item :label="$t('views.chatLog.selectKnowledge')" prop="dataset_id">
2025-05-30 06:34:24 +00:00
<el-select
v-model="form.dataset_id"
filterable
2025-06-11 13:02:26 +00:00
:placeholder="$t('views.chatLog.selectKnowledgePlaceholder')"
2025-05-30 06:34:24 +00:00
:loading="optionLoading"
@change="changeDataset"
>
<el-option v-for="item in datasetList" :key="item.id" :label="item.name" :value="item.id">
<span class="flex align-center">
2025-06-11 11:15:17 +00:00
<KnowledgeIcon v-if="!item.dataset_id" :type="item.type" />
2025-05-30 06:34:24 +00:00
{{ item.name }}
</span>
</el-option>
</el-select>
</el-form-item>
2025-06-11 11:15:17 +00:00
<el-form-item :label="$t('views.chatLog.saveToDocument')" prop="document_id">
2025-05-30 06:34:24 +00:00
<el-select
v-model="form.document_id"
filterable
2025-06-11 11:15:17 +00:00
:placeholder="$t('views.chatLog.documentPlaceholder')"
2025-05-30 06:34:24 +00:00
:loading="optionLoading"
>
<el-option
v-for="item in documentList"
:key="item.id"
:label="item.name"
:value="item.id"
>
{{ item.name }}
</el-option>
</el-select>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button>
<el-button type="primary" @click="submitForm(formRef)" :loading="loading">
{{ $t('views.document.setting.migration') }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, watch, reactive } from 'vue'
import { useRoute } from 'vue-router'
import type { FormInstance, FormRules } from 'element-plus'
import paragraphApi from '@/api/knowledge/paragraph'
import useStore from '@/stores'
import { t } from '@/locales'
2025-06-09 10:54:13 +00:00
const { knowledge, document } = useStore()
2025-05-30 06:34:24 +00:00
const route = useRoute()
const {
2025-06-11 11:15:17 +00:00
params: { id, documentId },
2025-05-30 06:34:24 +00:00
} = route as any
const emit = defineEmits(['refresh'])
const formRef = ref()
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
const form = ref<any>({
dataset_id: '',
2025-06-11 11:15:17 +00:00
document_id: '',
2025-05-30 06:34:24 +00:00
})
const rules = reactive<FormRules>({
dataset_id: [
2025-06-11 13:02:26 +00:00
{ required: true, message: t('views.chatLog.selectKnowledgePlaceholder'), trigger: 'change' },
2025-05-30 06:34:24 +00:00
],
2025-06-11 11:15:17 +00:00
document_id: [{ required: true, message: t('views.chatLog.documentPlaceholder'), trigger: 'change' }],
2025-05-30 06:34:24 +00:00
})
const datasetList = ref<any[]>([])
const documentList = ref<any[]>([])
const optionLoading = ref(false)
const paragraphList = ref<string[]>([])
watch(dialogVisible, (bool) => {
if (!bool) {
form.value = {
dataset_id: '',
2025-06-11 11:15:17 +00:00
document_id: '',
2025-05-30 06:34:24 +00:00
}
datasetList.value = []
documentList.value = []
paragraphList.value = []
formRef.value?.clearValidate()
}
})
function changeDataset(id: string) {
form.value.document_id = ''
getDocument(id)
}
function getDocument(id: string) {
document.asyncGetAllDocument(id, loading).then((res: any) => {
documentList.value = res.data?.filter((v: any) => v.id !== documentId)
})
}
function getDataset() {
2025-06-19 10:39:52 +00:00
knowledge.asyncGetFolderKnowledge(loading).then((res: any) => {
2025-05-30 06:34:24 +00:00
datasetList.value = res.data
})
}
const open = (list: any) => {
paragraphList.value = list
getDataset()
formRef.value?.clearValidate()
dialogVisible.value = true
}
const submitForm = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid, fields) => {
if (valid) {
paragraphApi
.putMigrateMulParagraph(
id,
documentId,
form.value.dataset_id,
form.value.document_id,
paragraphList.value,
2025-06-11 11:15:17 +00:00
loading,
2025-05-30 06:34:24 +00:00
)
.then(() => {
emit('refresh')
dialogVisible.value = false
})
}
})
}
defineExpose({ open })
</script>
<style lang="scss" scoped></style>