fix(应用): 修复对话日志添加的知识库的相关问题

This commit is contained in:
wxg0103 2024-11-19 16:31:08 +08:00 committed by wxg
parent 4fd6884ad6
commit ec4f844abd
2 changed files with 42 additions and 38 deletions

View File

@ -216,33 +216,36 @@ const onUploadImg = async (files: any, callback: any) => {
callback(res.map((item) => item.data)) callback(res.map((item) => item.data))
} }
function changeDataset(id: string) { function changeDataset(dataset_id: string) {
if (user.userInfo) { localStorage.setItem(id + 'chat_dataset_id', dataset_id)
localStorage.setItem(user.userInfo.id + 'chat_dataset_id', id)
}
form.value.document_id = '' form.value.document_id = ''
getDocument(id) getDocument(dataset_id)
} }
function changeDocument(id: string) { function changeDocument(document_id: string) {
if (user.userInfo) { localStorage.setItem(id + 'chat_document_id', document_id)
localStorage.setItem(user.userInfo.id + 'chat_document_id', id)
}
} }
function getDocument(id: string) { function getDocument(dataset_id: string) {
document.asyncGetAllDocument(id, loading).then((res: any) => { document.asyncGetAllDocument(dataset_id, loading).then((res: any) => {
documentList.value = res.data documentList.value = res.data
if (localStorage.getItem(id + 'chat_document_id')) {
form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string
}
if (!documentList.value.find((v) => v.id === form.value.document_id)) {
form.value.document_id = ''
}
}) })
} }
function getDataset() { function getDataset() {
application.asyncGetApplicationDataset(id, loading).then((res: any) => { application.asyncGetApplicationDataset(id, loading).then((res: any) => {
datasetList.value = res.data datasetList.value = res.data
if (localStorage.getItem(user.userInfo?.id + 'chat_dataset_id')) { if (localStorage.getItem(id + 'chat_dataset_id')) {
form.value.dataset_id = localStorage.getItem(user.userInfo?.id + 'chat_dataset_id') as string form.value.dataset_id = localStorage.getItem(id + 'chat_dataset_id') as string
if (!datasetList.value.find((v) => v.id === form.value.dataset_id)) { if (!datasetList.value.find((v) => v.id === form.value.dataset_id)) {
form.value.dataset_id = '' form.value.dataset_id = ''
form.value.document_id = ''
} else { } else {
getDocument(form.value.dataset_id) getDocument(form.value.dataset_id)
} }
@ -252,9 +255,6 @@ function getDataset() {
const open = (data: any) => { const open = (data: any) => {
getDataset() getDataset()
if (localStorage.getItem(user.userInfo?.id + 'chat_document_id')) {
form.value.document_id = localStorage.getItem(user.userInfo?.id + 'chat_document_id') as string
}
form.value.chat_id = data.chat_id form.value.chat_id = data.chat_id
form.value.record_id = data.id form.value.record_id = data.id
form.value.problem_text = data.problem_text ? data.problem_text.substring(0, 256) : '' form.value.problem_text = data.problem_text ? data.problem_text.substring(0, 256) : ''

View File

@ -33,8 +33,8 @@
<el-button @click="dialogVisible = true">清除策略</el-button> <el-button @click="dialogVisible = true">清除策略</el-button>
<el-button @click="exportLog">导出</el-button> <el-button @click="exportLog">导出</el-button>
<el-button @click="openDocumentDialog" :disabled="multipleSelection.length === 0" <el-button @click="openDocumentDialog" :disabled="multipleSelection.length === 0"
>添加至知识库</el-button >添加至知识库
> </el-button>
</div> </div>
</div> </div>
@ -171,9 +171,9 @@
<span>天之前的对话记录</span> <span>天之前的对话记录</span>
<template #footer> <template #footer>
<div class="dialog-footer" style="margin-top: 16px"> <div class="dialog-footer" style="margin-top: 16px">
<el-button @click="dialogVisible = false">{{ <el-button @click="dialogVisible = false"
$t('layout.topbar.avatar.dialog.cancel') >{{ $t('layout.topbar.avatar.dialog.cancel') }}
}}</el-button> </el-button>
<el-button type="primary" @click="saveCleanTime"> <el-button type="primary" @click="saveCleanTime">
{{ $t('layout.topbar.avatar.dialog.save') }} {{ $t('layout.topbar.avatar.dialog.save') }}
</el-button> </el-button>
@ -253,7 +253,7 @@
</el-form> </el-form>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button> <el-button @click.prevent="documentDialogVisible = false"> 取消 </el-button>
<el-button type="primary" @click="submitForm(formRef)" :loading="documentLoading"> <el-button type="primary" @click="submitForm(formRef)" :loading="documentLoading">
保存 保存
</el-button> </el-button>
@ -365,6 +365,7 @@ const rules = reactive<FormRules>({
const optionLoading = ref(false) const optionLoading = ref(false)
const documentList = ref<any[]>([]) const documentList = ref<any[]>([])
function filterChange(val: string) { function filterChange(val: string) {
if (val === 'clear') { if (val === 'clear') {
filter.value = cloneDeep(defaultFilter) filter.value = cloneDeep(defaultFilter)
@ -487,6 +488,7 @@ function getDetail() {
days.value = res.data.clean_time days.value = res.data.clean_time
}) })
} }
const exportLog = () => { const exportLog = () => {
const arr: string[] = [] const arr: string[] = []
multipleSelection.value.map((v) => { multipleSelection.value.map((v) => {
@ -542,28 +544,26 @@ function saveCleanTime() {
}) })
} }
function changeDataset(id: string) { function changeDataset(dataset_id: string) {
if (user.userInfo) { localStorage.setItem(id + 'chat_dataset_id', dataset_id)
localStorage.setItem(user.userInfo.id + 'chat_dataset_id', id)
}
form.value.document_id = '' form.value.document_id = ''
getDocument(id) getDocument(dataset_id)
} }
function changeDocument(id: string) { function changeDocument(document_id: string) {
if (user.userInfo) { localStorage.setItem(id + 'chat_document_id', document_id)
localStorage.setItem(user.userInfo.id + 'chat_document_id', id)
}
} }
const datasetList = ref<any[]>([]) const datasetList = ref<any[]>([])
function getDataset() { function getDataset() {
application.asyncGetApplicationDataset(id, documentLoading).then((res: any) => { application.asyncGetApplicationDataset(id, documentLoading).then((res: any) => {
datasetList.value = res.data datasetList.value = res.data
if (localStorage.getItem(user.userInfo?.id + 'chat_dataset_id')) { if (localStorage.getItem(id + 'chat_dataset_id')) {
form.value.dataset_id = localStorage.getItem(user.userInfo?.id + 'chat_dataset_id') as string form.value.dataset_id = localStorage.getItem(id + 'chat_dataset_id') as string
if (!datasetList.value.find((v) => v.id === form.value.dataset_id)) { if (!datasetList.value.find((v) => v.id === form.value.dataset_id)) {
form.value.dataset_id = '' form.value.dataset_id = ''
form.value.document_id = ''
} else { } else {
getDocument(form.value.dataset_id) getDocument(form.value.dataset_id)
} }
@ -594,20 +594,24 @@ const submitForm = async (formEl: FormInstance | undefined) => {
}) })
} }
function getDocument(id: string) { function getDocument(dataset_id: string) {
document.asyncGetAllDocument(id, documentLoading).then((res: any) => { document.asyncGetAllDocument(dataset_id, documentLoading).then((res: any) => {
documentList.value = res.data documentList.value = res.data
if (localStorage.getItem(id + 'chat_document_id')) {
form.value.document_id = localStorage.getItem(id + 'chat_document_id') as string
}
if (!documentList.value.find((v) => v.id === form.value.document_id)) {
form.value.document_id = ''
}
}) })
} }
function openDocumentDialog() { function openDocumentDialog() {
getDataset() getDataset()
if (localStorage.getItem(user.userInfo?.id + 'chat_document_id')) {
form.value.document_id = localStorage.getItem(user.userInfo?.id + 'chat_document_id') as string
}
formRef.value?.clearValidate() formRef.value?.clearValidate()
documentDialogVisible.value = true documentDialogVisible.value = true
} }
onMounted(() => { onMounted(() => {
changeDayHandle(history_day.value) changeDayHandle(history_day.value)
getDetail() getDetail()