主要功能: • 实现层级分析初始请求使用target_level=0获取顶层模型 • 新增getChildrenComponents API方法支持动态加载子组件 • 重构层级分析结果页面使用响应式数组直接管理组件数据 • 实现点击展开按钮动态加载并插入子组件到正确位置 • 修复子组件层级计算逻辑,确保父组件level+1 • 修复组件选择使用路径作为唯一标识,避免多选问题 • 优化界面显示,移除文件大小列,调整总组件数显示 • 添加componentChildren端点配置支持子组件查询 技术改进: • 从computed改为ref数组提升响应性能 • 使用component.path作为唯一标识解决ID重复问题 • 简化树形视图逻辑,移除复杂的展开状态管理 • 优化API参数处理,支持可选componentId参数 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
290 lines
6.9 KiB
JavaScript
290 lines
6.9 KiB
JavaScript
// CAD软件配置管理文件 - 统一管理所有CAD软件的配置和状态
|
||
|
||
// API基础配置
|
||
const API_CONFIG = {
|
||
// 基础配置
|
||
BASE_URL: import.meta.env.MODE === 'production' ? 'https://api.miany.com' : 'http://localhost',
|
||
TIMEOUT: 30000, // 30秒超时
|
||
|
||
// WebSocket配置
|
||
WEBSOCKET: {
|
||
BASE_URL: 'ws://localhost:8000',
|
||
ENDPOINT: '/api/v1/ws/connect',
|
||
CLIENT_ID: 'web_client',
|
||
USER_ID: null, // 动态设置,从auth store获取
|
||
RECONNECT_ATTEMPTS: 5,
|
||
RECONNECT_DELAY: 1000, // 1秒
|
||
HEARTBEAT_INTERVAL: 30000 // 30秒
|
||
},
|
||
|
||
// 通用API端点
|
||
COMMON_ENDPOINTS: {
|
||
health: '/health',
|
||
version: '/version',
|
||
ping: '/ping'
|
||
},
|
||
|
||
// 通知配置
|
||
NOTIFICATION: {
|
||
POSITION: 'top-right',
|
||
SUCCESS_DURATION: 2000, // 成功通知2秒
|
||
ERROR_DURATION: 3000, // 错误通知3秒
|
||
SUCCESS_TITLE: '操作成功',
|
||
ERROR_TITLE: '操作失败'
|
||
},
|
||
|
||
// 默认服务器配置
|
||
DEFAULT_SERVER: {
|
||
HOST: 'localhost',
|
||
PORT: 8080
|
||
},
|
||
|
||
// 导出格式支持
|
||
EXPORT_FORMATS: {
|
||
IFC: { extension: 'ifc', name: 'IFC 格式' },
|
||
STP: { extension: 'stp', name: 'STP 格式' }
|
||
},
|
||
|
||
// 几何优化默认参数
|
||
GEOMETRY_OPTIMIZATION: {
|
||
SOFTWARE_TYPE: "creo",
|
||
METHOD: "outer_shell",
|
||
QUALITY: 5,
|
||
CHORD_HEIGHT: 0.15,
|
||
FILL_HOLES: false,
|
||
IGNORE_SMALL_SURFACES: false,
|
||
SMALL_SURFACE_PERCENTAGE: 0.0,
|
||
OUTPUT_TYPE: "solid_surface",
|
||
IGNORE_QUILTS: false,
|
||
IGNORE_SKELETON: false,
|
||
ASSIGN_MASS_PROPERTIES: false
|
||
}
|
||
}
|
||
|
||
// CAD软件完整定义配置 - 整合显示信息和API配置
|
||
const CAD_SOFTWARE_DEFINITIONS = {
|
||
CREO: {
|
||
id: 'creo',
|
||
name: 'Creo Parametric',
|
||
displayName: 'Creo',
|
||
icon: 'fas fa-cogs',
|
||
version: '9.0',
|
||
port: 12345,
|
||
baseUrl: 'http://localhost:12345',
|
||
apiVersion: 'v1',
|
||
priority: 1,
|
||
description: '主要CAD软件',
|
||
features: [
|
||
'hierarchy', 'geometryComplexity', 'shellAnalysis',
|
||
'optimization', 'deleteComponent', 'export'
|
||
],
|
||
endpoints: {
|
||
connect: '/test',
|
||
status: '/api/status/model',
|
||
open: '/api/model/open',
|
||
hierarchy: '/api/creo/analysis/hierarchy',
|
||
hierarchyStatistics: '/api/analysis/hierarchy-statistics',
|
||
hierarchyDelete: '/api/creo/hierarchy/delete',
|
||
geometryComplexity: '/api/analysis/geometry-complexity',
|
||
shellAnalysis: '/api/analysis/shell-analysis',
|
||
optimization: '/api/creo/shrinkwrap/shell',
|
||
deleteComponent: '/api/creo/component/delete-by-path',
|
||
componentChildren: '/api/creo/component/children',
|
||
export: '/api/export/model'
|
||
}
|
||
},
|
||
REVIT: {
|
||
id: 'revit',
|
||
name: 'Revit',
|
||
displayName: 'Revit',
|
||
icon: 'fas fa-building',
|
||
version: '2024',
|
||
port: 9000,
|
||
baseUrl: 'http://localhost:9000',
|
||
apiVersion: 'v1',
|
||
priority: 2,
|
||
description: 'BIM模型管理',
|
||
features: ['overview', 'shellAnalysis', 'exportIfc'],
|
||
endpoints: {
|
||
connect: '/api/health',
|
||
overview: '/api/overview',
|
||
shellAnalysis: '/api/shell/analyze',
|
||
exportIfc: '/api/export/ifc'
|
||
}
|
||
},
|
||
PDMS: {
|
||
id: 'pdms',
|
||
name: 'PDMS',
|
||
displayName: 'PDMS',
|
||
icon: 'fas fa-industry',
|
||
version: '12.1',
|
||
port: 9001,
|
||
baseUrl: 'http://localhost:9001',
|
||
apiVersion: 'v1',
|
||
priority: 3,
|
||
description: '工厂设计管理',
|
||
features: ['status', 'piping'],
|
||
endpoints: {
|
||
connect: '/test',
|
||
status: '/api/status/model',
|
||
piping: '/api/v1/piping'
|
||
}
|
||
},
|
||
AUTOCAD: {
|
||
id: 'autocad',
|
||
name: 'AutoCAD',
|
||
displayName: 'AutoCAD',
|
||
icon: 'fas fa-drafting-compass',
|
||
version: '2024',
|
||
port: 8080,
|
||
baseUrl: 'http://localhost:8080',
|
||
apiVersion: 'v1',
|
||
priority: 4,
|
||
description: '连接和模型管理',
|
||
features: [],
|
||
endpoints: {}
|
||
},
|
||
SOLIDWORKS: {
|
||
id: 'solidworks',
|
||
name: 'SolidWorks',
|
||
displayName: 'SolidWorks',
|
||
icon: 'fas fa-cube',
|
||
version: '2023',
|
||
port: 8081,
|
||
baseUrl: 'http://localhost:8081',
|
||
apiVersion: 'v1',
|
||
priority: 5,
|
||
description: '装配体管理',
|
||
features: [],
|
||
endpoints: {}
|
||
},
|
||
CATIA: {
|
||
id: 'catia',
|
||
name: 'CATIA',
|
||
displayName: 'CATIA',
|
||
icon: 'fas fa-hammer',
|
||
version: 'V5-6',
|
||
port: 8082,
|
||
baseUrl: 'http://localhost:8082',
|
||
apiVersion: 'v1',
|
||
priority: 6,
|
||
description: '连接和模型管理',
|
||
features: [],
|
||
endpoints: {}
|
||
}
|
||
}
|
||
|
||
|
||
// 获取所有CAD软件定义
|
||
export const getAllCADDefinitions = () => {
|
||
return Object.values(CAD_SOFTWARE_DEFINITIONS)
|
||
.sort((a, b) => a.priority - b.priority)
|
||
}
|
||
|
||
|
||
// 根据ID获取CAD定义
|
||
export const getCADDefinitionById = (id) => {
|
||
return getAllCADDefinitions().find(cad => cad.id === id)
|
||
}
|
||
|
||
// 根据名称获取CAD定义
|
||
export const getCADDefinitionByName = (name) => {
|
||
return getAllCADDefinitions().find(cad =>
|
||
cad.name === name || cad.displayName === name
|
||
)
|
||
}
|
||
|
||
// 获取可显示的CAD列表
|
||
export const getDisplayableCADs = () => {
|
||
return getAllCADDefinitions()
|
||
}
|
||
|
||
// 检查CAD是否支持特定功能
|
||
export const cadSupportsFeature = (cadId, feature) => {
|
||
const cad = getCADDefinitionById(cadId)
|
||
return cad ? cad.features.includes(feature) : false
|
||
}
|
||
|
||
|
||
// ===== API相关工具函数 (从原api.js合并) =====
|
||
|
||
// 获取CAD服务配置
|
||
export const getCADServiceConfig = (cadName) => {
|
||
const serviceKey = cadName.toUpperCase().replace(/\s+/g, '')
|
||
return CAD_SOFTWARE_DEFINITIONS[serviceKey] || null
|
||
}
|
||
|
||
// 构建完整的API URL
|
||
export const buildApiUrl = (cadName, endpoint) => {
|
||
const service = getCADServiceConfig(cadName)
|
||
if (!service) {
|
||
throw new Error(`不支持的CAD软件: ${cadName}`)
|
||
}
|
||
|
||
const endpointPath = service.endpoints[endpoint]
|
||
if (!endpointPath) {
|
||
throw new Error(`不支持的端点: ${endpoint}`)
|
||
}
|
||
|
||
return `${service.baseUrl}${endpointPath}`
|
||
}
|
||
|
||
// 获取所有CAD服务列表
|
||
export const getAllCADServices = () => {
|
||
return Object.values(CAD_SOFTWARE_DEFINITIONS)
|
||
}
|
||
|
||
// 获取支持的导出格式
|
||
export const getExportFormats = () => {
|
||
return API_CONFIG.EXPORT_FORMATS
|
||
}
|
||
|
||
// 获取通知配置
|
||
export const getNotificationConfig = () => {
|
||
return API_CONFIG.NOTIFICATION
|
||
}
|
||
|
||
// 获取默认服务器配置
|
||
export const getDefaultServerConfig = () => {
|
||
return API_CONFIG.DEFAULT_SERVER
|
||
}
|
||
|
||
// 获取几何优化默认参数
|
||
export const getGeometryOptimizationDefaults = () => {
|
||
return API_CONFIG.GEOMETRY_OPTIMIZATION
|
||
}
|
||
|
||
// 获取WebSocket配置
|
||
export const getWebSocketConfig = () => {
|
||
return API_CONFIG.WEBSOCKET
|
||
}
|
||
|
||
// HTTP请求头配置
|
||
export const getRequestHeaders = () => {
|
||
return {
|
||
'Content-Type': 'application/json',
|
||
'Accept': 'application/json'
|
||
}
|
||
}
|
||
|
||
// 默认请求配置
|
||
export const getDefaultRequestConfig = () => {
|
||
return {
|
||
timeout: API_CONFIG.TIMEOUT,
|
||
headers: getRequestHeaders()
|
||
}
|
||
}
|
||
|
||
// 默认导出配置对象
|
||
export default {
|
||
CAD_SOFTWARE_DEFINITIONS,
|
||
API_CONFIG,
|
||
getAllCADDefinitions,
|
||
getDisplayableCADs,
|
||
getCADServiceConfig,
|
||
buildApiUrl,
|
||
getAllCADServices,
|
||
getExportFormats,
|
||
getRequestHeaders,
|
||
getDefaultRequestConfig
|
||
} |