fix: DDS and drag will reset conponent props

This commit is contained in:
SikongJueluo 2025-05-17 15:09:59 +08:00
parent 9b2ee8ad46
commit 3fb59af2dd
No known key found for this signature in database
3 changed files with 32 additions and 29 deletions

View File

@ -68,9 +68,7 @@
}" @mousedown.left.stop="startComponentDrag($event, component)" @mouseover="hoveredComponent = component.id" }" @mousedown.left.stop="startComponentDrag($event, component)" @mouseover="hoveredComponent = component.id"
@mouseleave="hoveredComponent = null"> @mouseleave="hoveredComponent = null">
<!-- 动态渲染组件 --> <!-- 动态渲染组件 -->
<KeepAlive> <component :is="getComponentDefinition(component.type)" v-if="props.componentModules[component.type]"
<component :is="getComponentDefinition(component.type)" :key="component.id"
v-show="props.componentModules[component.type]"
v-bind="prepareComponentProps(component.attrs || {}, component.id)" @update:bindKey=" v-bind="prepareComponentProps(component.attrs || {}, component.id)" @update:bindKey="
(value: string) => (value: string) =>
updateComponentProp(component.id, 'bindKey', value) updateComponentProp(component.id, 'bindKey', value)
@ -78,10 +76,9 @@
(pinInfo: any) => (pinInfo: any) =>
handlePinClick(component.id, pinInfo, pinInfo.originalEvent) handlePinClick(component.id, pinInfo, pinInfo.originalEvent)
" :ref="(el: any) => setComponentRef(component.id, el)" /> " :ref="(el: any) => setComponentRef(component.id, el)" />
</KeepAlive>
<!-- Fallback if component module not loaded yet --> <!-- Fallback if component module not loaded yet -->
<div v-if="!props.componentModules[component.type]" <div v-else
class="p-2 text-xs text-gray-400 border border-dashed border-gray-400 flex items-center justify-center"> class="p-2 text-xs text-gray-400 border border-dashed border-gray-400 flex items-center justify-center">
<div class="flex flex-col items-center"> <div class="flex flex-col items-center">
<div class="loading loading-spinner loading-xs mb-1"></div> <div class="loading loading-spinner loading-xs mb-1"></div>
@ -367,7 +364,7 @@ function prepareComponentProps(
if (componentId) { if (componentId) {
result.componentId = componentId; result.componentId = componentId;
} }
console.log("Prepare Props", result); // console.log(` ID: ${componentId}`, result);
return result; return result;
} }
@ -493,6 +490,8 @@ function startComponentDrag(e: MouseEvent, component: DiagramPart) {
// //
e.stopPropagation(); e.stopPropagation();
console.debug(`Start Drag Component: ${component.type}:${component.id}`)
// //
draggingComponentId.value = component.id; draggingComponentId.value = component.id;
isDragging.value = false; isDragging.value = false;
@ -544,12 +543,12 @@ function onComponentDrag(e: MouseEvent) {
if (!draggedComponent) return; if (!draggedComponent) return;
// //
diagramData.value = updatePartPosition( // diagramData.value = updatePartPosition(
diagramData.value, // diagramData.value,
draggingComponentId.value, // draggingComponentId.value,
Math.round(newX), // Math.round(newX),
Math.round(newY), // Math.round(newY),
); // );
// //
if (draggedComponent.group) { if (draggedComponent.group) {
@ -565,14 +564,14 @@ function onComponentDrag(e: MouseEvent) {
); );
// //
for (const groupComp of groupComponents) { // for (const groupComp of groupComponents) {
diagramData.value = updatePartPosition( // diagramData.value = updatePartPosition(
diagramData.value, // diagramData.value,
groupComp.id, // groupComp.id,
groupComp.x + deltaX, // groupComp.x + deltaX,
groupComp.y + deltaY, // groupComp.y + deltaY,
); // );
} // }
} }
// //

View File

@ -46,7 +46,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, watch, onMounted } from 'vue'; import { ref, computed, watch, onMounted, watchEffect } from 'vue';
import Pin from './Pin.vue'; import Pin from './Pin.vue';
// Pin // Pin
@ -94,6 +94,10 @@ const currentWaveformIndex = ref(0);
const waveformNames = ['正弦波', '方波', '三角波', '锯齿波']; const waveformNames = ['正弦波', '方波', '三角波', '锯齿波'];
const waveforms = ['sine', 'square', 'triangle', 'sawtooth']; const waveforms = ['sine', 'square', 'triangle', 'sawtooth'];
watchEffect(()=>{
console.log(`DDS Porperties: ${frequency.value} ${timebase.value}`)
})
// //
interface WaveformFunction { interface WaveformFunction {
(x: number, width: number, height: number, phaseRad: number): number; (x: number, width: number, height: number, phaseRad: number): number;

View File

@ -408,7 +408,7 @@ async function applyOutputWave() {
eqps.boardPort, eqps.boardPort,
0, 0,
currentWaveformIndex.value, currentWaveformIndex.value,
toInteger( frequency.value * Math.pow(2, 32 - 20) / 10 ), toInteger(frequency.value * Math.pow(2, 32 - 20)),
); );
if (!ret) { if (!ret) {
dialog.error("应用失败"); dialog.error("应用失败");