Skip to content

Commit 92518e5

Browse files
committed
fix(GraphView): 修复文件上传和模态框关闭逻辑
添加文件上传状态验证和错误处理 修复模态框关闭时未清空文件列表的问题 统一搜索框的占位文本 移除不再使用的说明弹窗组件
1 parent e04213f commit 92518e5

File tree

1 file changed

+70
-43
lines changed

1 file changed

+70
-43
lines changed

web/src/views/GraphView.vue

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
:options="state.dbOptions"
2626
@change="handleDbChange"
2727
:loading="state.loadingDatabases"
28+
mode="combobox"
29+
placeholder="选择或输入KB ID"
2830
/>
2931
</div>
3032
<!-- <a-button type="default" @click="openLink('http://localhost:7474/')" :icon="h(GlobalOutlined)">
@@ -58,7 +60,7 @@
5860
<div class="actions-left">
5961
<a-input
6062
v-model:value="state.searchInput"
61-
:placeholder="isNeo4j ? '输入要查询的实体' : '输入要查询的实体 (*为全部)'"
63+
placeholder="输入要查询的实体 (*为全部)"
6264
style="width: 300px"
6365
@keydown.enter="onSearch"
6466
allow-clear
@@ -125,9 +127,10 @@
125127
<a-modal
126128
:open="state.showModal" title="上传文件"
127129
@ok="addDocumentByFile"
128-
@cancel="() => state.showModal = false"
130+
@cancel="handleModalCancel"
129131
ok-text="添加到图数据库" cancel-text="取消"
130-
:confirm-loading="state.processing">
132+
:confirm-loading="state.processing"
133+
:ok-button-props="{ disabled: !hasValidFile }">
131134
<div class="upload">
132135
<div class="note">
133136
<p>上传的文件内容参考 test/data/A_Dream_of_Red_Mansions_tiny.jsonl 中的格式:</p>
@@ -177,34 +180,6 @@
177180
</div>
178181
</div>
179182
</a-modal>
180-
181-
<!-- 说明弹窗 -->
182-
<a-modal
183-
:open="state.showInfoModal"
184-
title="图数据库说明"
185-
@cancel="() => state.showInfoModal = false"
186-
:footer="null"
187-
width="600px"
188-
>
189-
<div class="info-content" v-if="isNeo4j">
190-
<p>本页面展示的是 Neo4j 图数据库中的知识图谱信息。</p>
191-
<p>具体展示内容包括:</p>
192-
<ul>
193-
<li>带有 <code>Entity</code> 标签的节点</li>
194-
<li>带有 <code>RELATION</code> 类型的关系边</li>
195-
</ul>
196-
<p>注意:</p>
197-
<ul>
198-
<li>这里仅展示用户上传的实体和关系,不包含知识库中自动创建的图谱。</li>
199-
<li>查询逻辑基于 <code>graphbase.py</code> 中的 <code>get_sample_nodes</code> 方法实现。</li>
200-
</ul>
201-
</div>
202-
<div class="info-content" v-else>
203-
<p>本页面展示的是 LightRAG 知识库生成的图谱信息。</p>
204-
<p>数据来源于选定的知识库实例。</p>
205-
<p>支持通过实体名称进行模糊搜索,输入 "*" 可查看采样全图。</p>
206-
</div>
207-
</a-modal>
208183
</div>
209184
</template>
210185

@@ -252,7 +227,21 @@ const state = reactive({
252227
lightragStats: null,
253228
})
254229
255-
const isNeo4j = computed(() => state.selectedDbId === 'neo4j');
230+
const isNeo4j = computed(() => {
231+
// 当 selectedDbId 是 'neo4j' 时,或者以 'kb_' 开头时,我们认为它是 Neo4j 驱动的
232+
// 但是对于 kb_ 开头的,我们可能想要使用 LightRAGInfoPanel 的展示风格(因为它有 stats)
233+
// 或者复用 GraphInfoPanel。
234+
// GraphInfoPanel 是为 'neo4j' 全局图设计的,包含了 model matching 检查等。
235+
// KBs (kb_*) 使用 Neo4j 存储,但逻辑上更接近 LightRAG 的"知识库"概念。
236+
// 为了让 LightRAGInfoPanel 能够展示 stats (get_stats 已经更新支持 kb_),
237+
// 我们这里让 kb_ ID 返回 false,这样会进入 LightRAGInfoPanel 分支。
238+
return state.selectedDbId === 'neo4j';
239+
});
240+
241+
// 检查是否有有效的已上传文件
242+
const hasValidFile = computed(() => {
243+
return fileList.value.some(file => file.status === 'done' && file.response?.file_path);
244+
});
256245
257246
// 计算未索引节点数量
258247
const unindexedCount = computed(() => {
@@ -293,7 +282,7 @@ const handleDbChange = () => {
293282
if (isNeo4j.value) {
294283
loadGraphInfo();
295284
} else {
296-
// Also load stats for LightRAG
285+
// Also load stats for LightRAG or KB
297286
loadLightRAGStats();
298287
}
299288
loadSampleNodes();
@@ -323,13 +312,37 @@ const loadGraphInfo = () => {
323312
}
324313
325314
const addDocumentByFile = () => {
315+
// 使用计算属性验证文件
316+
if (!hasValidFile.value) {
317+
message.error('请先等待文件上传完成')
318+
return
319+
}
320+
326321
state.processing = true
327-
const files = fileList.value.filter(file => file.status === 'done').map(file => file.response.file_path)
328-
neo4jApi.addEntities(files[0])
322+
323+
// 获取已上传的文件路径
324+
const uploadedFile = fileList.value.find(file => file.status === 'done' && file.response?.file_path);
325+
const filePath = uploadedFile?.response?.file_path;
326+
327+
// 再次验证文件路径
328+
if (!filePath) {
329+
message.error('文件路径获取失败,请重新上传文件')
330+
state.processing = false
331+
return
332+
}
333+
334+
neo4jApi.addEntities(filePath)
329335
.then((data) => {
330336
if (data.status === 'success') {
331337
message.success(data.message);
332338
state.showModal = false;
339+
// 清空文件列表
340+
fileList.value = [];
341+
// 刷新图谱数据
342+
setTimeout(() => {
343+
loadGraphInfo();
344+
loadSampleNodes();
345+
}, 500);
333346
} else {
334347
throw new Error(data.message);
335348
}
@@ -372,11 +385,6 @@ const onSearch = () => {
372385
// 可选:提示模型不一致
373386
}
374387
375-
if (!state.searchInput && isNeo4j.value) {
376-
message.error('请输入要查询的实体')
377-
return
378-
}
379-
380388
state.searchLoading = true
381389
382390
unifiedApi.getSubgraph({
@@ -409,16 +417,35 @@ onMounted(async () => {
409417
loadSampleNodes();
410418
});
411419
412-
const handleFileUpload = (event) => {
413-
console.log(event)
414-
console.log(fileList.value)
420+
const handleFileUpload = ({ file, fileList: newFileList }) => {
421+
// 更新文件列表
422+
fileList.value = newFileList;
423+
424+
// 如果上传失败,显示错误信息
425+
if (file.status === 'error') {
426+
message.error(`文件上传失败: ${file.name}`);
427+
}
428+
429+
// 如果上传成功,显示成功信息
430+
if (file.status === 'done' && file.response?.file_path) {
431+
message.success(`文件上传成功: ${file.name}`);
432+
}
433+
434+
console.log('File upload status:', file.status, file.name);
435+
console.log('File list:', fileList.value);
415436
}
416437
417438
const handleDrop = (event) => {
418439
console.log(event)
419440
console.log(fileList.value)
420441
}
421442
443+
const handleModalCancel = () => {
444+
state.showModal = false;
445+
// 重置文件列表
446+
fileList.value = [];
447+
};
448+
422449
const graphStatusClass = computed(() => {
423450
if (state.loadingGraphInfo) return 'loading';
424451
return graphInfo.value?.status === 'open' ? 'open' : 'closed';

0 commit comments

Comments
 (0)