继电器状态面板调整

This commit is contained in:
joylink_zhaoerwei 2023-11-14 10:37:36 +08:00
parent 759223119f
commit d93852affc
2 changed files with 60 additions and 35 deletions

View File

@ -26,11 +26,14 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useLineStore } from 'src/stores/line-store'; import { useLineStore } from 'src/stores/line-store';
import { ref, watchEffect, watch } from 'vue'; import { ref, watch, onMounted, onUnmounted } from 'vue';
import { setRelayState } from 'src/api/Simulation'; import { setRelayState } from 'src/api/Simulation';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { ApiError } from 'src/boot/axios'; import { ApiError } from 'src/boot/axios';
import { IRelayState, Relay } from 'src/graphics/relay/Relay'; import { Relay } from 'src/graphics/relay/Relay';
import { JlGraphic } from 'src/jl-graphic';
import { RelayState } from 'src/drawApp/relayCabinetGraphics/RelayInteraction';
const graphic = ref();
const $q = useQuasar(); const $q = useQuasar();
const lineStore = useLineStore(); const lineStore = useLineStore();
@ -44,9 +47,22 @@ let operateOptions: {
value: boolean; value: boolean;
}[] = []; }[] = [];
watchEffect(() => { watch(
if (lineStore.selectedGraphics) { () => lineStore.selectedGraphics,
const relay = lineStore.selectedGraphics[0]; (val, oldVal) => {
if (oldVal?.length == 1 && oldVal[0].type == Relay.Type) {
unSubscribeState(oldVal[0] as JlGraphic);
}
if (val?.length == 1 && val[0].type == Relay.Type) {
graphic.value = val[0];
setNewRelayState(val[0] as Relay);
} else {
graphic.value = null;
}
}
);
function setNewRelayState(relay: Relay) {
if (relay && relay instanceof Relay) { if (relay && relay instanceof Relay) {
relayState.value = { relayState.value = {
id: relay.datas.id, id: relay.datas.id,
@ -57,17 +73,33 @@ watchEffect(() => {
? [{ label: '驱动落下', value: false }] ? [{ label: '驱动落下', value: false }]
: [{ label: '驱动吸起', value: true }]; : [{ label: '驱动吸起', value: true }];
} }
subscribeState(relay as JlGraphic);
}
onMounted(() => {
if (lineStore.selectedGraphics) {
setNewRelayState(lineStore.selectedGraphics[0] as Relay);
} }
}); });
watch( function subscribeState(g: JlGraphic) {
() => lineStore.socketStates, if (g) {
(val) => { g.on('stateupdate', updateState);
if (val && relayState.value.id) {
relayState.value = val[0].clone() as IRelayState;
} }
} }
);
function unSubscribeState(g: JlGraphic) {
if (g) {
g.off('stateupdate', updateState);
}
}
function updateState(newVal: RelayState) {
(relayState.value.xh = newVal.states.xh || false),
(operateOptions = newVal.states.xh
? [{ label: '驱动落下', value: false }]
: [{ label: '驱动吸起', value: true }]);
}
function changePosition(td: boolean) { function changePosition(td: boolean) {
if (lineStore.simulationId) { if (lineStore.simulationId) {
@ -89,4 +121,10 @@ function changePosition(td: boolean) {
}); });
} }
} }
onUnmounted(() => {
if (graphic.value) {
unSubscribeState(graphic.value as JlGraphic);
}
});
</script> </script>

View File

@ -87,19 +87,6 @@ function handleSubscribe(relayScene: IGraphicScene) {
} }
}); });
} }
if (states && states.length && app.selectedGraphics.length) {
const selectedGraphic = app.selectedGraphics[0];
const find = states.find((item) => {
return (
item.graphicType == Relay.Type &&
(item as RelayState).id == selectedGraphic.id &&
selectedGraphic.updateStates(item)
);
});
if (find) {
lineStore.setSocketStates([find]);
}
}
return states; return states;
}, },
graphicQueryer: (state: GraphicState, store: GraphicQueryStore) => { graphicQueryer: (state: GraphicState, store: GraphicQueryStore) => {