update pay function

This commit is contained in:
2025-11-20 16:59:09 +08:00
parent 7c8310eeb6
commit 8dfd344806
3 changed files with 88 additions and 17 deletions

View File

@@ -300,8 +300,8 @@
"tags": [
"分类树"
],
"summary": "获取特定节点及其子树",
"description": "根据路径获取树中的特定节点及其所有子节点。\n\n## 使用场景\n- 懒加载:用户点击节点时动态加载子节点\n- 子树查询:获取某个分类下的所有数据\n- 面包屑导航:根据路径定位节点\n\n## 路径格式\n使用竖线(|)分隔层级,例如:\n- 一级: \"\"\n- 二级: \"钴|钴化合物\"\n- 三级: \"钴|钴化合物|硫酸钴\"\n",
"summary": "获取节点及其直接子节点(第一层)",
"description": "根据路径获取树中的特定节点,**只返回直接子节点**(不包括孙节点及更深层级)。\n\n## 功能特点\n- **分层懒加载**: 每次只返回下一层,避免一次性加载过多数据\n- **性能优化**: 减少数据传输量,提升响应速度\n- **无限层级**: 支持任意深度的节点展开\n\n## 使用场景\n- 用户点击节点时,动态加载该节点的直接子节点\n- 逐层展开树形结构\n- 按需加载,提升用户体验\n\n## 返回数据说明\n- 返回该节点的基本信息\n- 返回该节点的直接子节点列表\n- 每个子节点的`children`数组为空`[]`\n- 通过`has_children`字段判断子节点是否可继续展开\n\n## 路径格式\n使用竖线(|)分隔层级,例如:\n- 第1层: \"小金属\"\n- 第2层: \"小金属|钴\"\n- 第3层: \"小金属|钴|钴化合物\"\n",
"operationId": "getCategoryTreeNode",
"parameters": [
{
@@ -337,15 +337,75 @@
"schema": {
"$ref": "#/components/schemas/TreeNode"
},
"example": {
"name": "硫酸钴",
"path": "钴|钴化合物|硫酸钴",
"level": 3,
"children": [
{
"examples": {
"展开第1层节点": {
"value": {
"name": "小金属",
"path": "小金属",
"level": 1,
"has_children": true,
"children": [
{
"name": "钴",
"path": "小金属|钴",
"level": 2,
"has_children": true,
"children": [],
"metrics": []
},
{
"name": "锂",
"path": "小金属|锂",
"level": 2,
"has_children": true,
"children": [],
"metrics": []
},
{
"name": "镍",
"path": "小金属|镍",
"level": 2,
"has_children": true,
"children": [],
"metrics": []
}
],
"metrics": []
}
},
"展开第2层节点": {
"value": {
"name": "钴",
"path": "小金属|钴",
"level": 2,
"has_children": true,
"children": [
{
"name": "钴化合物",
"path": "小金属|钴|钴化合物",
"level": 3,
"has_children": true,
"children": [],
"metrics": []
},
{
"name": "钴矿",
"path": "小金属|钴|钴矿",
"level": 3,
"has_children": true,
"children": [],
"metrics": []
}
],
"metrics": []
}
},
"叶子节点(含指标)": {
"value": {
"name": "产量",
"path": "钴|钴化合物|硫酸钴|产量",
"level": 4,
"path": "小金属|钴|钴化合物|硫酸钴|产量",
"level": 5,
"has_children": false,
"children": [],
"metrics": [
{
@@ -358,7 +418,7 @@
}
]
}
]
}
}
}
}
@@ -373,7 +433,7 @@
"examples": {
"节点不存在": {
"value": {
"detail": "未找到路径 '|不存在的节点' 对应的节点"
"detail": "未找到路径 '小金属|不存在的节点' 对应的节点"
}
},
"数据源不存在": {

View File

@@ -87,16 +87,18 @@ export const fetchCategoryTree = async (
* 获取特定节点及其子树
* @param path 节点完整路径(用 | 分隔)
* @param source 数据源类型 ('SMM' | 'Mysteel')
* @param maxDepth 返回的子树最大层级深度默认1层只返回直接子节点
* @returns 节点数据及其子树
*/
export const fetchCategoryNode = async (
path: string,
source: 'SMM' | 'Mysteel'
source: 'SMM' | 'Mysteel',
maxDepth: number = 1
): Promise<TreeNode> => {
try {
const encodedPath = encodeURIComponent(path);
const response = await fetch(
`/category-api/api/category-tree/node?path=${encodedPath}&source=${source}`,
`/category-api/api/category-tree/node?path=${encodedPath}&source=${source}&max_depth=${maxDepth}`,
{
method: 'GET',
headers: {

View File

@@ -349,10 +349,11 @@ const DataBrowser: React.FC = () => {
return newSet;
});
} else {
// 展开节点 - 检查是否需要加载子节点
const needsLoading = !node.children || node.children.length === 0;
// 展开节点 - 始终尝试加载子节点(如果还没加载过)
const hasChildren = node.children && node.children.length > 0;
if (needsLoading) {
// 如果没有子节点数据,尝试从服务器加载
if (!hasChildren) {
// 添加加载状态
setLoadingNodes((prev) => new Set(prev).add(node.path));
@@ -711,6 +712,14 @@ const DataBrowser: React.FC = () => {
unit: result.unit,
description: result.description,
};
// 更新面包屑导航为搜索结果的路径
const pathParts = result.category_path.split(' > ');
setBreadcrumbs(pathParts);
// 清空搜索框,显示树结构
setSearchQuery('');
handleMetricClick(metric);
}}
>