继电器状态面板调整
This commit is contained in:
parent
759223119f
commit
d93852affc
@ -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,31 +47,60 @@ let operateOptions: {
|
|||||||
value: boolean;
|
value: boolean;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
watchEffect(() => {
|
|
||||||
if (lineStore.selectedGraphics) {
|
|
||||||
const relay = lineStore.selectedGraphics[0];
|
|
||||||
if (relay && relay instanceof Relay) {
|
|
||||||
relayState.value = {
|
|
||||||
id: relay.datas.id,
|
|
||||||
code: relay.datas.code,
|
|
||||||
xh: relay.states.xh || false,
|
|
||||||
};
|
|
||||||
operateOptions = relay.states.xh
|
|
||||||
? [{ label: '驱动落下', value: false }]
|
|
||||||
: [{ label: '驱动吸起', value: true }];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => lineStore.socketStates,
|
() => lineStore.selectedGraphics,
|
||||||
(val) => {
|
(val, oldVal) => {
|
||||||
if (val && relayState.value.id) {
|
if (oldVal?.length == 1 && oldVal[0].type == Relay.Type) {
|
||||||
relayState.value = val[0].clone() as IRelayState;
|
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) {
|
||||||
|
relayState.value = {
|
||||||
|
id: relay.datas.id,
|
||||||
|
code: relay.datas.code,
|
||||||
|
xh: relay.states.xh || false,
|
||||||
|
};
|
||||||
|
operateOptions = relay.states.xh
|
||||||
|
? [{ label: '驱动落下', value: false }]
|
||||||
|
: [{ label: '驱动吸起', value: true }];
|
||||||
|
}
|
||||||
|
subscribeState(relay as JlGraphic);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (lineStore.selectedGraphics) {
|
||||||
|
setNewRelayState(lineStore.selectedGraphics[0] as Relay);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function subscribeState(g: JlGraphic) {
|
||||||
|
if (g) {
|
||||||
|
g.on('stateupdate', updateState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
setRelayState({
|
setRelayState({
|
||||||
@ -89,4 +121,10 @@ function changePosition(td: boolean) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (graphic.value) {
|
||||||
|
unSubscribeState(graphic.value as JlGraphic);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user