feat: 实现层级删除功能完整集成

- 配置API端点:在cad.js中添加hierarchyDelete端点
- 扩展API服务:在creoApi.js中添加deleteHierarchy方法
- Store状态管理:添加currentProjectName用于存储当前项目名称
- 项目名称自动获取:在查看/打开模型时自动设置项目名称
- 组件内部集成:HierarchyDeletionParamsPage直接调用删除API
- 成功提示优化:显示删除数量和具体组件名称列表
- 严格错误处理:遵循快速失败原则,不使用备用方案

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
sladro 2025-09-18 10:52:07 +08:00
parent a7decc6645
commit 7ea1014570
6 changed files with 87 additions and 2 deletions

View File

@ -147,6 +147,7 @@ const handleOperation = async () => {
- ✅ PDMS工厂设计模型查看器PdmsModelViewer
- ✅ Revit建筑设计模型查看器RevitModelViewer
- ✅ 层级统计功能完整集成getHierarchyStatistics API + 层级删除配置页面)
- ✅ 层级删除功能完整实现deleteHierarchy API + 项目名称管理 + 成功提示)
## 页面添加标准流程

View File

@ -155,6 +155,7 @@ const handleOpenModel = async () => {
if (connectedCAD.id === 'creo') {
const result = await creoApi.getCurrentModel()
if (result.success) {
cadStore.currentProjectName = result.data.data.fileName
emit('show-model-viewer', result.data)
}
} else if (connectedCAD.id === 'revit') {
@ -192,6 +193,7 @@ const handleOpenModel = async () => {
if (filePath && connectedCAD.id === 'creo') {
const result = await creoApi.openModelFile(filePath)
if (result.success) {
cadStore.currentProjectName = result.data.data.fileName
emit('show-model-viewer', result.data)
}
}

View File

@ -61,7 +61,7 @@
</button>
<button class="params-action-btn danger"
id="execute-deletion-btn"
@click="$emit('execute-deletion', getExecutionParams())"
@click="handleExecuteDeletion"
:disabled="loading || selectedLevel === null">
<i class="fas fa-trash"></i>
执行删除
@ -74,6 +74,8 @@
<script setup>
import { ref, computed, onMounted } from 'vue'
import { creoApi } from '@/services/creoApi'
import { ElNotification } from 'element-plus'
import { useCADStore } from '@/stores/cad'
// Props - 使
defineProps({
@ -84,7 +86,10 @@ defineProps({
})
// Emits
defineEmits(['close', 'execute-deletion'])
const emit = defineEmits(['close'])
// Store
const cadStore = useCADStore()
//
const selectedLevel = ref(null)
@ -162,6 +167,52 @@ const fetchHierarchyStatistics = async () => {
loading.value = false
}
//
const handleExecuteDeletion = async () => {
if (selectedLevel.value === null) return
if (!cadStore.currentProjectName) {
throw new Error('当前没有项目名称')
}
const result = await creoApi.deleteHierarchy(selectedLevel.value, cadStore.currentProjectName)
if (result.success) {
//
showDeletionSuccessMessage(result.data.data)
emit('close')
}
}
//
const showDeletionSuccessMessage = (data) => {
const totalDeleted = data.deletion_summary?.total_deleted || 0
//
const allDeletedComponents = []
if (data.deleted_components) {
Object.values(data.deleted_components).forEach(levelComponents => {
allDeletedComponents.push(...levelComponents)
})
}
//
let componentsList = allDeletedComponents.join(', ')
const maxLength = 200 //
if (componentsList.length > maxLength) {
componentsList = componentsList.substring(0, maxLength) + '...'
}
//
const message = `删除成功!共删除 ${totalDeleted} 个组件:${componentsList}`
ElNotification({
title: '层级删除完成',
message: message,
type: 'success',
duration: 5000 // 5
})
}
//
onMounted(() => {
fetchHierarchyStatistics()

View File

@ -84,6 +84,7 @@ const CAD_SOFTWARE_DEFINITIONS = {
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',

View File

@ -165,6 +165,31 @@ class CreoApiService {
}
})
}
/**
* 删除指定层级及以下的所有组件
* @param {number} targetLevel - 目标层级
* @param {string} projectName - 项目名称
* @returns {Promise<{success: boolean, data?: any, error?: string}>}
*/
async deleteHierarchy(targetLevel, projectName) {
if (!projectName) {
throw new Error('项目名称不能为空')
}
const url = buildApiUrl(this.softwareName, 'hierarchyDelete')
return await apiClient.post(url, {
"software_type": SOFTWARE_TYPE,
"project_name": projectName,
"target_level": targetLevel
}, {
operationContext: {
software: 'Creo',
operation: `层级删除 - 层级${targetLevel}`
}
})
}
}
// 导出单例实例

View File

@ -26,6 +26,9 @@ export const useCADStore = defineStore('cad', () => {
// CAD软件连接状态 - 配置驱动
const cadConnections = ref(initializeCADConnections())
// 当前项目名称
const currentProjectName = ref(null)
// 当前连接的CAD软件
const currentCAD = computed(() => {
return cadConnections.value.find(cad => cad.connected)
@ -82,10 +85,12 @@ export const useCADStore = defineStore('cad', () => {
}
}
return {
// 状态
cadConnections,
currentCAD,
currentProjectName,
displayableCADs,
// 方法