Skip to content

Commit 7df10af

Browse files
committed
refactor(ui): 优化知识图谱界面布局和交互
调整图谱布局参数提升渲染效果 重构顶部操作栏布局,改进搜索框样式和交互 移除冗余的说明按钮
1 parent 2e9fd9c commit 7df10af

File tree

3 files changed

+84
-38
lines changed

3 files changed

+84
-38
lines changed

web/src/components/GraphCanvas.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ const MAX_RETRIES = 5
6868
const defaultLayout = {
6969
type: 'd3-force',
7070
preventOverlap: true,
71-
// 性能友好参数(参考 GraphView.vue)
7271
alphaDecay: 0.1,
7372
alphaMin: 0.01,
74-
velocityDecay: 0.7,
75-
iterations: 100,
73+
velocityDecay: 0.6,
74+
iterations: 150,
7675
force: {
7776
center: { x: 0.5, y: 0.5, strength: 0.1 },
78-
charge: { strength: -400, distanceMax: 400 },
77+
charge: { strength: -400, distanceMax: 600 },
7978
link: { distance: 100, strength: 0.8 },
8079
},
8180
collide: { radius: 40, strength: 0.8, iterations: 3 },
@@ -217,9 +216,6 @@ function initGraph() {
217216
const { target } = evt
218217
// 获取节点ID
219218
const nodeId = target.id
220-
// 从 graph data 中找到对应的节点数据
221-
// 注意:G6 v5 的事件对象结构可能有所不同,这里假设 target.id 是节点ID
222-
// 也可以通过 graphInstance.getNodeData(nodeId) 获取
223219
const nodeData = graphInstance.getNodeData(nodeId)
224220
emit('node-click', nodeData)
225221
})
@@ -271,7 +267,7 @@ function setGraphData() {
271267
emit('data-rendered')
272268
console.log('图谱渲染完成,布局已稳定')
273269
}, 1500)
274-
}, 10) // 等待 1ms 确保布局完成
270+
}, 10) // 等待 10ms 确保布局完成
275271
}
276272
277273
// 关键词高亮功能

web/src/components/KnowledgeGraphSection.vue

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,34 @@
1818
>
1919
<template #top>
2020
<div class="compact-actions">
21-
<a-input-search
22-
v-model:value="searchInput"
23-
placeholder="搜索实体"
24-
style="width: 200px"
25-
@search="onSearch"
26-
allow-clear
27-
/>
28-
<a-button
29-
type="text"
30-
:icon="h(ReloadOutlined)"
31-
:loading="graph.fetching"
32-
@click="loadGraph"
33-
title="刷新"
34-
/>
35-
<a-button
36-
type="text"
37-
:icon="h(SettingOutlined)"
38-
@click="showSettings = true"
39-
title="设置"
40-
/>
21+
<div class="actions-left">
22+
<a-input
23+
v-model:value="searchInput"
24+
placeholder="搜索实体"
25+
style="width: 240px"
26+
@keydown.enter="onSearch"
27+
allow-clear
28+
>
29+
<template #suffix>
30+
<component :is="graph.fetching ? LoadingOutlined : SearchOutlined" @click="onSearch" />
31+
</template>
32+
</a-input>
33+
<a-button
34+
class="action-btn"
35+
:icon="h(ReloadOutlined)"
36+
:loading="graph.fetching"
37+
@click="loadGraph"
38+
title="刷新"
39+
/>
40+
</div>
41+
<div class="actions-right">
42+
<a-button
43+
class="action-btn"
44+
:icon="h(SettingOutlined)"
45+
@click="showSettings = true"
46+
title="设置"
47+
/>
48+
</div>
4149
</div>
4250
</template>
4351
</GraphCanvas>
@@ -94,7 +102,7 @@
94102
<script setup>
95103
import { ref, computed, watch, nextTick, onUnmounted, reactive, h } from 'vue';
96104
import { useDatabaseStore } from '@/stores/database';
97-
import { ReloadOutlined, SettingOutlined } from '@ant-design/icons-vue';
105+
import { ReloadOutlined, SettingOutlined, SearchOutlined, LoadingOutlined } from '@ant-design/icons-vue';
98106
import GraphCanvas from '@/components/GraphCanvas.vue';
99107
import GraphDetailPanel from '@/components/GraphDetailPanel.vue';
100108
import { getKbTypeLabel } from '@/utils/kb_utils';
@@ -241,14 +249,59 @@ onUnmounted(() => {
241249
position: absolute;
242250
top: 10px;
243251
left: 10px;
252+
right: 10px;
244253
display: flex;
254+
justify-content: space-between;
245255
align-items: center;
246-
gap: 8px;
247-
background: var(--color-trans-light);
248-
backdrop-filter: blur(4px);
249-
padding: 6px;
250-
border-radius: 8px;
251-
box-shadow: 0 0px 4px var(--shadow-3);
256+
pointer-events: none; /* Let clicks pass through empty areas */
257+
258+
.actions-left, .actions-right {
259+
pointer-events: auto; /* Re-enable clicks for buttons/inputs */
260+
display: flex;
261+
align-items: center;
262+
gap: 4px;
263+
background: var(--color-trans-light);
264+
backdrop-filter: blur(4px);
265+
padding: 2px;
266+
border-radius: 8px;
267+
box-shadow: 0 0px 4px var(--shadow-3);
268+
}
269+
270+
:deep(.ant-input-affix-wrapper) {
271+
padding: 4px 11px;
272+
border-radius: 6px;
273+
border-color: transparent;
274+
box-shadow: none;
275+
background: rgba(255, 255, 255, 0.6);
276+
277+
&:hover, &:focus, &-focused {
278+
background: #fff;
279+
border-color: var(--primary-color);
280+
}
281+
282+
input {
283+
background: transparent;
284+
}
285+
}
286+
287+
.action-btn {
288+
width: 32px;
289+
height: 32px;
290+
padding: 0;
291+
display: flex;
292+
align-items: center;
293+
justify-content: center;
294+
border: none;
295+
background: transparent;
296+
color: var(--gray-600);
297+
border-radius: 6px;
298+
box-shadow: none;
299+
300+
&:hover {
301+
background: rgba(0, 0, 0, 0.05);
302+
color: var(--primary-color);
303+
}
304+
}
252305
}
253306
254307
.graph-disabled {

web/src/views/GraphView.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@
8686
<a-button type="default" @click="exportGraphData" :icon="h(ExportOutlined)">
8787
导出数据
8888
</a-button>
89-
<a-button type="default" @click="state.showInfoModal = true" :icon="h(InfoCircleOutlined)">
90-
说明
91-
</a-button>
9289
</div>
9390
</div>
9491
</template>

0 commit comments

Comments
 (0)