From 15ec017e601de3e555933fcbf88fc82af1e0aa57 Mon Sep 17 00:00:00 2001 From: sladro Date: Mon, 2 Mar 2026 18:55:01 +0800 Subject: [PATCH] feat: add ReportLogViewer component for displaying logs and model comparison, along with a new CAD store. --- src/components/pages/ReportLogViewer.vue | 241 +++++++++++++++++++++-- src/stores/cad.js | 22 ++- 2 files changed, 245 insertions(+), 18 deletions(-) diff --git a/src/components/pages/ReportLogViewer.vue b/src/components/pages/ReportLogViewer.vue index 37b33f6..4a7140e 100644 --- a/src/components/pages/ReportLogViewer.vue +++ b/src/components/pages/ReportLogViewer.vue @@ -202,27 +202,79 @@ +
-
-
-
- +
+ +
+
+
1
+

记录当前模型基准状态

+
+
+ + 读取当前 CAD 模型参数作为基准 + +
+

基准原始模型

+
    +
  • 模型文件: {{ cadStore.manualComparisonState.baselineData?.name }}
  • +
  • 内存占用: {{ cadStore.manualComparisonState.baselineData?.mem }}
  • +
  • 面片数量: {{ cadStore.manualComparisonState.baselineData?.poly }}
  • +
  • 特征数量: {{ cadStore.manualComparisonState.baselineData?.features }}
  • +
+
-

当前 CAD 打开模型

-

将自动抓取当前插件会话中的模型参数作为基准

- -
VS
- -
- -

请选择比对目标离线文件 (.prt, .ifc, .rvt...)

- 选择本地文件 + + +
+
+
2
+

自动打开离线文件并比对

+
+
+
+ 请填写需要对比的离线文件绝对路径 (支持 .rvt, .rfa, .prt, .asm 等格式): +
+
+ + + 自动打开并读取参数 + +
+ + +
+
+
+

基准状态

+
    +
  • 内存占用 {{ cadStore.manualComparisonState.baselineData?.mem }}
  • +
  • 面片数量 {{ cadStore.manualComparisonState.baselineData?.poly }}
  • +
  • 特征总数 {{ cadStore.manualComparisonState.baselineData?.features }}
  • +
+
+
VS
+
+

离线文件读取状态

+
    +
  • 文件名称 {{ cadStore.manualComparisonState.resultData?.name }}
  • +
  • 内存占用 {{ cadStore.manualComparisonState.resultData?.mem }}
  • +
  • 面片数量 {{ cadStore.manualComparisonState.resultData?.poly }}
  • +
  • 特征总数 {{ cadStore.manualComparisonState.resultData?.features }}
  • +
+
+
+ +
+ 开启新一轮比对 +
+
+
+
-
- 开始混合比对分析 -
@@ -253,6 +305,8 @@ const comparisonMode = ref('live') const isCapturingBaseline = ref(false) const isCapturingResult = ref(false) +const isCapturingManualBaseline = ref(false) +const isCapturingManualResult = ref(false) const cadStore = useCADStore() @@ -404,6 +458,161 @@ const resetLiveFlow = () => { cadStore.resetLiveComparison() } +const captureManualBaseline = async () => { + const connectedCAD = cadStore.currentCAD + if (!connectedCAD) { + ElMessage.warning('请先连接并打开对应的 CAD 插件和模型') + return + } + + isCapturingManualBaseline.value = true + try { + let result; + let stats = { + mem: 'API暂未支持', + poly: 'API暂未支持', + features: 'API暂未支持' + } + + if (connectedCAD.id === 'creo') { + result = await creoApi.getCurrentModel() + try { + const statResult = await creoApi.getHierarchyStatistics() + if (statResult.success && statResult.data?.data?.statistics) { + let totalFeatures = 0 + Object.values(statResult.data.data.statistics).forEach(v => totalFeatures += v) + if(totalFeatures > 0) stats.features = `${totalFeatures} +` + } + } catch(e) { } + } else if (connectedCAD.id === 'revit') { + result = await revitApi.getCurrentModel() + } else if (connectedCAD.id === 'pdms') { + result = await pdmsApi.getCurrentModel() + } + + if (result && result.success) { + const respData = result.data?.data || {} + let fileName = '当前活动模型' + + if (connectedCAD.id === 'creo' && respData.fileName) fileName = respData.fileName + else if (connectedCAD.id === 'revit' && respData.project?.name) fileName = respData.project.name + else if (connectedCAD.id === 'pdms' && respData.ProjectInfo?.ProjectName) fileName = respData.ProjectInfo.ProjectName + + if (respData.fileSize) stats.mem = respData.fileSize + if (respData.memoryUsage) stats.mem = respData.memoryUsage + if (respData.polygonCount) stats.poly = respData.polygonCount + if (respData.featureCount) stats.features = respData.featureCount + if (respData.componentCount) stats.features = respData.componentCount + + if (connectedCAD.id === 'revit' && respData.project) { + if (respData.project.fileSizeDisplay) stats.mem = respData.project.fileSizeDisplay + if (respData.project.polygonCount !== undefined) stats.poly = respData.project.polygonCount + if (respData.project.featureCount !== undefined) stats.features = respData.project.featureCount + } + + cadStore.manualComparisonState.baselineData = { + name: fileName, + mem: stats.mem, + poly: stats.poly, + features: stats.features + } + cadStore.manualComparisonState.step = 2 + ElMessage.success('基准状态参数读取成功') + } else { + throw new Error(result?.error || '未能获取到开启的模型信息') + } + } catch (error) { + ElMessage.error(`获取基准数据失败: ${error.message}`) + } finally { + isCapturingManualBaseline.value = false + } +} + +const captureManualResult = async () => { + const filePath = cadStore.manualComparisonState.targetFilePath + if (!filePath || filePath.trim() === '') { + ElMessage.warning('请填写离线模型的绝对路径') + return + } + + const ext = filePath.split('.').pop().toLowerCase() + let apiToUse = null + let cadType = '' + + if (['rvt', 'rfa'].includes(ext)) { + apiToUse = revitApi + cadType = 'revit' + } else if (['prt', 'asm'].includes(ext)) { + apiToUse = creoApi + cadType = 'creo' + } else { + ElMessage.warning(`暂不支持的离线文件后缀: .${ext},目前自动打开支持 .rvt, .rfa, .prt, .asm`) + return + } + + isCapturingManualResult.value = true + try { + // 假设 apiToUse 是挂载在配置里的或者能通过某些方式访问 + // 调用打开指定的离线文件 + const openRes = await apiToUse.openModelFile(filePath) + if (!openRes || !openRes.success) { + throw new Error(openRes?.error || '打开离线模型文件失败') + } + + let result = await apiToUse.getCurrentModel() + let stats = { mem: 'API暂未支持', poly: 'API暂未支持', features: 'API暂未支持' } + + if (cadType === 'creo') { + try { + const statResult = await creoApi.getHierarchyStatistics() + if (statResult.success && statResult.data?.data?.statistics) { + let totalFeatures = 0 + Object.values(statResult.data.data.statistics).forEach(v => totalFeatures += v) + if(totalFeatures > 0) stats.features = `${totalFeatures} +` + } + } catch(e) { } + } + + if (result && result.success) { + const respData = result.data?.data || {} + + // 提取文件名 + let fileName = filePath.split('\\').pop().split('/').pop() + + if (respData.fileSize) stats.mem = respData.fileSize + if (respData.memoryUsage) stats.mem = respData.memoryUsage + if (respData.polygonCount) stats.poly = respData.polygonCount + if (respData.featureCount) stats.features = respData.featureCount + if (respData.componentCount) stats.features = respData.componentCount + + if (cadType === 'revit' && respData.project) { + if (respData.project.fileSizeDisplay) stats.mem = respData.project.fileSizeDisplay + if (respData.project.polygonCount !== undefined) stats.poly = respData.project.polygonCount + if (respData.project.featureCount !== undefined) stats.features = respData.project.featureCount + } + + cadStore.manualComparisonState.resultData = { + name: fileName, + mem: stats.mem, + poly: stats.poly, + features: stats.features + } + cadStore.manualComparisonState.step = 3 + ElMessage.success('离线模型已成功打开并读取参数') + } else { + throw new Error(result?.error || '未能获取到离线模型信息') + } + } catch (error) { + ElMessage.error(`获取离线模型数据失败: ${error.message}`) + } finally { + isCapturingManualResult.value = false + } +} + +const resetManualFlow = () => { + cadStore.resetManualComparison() +} + // 模拟报告数据 const mockReports = [ { diff --git a/src/stores/cad.js b/src/stores/cad.js index 0ad65bb..f4d27cd 100644 --- a/src/stores/cad.js +++ b/src/stores/cad.js @@ -97,13 +97,20 @@ export const useCADStore = defineStore('cad', () => { draggedFile.value = file } - // 实时穿透对比状态 (全局保留) const liveComparisonState = ref({ step: 1, // 1: 准备抓取基准, 2: 已抓取基准(等待抓取结果), 3: 完成对比 baselineData: null, resultData: null }) + // 离线文件对比状态 + const manualComparisonState = ref({ + step: 1, // 1: 准备抓取基准, 2: 填写并打开离线文件, 3: 完成对比 + baselineData: null, + targetFilePath: '', + resultData: null + }) + // 重置实时穿透对比状态 const resetLiveComparison = () => { liveComparisonState.value = { @@ -113,6 +120,15 @@ export const useCADStore = defineStore('cad', () => { } } + const resetManualComparison = () => { + manualComparisonState.value = { + step: 1, + baselineData: null, + targetFilePath: '', + resultData: null + } + } + return { // 状态 cadConnections, @@ -129,6 +145,8 @@ export const useCADStore = defineStore('cad', () => { setCurrentProjectName, setDraggedFile, liveComparisonState, - resetLiveComparison + resetLiveComparison, + manualComparisonState, + resetManualComparison } }) \ No newline at end of file