[前端+RAG] 异步上传+前端轮询自动刷新导读;PDF阅读模式合并行消除留白
This commit is contained in:
@@ -58,8 +58,8 @@
|
||||
<script setup lang='ts'>
|
||||
import {copyToClip} from "@/utils";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {fileGuidInfo} from "@/api";
|
||||
import {computed, inject, ref, type Ref} from "vue";
|
||||
import {fileGuidInfo, getFileGuide} from "@/api";
|
||||
import {inject, onBeforeUnmount, ref, watch, type Ref} from "vue";
|
||||
import MarkdownIt from "markdown-it";
|
||||
import {transforMd} from "@/utils/markdown";
|
||||
|
||||
@@ -78,9 +78,51 @@ const articleAbstract=ref('');
|
||||
const articleKeywords=ref('');
|
||||
const articleParagraph=ref('');
|
||||
|
||||
// 监听选中文件变化,更新导读内容
|
||||
import {watch} from "vue";
|
||||
// 轮询定时器
|
||||
let pollTimer: any = null;
|
||||
const PLACEHOLDER = '导读生成中';
|
||||
|
||||
const isPending = (text: string) => text && text.startsWith(PLACEHOLDER);
|
||||
|
||||
const startPolling = () => {
|
||||
stopPolling();
|
||||
pollTimer = setInterval(async () => {
|
||||
if (!selectedFile.value?.fileId) { stopPolling(); return; }
|
||||
try {
|
||||
const res = await getFileGuide(selectedFile.value.fileId);
|
||||
if (res?.code === 200 && res.data) {
|
||||
const d = res.data;
|
||||
if (!isPending(d.articleAbstract)) {
|
||||
articleAbstract.value = d.articleAbstract || '';
|
||||
let kw = d.articleKeywords || '';
|
||||
if (kw && (kw.indexOf('关键词:') > -1 || kw.indexOf('关键词:') > -1)) {
|
||||
kw = kw.substring(kw.indexOf('关键词:') + 4, kw.length);
|
||||
kw = kw.substring(kw.indexOf('关键词:') + 4, kw.length);
|
||||
}
|
||||
articleKeywords.value = kw;
|
||||
articleParagraph.value = d.articleParagraph || '';
|
||||
// 同步更新 selectedFile 让其他组件也能拿到
|
||||
if (selectedFile.value) {
|
||||
selectedFile.value.articleAbstract = d.articleAbstract;
|
||||
selectedFile.value.articleKeywords = d.articleKeywords;
|
||||
selectedFile.value.articleParagraph = d.articleParagraph;
|
||||
}
|
||||
stopPolling();
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
const stopPolling = () => {
|
||||
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
|
||||
};
|
||||
|
||||
onBeforeUnmount(() => stopPolling());
|
||||
|
||||
// 监听选中文件变化
|
||||
watch(() => selectedFile.value, (newFile) => {
|
||||
stopPolling();
|
||||
if (newFile) {
|
||||
articleAbstract.value = newFile.articleAbstract || '';
|
||||
let kw = newFile.articleKeywords || '';
|
||||
@@ -90,6 +132,10 @@ watch(() => selectedFile.value, (newFile) => {
|
||||
}
|
||||
articleKeywords.value = kw;
|
||||
articleParagraph.value = newFile.articleParagraph || '';
|
||||
// 如果是占位文字,启动轮询
|
||||
if (isPending(articleAbstract.value) || isPending(articleKeywords.value) || isPending(articleParagraph.value)) {
|
||||
startPolling();
|
||||
}
|
||||
} else {
|
||||
articleAbstract.value = '';
|
||||
articleKeywords.value = '';
|
||||
|
||||
@@ -211,7 +211,7 @@ import {onMounted, onUnmounted, ref, reactive, provide, nextTick, computed, watc
|
||||
import {
|
||||
getKnowledgeBaseList, addKnowledgeBase, editKnowledgeBase, delKnowledgeBase,
|
||||
getKnowledgeBaseContent, uploadFile, editFile, delFile, delFiles,
|
||||
downloadFile, getFileContent, addFileNote, getSize
|
||||
downloadFile, getFileContent, addFileNote, getSize, getFileGuide
|
||||
} from "@/api";
|
||||
import {withLoading} from "@/utils/loading";
|
||||
import {copyToClip, getGlobalSelectionPosition} from "@/utils";
|
||||
@@ -441,6 +441,18 @@ const handleNodeClick = async (data: any) => {
|
||||
articleParagraph: doc.articleParagraph || '暂无内容,请重试',
|
||||
fullContent: doc.context
|
||||
};
|
||||
|
||||
// 从 API 获取最新的导读数据(后台线程可能已更新 MySQL)
|
||||
try {
|
||||
const res = await getFileGuide(doc.id + '');
|
||||
if (res?.code === 200 && res.data) {
|
||||
const fresh = res.data;
|
||||
if (fresh.articleAbstract) { selectedFile.value.articleAbstract = fresh.articleAbstract; data.raw.articleAbstract = fresh.articleAbstract; }
|
||||
if (fresh.articleKeywords) { selectedFile.value.articleKeywords = fresh.articleKeywords; data.raw.articleKeywords = fresh.articleKeywords; }
|
||||
if (fresh.articleParagraph) { selectedFile.value.articleParagraph = fresh.articleParagraph; data.raw.articleParagraph = fresh.articleParagraph; }
|
||||
}
|
||||
} catch {}
|
||||
|
||||
// 根据文件类型加载内容
|
||||
readingMode.value = false;
|
||||
const ext = doc.filename?.split('.').pop()?.toLowerCase() || '';
|
||||
|
||||
Reference in New Issue
Block a user