fix: 回退Grid布局恢复flex并列,保留二级分组映射,空大类隐藏
This commit is contained in:
@@ -6,15 +6,20 @@
|
||||
* - 节点高亮 + 联动回调
|
||||
* - 「全部展开 / 全部收起」操作按钮
|
||||
*
|
||||
* 数据分组逻辑完全委托给 useKnowledgeGrouping(数据分组层),
|
||||
* 数据分组逻辑完全委托给后端 get_grouped_items(数据分组层),
|
||||
* 本组件只管交互,不感知分组的业务含义。
|
||||
*
|
||||
* 二级节点 key 格式(由 useKnowledgeGrouping 控制):
|
||||
* - 大类节点: "manuscript"
|
||||
* - 二级节点(新格式): "manuscript|author|左鑫"
|
||||
* type|二级字段名|字段值
|
||||
* 二级节点 key 格式(由后端控制):
|
||||
* - 大类节点: "manuscript"
|
||||
* - 二级节点(新格式): "manuscript|author|左鑫"
|
||||
* type|二级字段名|字段值
|
||||
* - 二级节点(出处,杂志文章): "military_report|source_detail|航空知识..."
|
||||
*
|
||||
* 将来切换分组维度时,只改 useKnowledgeGrouping,本组件只调整 key 解析逻辑(解包字段数)。
|
||||
* 回调给 KnowledgeBase:统一返回 { type, detail }
|
||||
* - 大类节点 → { type: "manuscript", detail: null }
|
||||
* - 作者二级节点 → { type: "manuscript", detail: "左鑫" }
|
||||
* - 出处二级节点 → { type: "military_report", detail: "航空知识..." }
|
||||
* (detail=author名 或 source_detail原文,与 displayedItems 过滤逻辑对齐)
|
||||
*/
|
||||
|
||||
import { useState, useCallback } from 'react'
|
||||
@@ -26,7 +31,7 @@ const { TreeNode } = Tree
|
||||
|
||||
export default function KnowledgeTree({
|
||||
treeData, // 来自 getGroupedItems() API 的原始树数据(含全部节点)
|
||||
onNodeSelect, // 选中节点时回调,参数: { key, type, secondaryField, secondaryValue } | null(全部)
|
||||
onNodeSelect, // 选中节点时回调,参数: { key, type, detail } | null(全部)
|
||||
selectedKey, // 当前选中的 key(用于高亮)
|
||||
}) {
|
||||
const [expandedKeys, setExpandedKeys] = useState(() => {
|
||||
@@ -66,9 +71,10 @@ export default function KnowledgeTree({
|
||||
const key = selectedKeys[0]
|
||||
|
||||
// 解析 key 格式:
|
||||
// "all" → 全部根节点
|
||||
// "manuscript" → 大类节点
|
||||
// "manuscript|author|左鑫" → 二级节点(type|二级字段名|字段值)
|
||||
// "all" → 全部根节点
|
||||
// "manuscript" → 大类节点
|
||||
// "manuscript|author|左鑫" → 二级节点(新格式:type|fieldName|fieldValue)
|
||||
// "military_report|source_detail|..." → 二级节点(出处)
|
||||
if (key === 'all') {
|
||||
onNodeSelect(null)
|
||||
return
|
||||
@@ -77,15 +83,11 @@ export default function KnowledgeTree({
|
||||
const parts = key.split('|')
|
||||
if (parts.length === 1) {
|
||||
// 大类节点
|
||||
onNodeSelect({ key, type: parts[0], secondaryField: null, secondaryValue: null })
|
||||
onNodeSelect({ key, type: parts[0], detail: null })
|
||||
} else {
|
||||
// 二级节点:新格式 type|fieldName|fieldValue
|
||||
onNodeSelect({
|
||||
key,
|
||||
type: parts[0],
|
||||
secondaryField: parts[1],
|
||||
secondaryValue: parts[2],
|
||||
})
|
||||
// 二级节点:parts[0]=type, parts[1]=字段名(废弃不用), parts[2]=字段值
|
||||
// 统一以 parts[2] 作为 detail(作者名 或 出处名),与 displayedItems 过滤逻辑对齐
|
||||
onNodeSelect({ key, type: parts[0], detail: parts[2] })
|
||||
}
|
||||
}, [onNodeSelect])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user