Refactor component configuration and diagram management

- Removed the component configuration from `componentConfig.ts` to streamline the codebase.
- Introduced a new `diagram.json` file to define the initial structure for diagrams.
- Created a `diagramManager.ts` to handle diagram data, including loading, saving, and validating diagram structures.
- Updated `ProjectView.vue` to integrate the new diagram management system, including handling component selection and property updates.
- Enhanced the component property management to support dynamic attributes and improved error handling.
- Added functions for managing connections between components within the diagram.
This commit is contained in:
alivender
2025-05-07 15:42:35 +08:00
parent 1c75aa621a
commit 47cfe17d16
10 changed files with 1457 additions and 890 deletions

View File

@@ -101,7 +101,6 @@
<script setup lang="ts">
import { ref, computed, shallowRef, onMounted } from 'vue';
import { getComponentConfig } from '@/components/equipments/componentConfig';
// Props 定义
interface Props {
@@ -208,18 +207,22 @@ function closeMenu() {
// 添加新元器件
async function addComponent(componentTemplate: { type: string; name: string }) {
// 先从配置文件中获取默认属性
const config = getComponentConfig(componentTemplate.type);
const defaultProps: Record<string, any> = {};
if (config && config.props) {
config.props.forEach(prop => {
defaultProps[prop.name] = prop.default;
});
// 先加载组件模块
const moduleRef = await loadComponentModule(componentTemplate.type);
let defaultProps: Record<string, any> = {};
// 尝试直接调用组件导出的getDefaultProps方法
if(moduleRef){
if (typeof moduleRef.getDefaultProps === 'function') {
defaultProps = moduleRef.getDefaultProps();
console.log(`Got default props from ${componentTemplate.type}:`, defaultProps);
} else {
// 回退到配置文件
console.log(`No getDefaultProps found for ${componentTemplate.type}`);
}
} else{
console.log(`Failed to load module for ${componentTemplate.type}`);
}
// 再加载组件模块以便后续使用
await loadComponentModule(componentTemplate.type);
// 发送添加组件事件给父组件
emit('add-component', {