fix: Component awlays reset

This commit is contained in:
2025-05-17 17:32:16 +08:00
parent c7907b4253
commit 7aff4f3f02
7 changed files with 48 additions and 161 deletions

View File

@@ -112,7 +112,15 @@
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, onUnmounted, computed, watch } from "vue";
import {
ref,
reactive,
onMounted,
onUnmounted,
computed,
watch,
provide,
} from "vue";
import WireComponent from "./equipments/Wire.vue";
// 导入 diagram 管理器
@@ -122,10 +130,7 @@ import {
updatePartPosition,
updatePartAttribute,
deletePart,
addConnection,
deleteConnection,
findConnectionsByPart,
moveGroupComponents,
parseConnectionPin,
connectionArrayToWireItem,
validateDiagramData,
@@ -137,7 +142,8 @@ import type {
ConnectionArray,
WireItem,
} from "./diagramManager";
import { toString } from "lodash";
import { CanvasCurrentSelectedComponentID } from "./InjectKeys";
// 右键菜单处理函数
function handleContextMenu(e: MouseEvent) {
@@ -174,6 +180,9 @@ const hoveredComponent = ref<string | null>(null);
const draggingComponentId = ref<string | null>(null);
const componentDragOffset = reactive({ x: 0, y: 0 });
// Provide and Inject
provide(CanvasCurrentSelectedComponentID, selectedComponentId);
// Diagram 数据
const diagramData = ref<DiagramData>({
version: 1,
@@ -244,7 +253,7 @@ const wireItems = computed<WireItem[]>(() => {
console.log(`线路${index} - 计算后的起点位置:`, startPos);
}
} catch (error) {
console.error(`获取引脚位置出错:`, error);
// console.error(`获取引脚位置出错:`, error);
}
}
}
@@ -490,7 +499,7 @@ function startComponentDrag(e: MouseEvent, component: DiagramPart) {
// 阻止事件冒泡
e.stopPropagation();
console.debug(`Start Drag Component: ${component.type}:${component.id}`)
console.debug(`Start Drag Component: ${component.type}:${component.id}`);
// 设置拖拽状态
draggingComponentId.value = component.id;