From 9704e9e3eb3b100bccea1f6e3bdcfa15a5dada28 Mon Sep 17 00:00:00 2001 From: hejl Date: Tue, 17 Jun 2025 16:05:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=B1=E5=B7=AE=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E4=B8=AAbug=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../outline/services/outline_service.dart | 177 +++++++++++++++++- .../outline/widgets/outline_explorer.dart | 2 +- 2 files changed, 177 insertions(+), 2 deletions(-) diff --git a/win_text_editor/lib/modules/outline/services/outline_service.dart b/win_text_editor/lib/modules/outline/services/outline_service.dart index 812f012..681577e 100644 --- a/win_text_editor/lib/modules/outline/services/outline_service.dart +++ b/win_text_editor/lib/modules/outline/services/outline_service.dart @@ -163,7 +163,10 @@ class OutlineService { await _loadComponent(rootPath, dirNode.value, dirNode); break; case 'Business': - // 其他操作类型的处理 + await _loadBusiness(rootPath, dirNode.value, dirNode); + break; + case 'Atom': + await _loadAtom(rootPath, dirNode.value, dirNode); break; default: Logger().error("操作节点类型不支持: ${dirNode.value}"); @@ -222,6 +225,178 @@ class OutlineService { } } + //加载原子逻辑层 + static Future _loadAtom(String rootPath, String? fieldName, OutlineNode parentNode) async { + if (fieldName == null || fieldName.isEmpty) return; + + final uftatomDir = Directory('$rootPath\\uftatom'); + if (!await uftatomDir.exists()) { + Logger().error('uftatom目录不存在'); + return; + } + + try { + // 遍历所有.uftstructure文件 + final uftatomFiles = + await uftatomDir + .list(recursive: true) + .where( + (entity) => + entity.path.endsWith('.uftatomfunction') || + entity.path.endsWith('.uftatomservice'), + ) + .cast() + .toList(); + + for (final file in uftatomFiles) { + try { + final content = await file.readAsString(); + final document = XmlDocument.parse(content); + String matchType = "I"; + + // 查找匹配的入参 + final List matchingProperties = + document + .findAllElements('inputParameters') + .where((element) => element.getAttribute('id') == fieldName) + .toList(); + + if (matchingProperties.isEmpty) { + matchingProperties.addAll( + document + .findAllElements('outputParameters') + .where((element) => element.getAttribute('id') == fieldName), + ); + matchType = "O"; + } + + if (matchingProperties.isEmpty) { + matchingProperties.addAll( + document + .findAllElements('internalParams') + .where((element) => element.getAttribute('id') == fieldName), + ); + matchType = "X"; + } + + if (matchingProperties.isNotEmpty) { + // 获取structure:Structure节点的chineseName + final businessNode = document.findAllElements('business:Function').firstOrNull; + final chineseName = businessNode?.getAttribute('chineseName') ?? '未命名'; + + // 获取文件名(不带路径) + final fileName = file.path; + + // 创建并添加子节点 + parentNode.children.add( + OutlineNode( + name: fileName, + title: '$chineseName($matchType)', + value: 'Atom', + frequency: 0, + isDirectory: false, // 这些是叶子节点 + depth: 4, + ), + ); + } + } catch (e) { + Logger().error('解析文件 ${file.path} 失败: $e'); + } + } + + Logger().info('为 $fieldName 找到 ${parentNode.children.length} 个匹配项'); + } catch (e) { + Logger().error('加载UFT对象失败: $e'); + rethrow; + } + } + + //加载业务逻辑层 + static Future _loadBusiness( + String rootPath, + String? fieldName, + OutlineNode parentNode, + ) async { + if (fieldName == null || fieldName.isEmpty) return; + + final uftbusinessDir = Directory('$rootPath\\uftbusiness'); + if (!await uftbusinessDir.exists()) { + Logger().error('uftbusiness目录不存在'); + return; + } + + try { + // 遍历所有.uftstructure文件 + final uftbusinessFiles = + await uftbusinessDir + .list(recursive: true) + .where((entity) => entity.path.endsWith('.uftfunction')) + .cast() + .toList(); + + for (final file in uftbusinessFiles) { + try { + final content = await file.readAsString(); + final document = XmlDocument.parse(content); + String matchType = "I"; + + // 查找匹配的入参 + final List matchingProperties = + document + .findAllElements('inputParameters') + .where((element) => element.getAttribute('id') == fieldName) + .toList(); + + if (matchingProperties.isEmpty) { + matchingProperties.addAll( + document + .findAllElements('outputParameters') + .where((element) => element.getAttribute('id') == fieldName), + ); + matchType = "O"; + } + + if (matchingProperties.isEmpty) { + matchingProperties.addAll( + document + .findAllElements('internalParams') + .where((element) => element.getAttribute('id') == fieldName), + ); + matchType = "X"; + } + + if (matchingProperties.isNotEmpty) { + // 获取structure:Structure节点的chineseName + final businessNode = document.findAllElements('business:Function').firstOrNull; + final chineseName = businessNode?.getAttribute('chineseName') ?? '未命名'; + + // 获取文件名(不带路径) + final fileName = file.path; + + // 创建并添加子节点 + parentNode.children.add( + OutlineNode( + name: fileName, + title: '$chineseName($matchType)', + value: 'Business', + frequency: 0, + isDirectory: false, // 这些是叶子节点 + depth: 4, + ), + ); + } + } catch (e) { + Logger().error('解析文件 ${file.path} 失败: $e'); + } + } + + Logger().info('为 $fieldName 找到 ${parentNode.children.length} 个匹配项'); + } catch (e) { + Logger().error('加载UFT对象失败: $e'); + rethrow; + } + } + // 私有方法:加载UFT对象 static Future _loadUftObject( String rootPath, diff --git a/win_text_editor/lib/modules/outline/widgets/outline_explorer.dart b/win_text_editor/lib/modules/outline/widgets/outline_explorer.dart index 2cf4c57..34f4627 100644 --- a/win_text_editor/lib/modules/outline/widgets/outline_explorer.dart +++ b/win_text_editor/lib/modules/outline/widgets/outline_explorer.dart @@ -199,7 +199,7 @@ class _OutlineExplorerState extends State { case "Business": case "Atom": if (widget.onFileDoubleTap != null) { - widget.onFileDoubleTap!(outlineNode.name, outlineNode.name); + widget.onFileDoubleTap!(outlineNode.name, null); } break; case "Component":