diff --git a/src/components/layout/CadSidebar.vue b/src/components/layout/CadSidebar.vue index e36b08b..ec6bf2a 100644 --- a/src/components/layout/CadSidebar.vue +++ b/src/components/layout/CadSidebar.vue @@ -178,19 +178,40 @@ const handleOpenModel = async () => { inputPlaceholder: '例如: Z:\\工具\\Revit2017(64bit)\\model.asm' }) - if (filePath && connectedCAD.id === 'creo') { + if (filePath) { // 处理文件路径格式,支持中文字符和特殊字符 const processedFilePath = filePath.trim() - // 第一步:打开模型文件 - const openResult = await creoApi.openModelFile(processedFilePath) - if (openResult.success) { - // 第二步:获取当前模型详细信息 - const modelResult = await creoApi.getCurrentModel() - if (modelResult.success) { - cadStore.setCurrentProjectName(modelResult.data.data.fileName) - emit('show-model-viewer', modelResult.data) + if (connectedCAD.id === 'creo') { + // 第一步:打开模型文件 + const openResult = await creoApi.openModelFile(processedFilePath) + if (openResult.success) { + // 第二步:获取当前模型详细信息 + const modelResult = await creoApi.getCurrentModel() + if (modelResult.success) { + cadStore.setCurrentProjectName(modelResult.data.data.fileName) + emit('show-model-viewer', modelResult.data) + } } + } else if (connectedCAD.id === 'revit') { + // Revit:打开模型文件 + const openResult = await revitApi.openModelFile(processedFilePath, false) + if (openResult.success) { + // 第二步:获取当前模型详细信息 + const modelResult = await revitApi.getCurrentModel() + if (modelResult.success) { + cadStore.setCurrentProjectName(modelResult.data.data.project.name) + emit('show-model-viewer', modelResult.data.data) + } + } + } else if (connectedCAD.id === 'pdms') { + ElNotification({ + title: '暂不支持', + message: 'PDMS 打开模型文件功能尚未实现', + type: 'warning', + position: 'top-right', + duration: notificationConfig.ERROR_DURATION + }) } } } catch (error) { @@ -304,13 +325,52 @@ const handleDrop = async (event) => { }) const openResult = await creoApi.openModelFile(filePath) - + if (openResult.success) { const modelResult = await creoApi.getCurrentModel() if (modelResult.success) { cadStore.setCurrentProjectName(modelResult.data.data.fileName) emit('show-model-viewer', modelResult.data) - + + ElNotification({ + title: '打开成功', + message: `已成功打开模型: ${fileName}`, + type: 'success', + position: 'top-right', + duration: notificationConfig.SUCCESS_DURATION + }) + } + } else { + throw new Error(openResult.error || 'API返回失败') + } + } catch (error) { + ElNotification({ + title: '打开失败', + message: error.message || '未知错误', + type: 'error', + position: 'top-right', + duration: notificationConfig.ERROR_DURATION + }) + } + } else if (connectedCAD.id === 'revit') { + // Revit 拖拽打开 + try { + ElNotification({ + title: '正在打开', + message: `正在请求Revit打开: ${fileName}`, + type: 'info', + position: 'top-right', + duration: 2000 + }) + + const openResult = await revitApi.openModelFile(filePath, false) + + if (openResult.success) { + const modelResult = await revitApi.getCurrentModel() + if (modelResult.success) { + cadStore.setCurrentProjectName(modelResult.data.data.project.name) + emit('show-model-viewer', modelResult.data.data) + ElNotification({ title: '打开成功', message: `已成功打开模型: ${fileName}`, diff --git a/src/components/pages/FileManagementPage.vue b/src/components/pages/FileManagementPage.vue index 27e076c..a5af8bf 100644 --- a/src/components/pages/FileManagementPage.vue +++ b/src/components/pages/FileManagementPage.vue @@ -352,6 +352,7 @@ import { websocketService } from '@/services/websocketService' import { getWebSocketConfig } from '@/config/cad' import { useCADStore } from '@/stores/cad' import creoApi from '@/services/creoApi' +import revitApi from '@/services/revitApi' const cadStore = useCADStore() @@ -835,9 +836,22 @@ const openModel = async (fileInfo) => { console.error('调用Creo打开接口异常', error) alert(`打开模型失败: ${error.message}`) } + } else if (currentCADId === 'revit') { + // Revit: 发送打开命令到本地插件 API + try { + const result = await revitApi.openModelFile(fileInfo.filePath, false) + if (result && result.success) { + console.log(`Revit打开模型成功: ${fileInfo.filename}`) + } else { + console.error('Revit打开模型失败', result) + } + } catch (error) { + console.error('调用Revit打开接口异常', error) + alert(`打开模型失败: ${error.message}`) + } } else { // 3. 其他软件: 占位提示 - alert(`当前连接的是 ${cadStore.currentCAD.name},该软件的打开模型接口尚未实现(仅支持Creo)。`) + alert(`当前连接的是 ${cadStore.currentCAD.name},该软件的打开模型接口尚未实现(仅支持Creo和Revit)。`) } } diff --git a/src/config/cad.js b/src/config/cad.js index d689e9b..de482c8 100644 --- a/src/config/cad.js +++ b/src/config/cad.js @@ -106,14 +106,15 @@ const CAD_SOFTWARE_DEFINITIONS = { apiVersion: 'v1', priority: 2, description: 'BIM模型管理', - features: ['overview', 'shellAnalysis', 'exportIfc'], + features: ['overview', 'shellAnalysis', 'exportIfc', 'open'], endpoints: { connect: '/api/health', overview: '/api/overview', shellAnalysis: '/api/shell/analyze', exportIfc: '/api/export/ifc', shellExecute: '/api/shell/execute', - taskStatus: '/api/task' + taskStatus: '/api/task', + open: '/api/open' } }, PDMS: { diff --git a/src/services/revitApi.js b/src/services/revitApi.js index 6795b9e..755dbd7 100644 --- a/src/services/revitApi.js +++ b/src/services/revitApi.js @@ -130,6 +130,26 @@ class RevitApiService { } }) } + + /** + * 打开模型文件 + * @param {string} filePath - 模型文件绝对路径 + * @param {boolean} detached - 是否分离打开(默认false) + * @returns {Promise<{success: boolean, data?: any, error?: string}>} + */ + async openModelFile(filePath, detached = false) { + const url = buildApiUrl(this.softwareName, 'open') + + return await apiClient.post(url, { + filePath, + detached + }, { + operationContext: { + software: 'Revit', + operation: '打开模型文件' + } + }) + } } // 导出单例实例