Browse Source

all

hanyuqing
hanyuqing 3 months ago
parent
commit
b1c54e4435
  1. 2
      controller/GraphController.py
  2. 4
      service/GraphService.py
  3. 17
      util/neo4j_utils.py
  4. BIN
      vue/src/assets/图标5.png
  5. 3
      vue/src/components/Menu.vue
  6. 37
      vue/src/system/GraphDemo.vue

2
controller/GraphController.py

@ -148,6 +148,8 @@ def get_graph(req):
headers={"Content-Type": "text/plain; charset=utf-8"}
)
except Exception as e:
error_trace = traceback.format_exc()
print("Error in /api/tree:", error_trace)
return jsonify({"error": str(e)}), 500
@app.get("/api/drug-tree")
def get_drug_tree():

4
service/GraphService.py

@ -118,6 +118,10 @@ def build_g6_subgraph_by_props(
center_nodes = neo4j_util.find_nodes_with_element_id(node_label, node_properties)
if center_nodes:
n = center_nodes[0]
print("sssssssss")
print(center_nodes)
if "labels" in n and n["labels"]:
n["label"] = n["labels"][0]
node_dict[n["id"]] = n
nodes = list(node_dict.values())

17
util/neo4j_utils.py

@ -141,8 +141,8 @@ class Neo4jUtil:
params = {f"prop_{k}": v for k, v in properties.items()}
cypher += f" WHERE {where_clause}"
cypher += " RETURN elementId(n) AS id, n{.*} AS props"
# cypher += " RETURN elementId(n) AS id, n{.*} AS props"
cypher += " RETURN elementId(n) AS id, labels(n) AS labels, n{.*} AS props"
raw = self.execute_read(cypher, params)
return [self._merge_id_and_props(row) for row in raw]
@ -598,10 +598,15 @@ class Neo4jUtil:
# ==================== 内部辅助方法 ====================
def _merge_id_and_props(self, row: Dict[str, Any]) -> Dict[str, Any]:
"""合并 id 和 props"""
props = dict(row.get("props", {}))
props["id"] = row["id"]
return props
"""
elementIdlabels props 合并为一个扁平字典
"""
result = {
"id": row["id"],
"labels": row["labels"], # 保留标签列表,如 ["Disease"]
**row["props"] # 展开所有属性(name, nodeId 等)
}
return result
def _enrich_relationship(self, row: Dict[str, Any]) -> Dict[str, Any]:
"""格式化关系结果"""

BIN
vue/src/assets/图标5.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

3
vue/src/components/Menu.vue

@ -65,6 +65,7 @@ import i1 from '@/assets/图标1.png';
import i2 from '@/assets/图标2.png';
import i3 from '@/assets/图标3.png';
import i4 from '@/assets/图标4.png';
import i5 from '@/assets/图标5.png';
import { getUserProfile } from "@/api/profile";
const router = useRouter();
@ -102,7 +103,7 @@ const menuItems = [
{ name: '知识图谱构建', path: '/kg-builder', icon: i2 },
{ name: '知识图谱问答', path: '/kg-qa', icon: i3 },
{ name: '知识图谱数据', path: '/kg-data', icon: i4 },
{ name: '图谱样式工具', path: '/kg-style', icon: i4 }
{ name: '图谱样式工具', path: '/kg-style', icon: i5 }
];
const handleMenuClick = (i) => {

37
vue/src/system/GraphDemo.vue

@ -27,6 +27,7 @@
<section class="main-content">
<div class="disease-container">
<div class="disease-header" :style="headerStyle">
<div style="display: flex;align-items: center;">
<div class="d-title"><img :src="iconSrc" class="d-icon"/>
<span v-if="typeRadio=== 'Disease'">疾病信息</span>
<span v-if="typeRadio=== 'Drug'">药品信息</span>
@ -37,6 +38,17 @@
<div v-if="typeRadio=== 'Check'" class="d-count" :style="headerLabel">{{checkCount.toLocaleString()}}</div>
</div>
<div >
<div class="select-container">
<select name="options" id="mySelect">
<option value="1">疾病</option>
<option value="2">药品</option>
<option value="3">检查</option>
</select>
<img src="../assets/下拉.png" style="width: 32px"/>
</div>
</div>
</div>
<div>
<el-radio-group v-model="typeRadio" @change="changeTree">
<el-radio
value="Disease"
@ -1331,8 +1343,8 @@ button:hover {
color: #fff;
display: flex;
align-items: center;
padding: 0 15px;
justify-content: flex-start;
padding: 0 2px 0px 15px;
justify-content: space-between;
}
.d-title{
display: flex;
@ -1455,4 +1467,25 @@ button:hover {
/deep/ .radio-check .el-radio__input.is-checked+.el-radio__label {
color: #1890ff;
}
.select-container {
position: relative;
text-align: right;
display: flex;
align-items: center;
}
select {
padding: 4px 12px;
border-radius: 20px;
background-color: rgba(255, 255, 255);
font-size: 12px;
appearance: none; /* 移除默认下拉箭头 */
-webkit-appearance: none;
cursor: pointer;
height: 25px;
border: none;
}
select:focus {
outline: none;
}
</style>
Loading…
Cancel
Save