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:
parent
a7decc6645
commit
7ea1014570
@ -147,6 +147,7 @@ const handleOperation = async () => {
|
||||
- ✅ PDMS工厂设计模型查看器(PdmsModelViewer)
|
||||
- ✅ Revit建筑设计模型查看器(RevitModelViewer)
|
||||
- ✅ 层级统计功能完整集成(getHierarchyStatistics API + 层级删除配置页面)
|
||||
- ✅ 层级删除功能完整实现(deleteHierarchy API + 项目名称管理 + 成功提示)
|
||||
|
||||
## 页面添加标准流程
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 导出单例实例
|
||||
|
||||
@ -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,
|
||||
|
||||
// 方法
|
||||
|
||||
Loading…
Reference in New Issue
Block a user