继电器、道岔、区段、屏蔽门状态组件格式化统一及代码优化

This commit is contained in:
joylink_zhaoerwei 2024-01-24 15:36:46 +08:00
parent fc8ddeecb7
commit cde11aa2bb
4 changed files with 115 additions and 94 deletions

View File

@ -61,7 +61,7 @@ watch(
} }
if (val?.length == 1 && val[0] instanceof Relay) { if (val?.length == 1 && val[0] instanceof Relay) {
copySelectGraphic = toRaw(val[0]); copySelectGraphic = toRaw(val[0]);
setNewRelayState(val[0]); initRelayState(val[0]);
} else { } else {
copySelectGraphic = null; copySelectGraphic = null;
} }
@ -70,11 +70,12 @@ watch(
onMounted(() => { onMounted(() => {
if (lineStore.selectedGraphics) { if (lineStore.selectedGraphics) {
setNewRelayState(lineStore.selectedGraphics[0] as Relay); initRelayState(lineStore.selectedGraphics[0] as Relay);
} }
}); });
function setNewRelayState(relay: Relay) { function initRelayState(relay: Relay) {
copySelectGraphic = toRaw(relay);
relayState.value = { relayState.value = {
id: relay.datas.id, id: relay.datas.id,
code: relay.datas.code, code: relay.datas.code,
@ -84,14 +85,6 @@ function setNewRelayState(relay: Relay) {
subscribeState(relay); subscribeState(relay);
} }
function subscribeState(g: Relay) {
g.on('stateupdate', updateState);
}
function unSubscribeState(g: Relay) {
g.off('stateupdate', updateState);
}
function updateState(newVal: RelayState) { function updateState(newVal: RelayState) {
relayState.value.xh = newVal.states.xh || false; relayState.value.xh = newVal.states.xh || false;
} }
@ -117,6 +110,14 @@ function changePosition(operation: request.Relay.Operation) {
} }
} }
function subscribeState(g: Relay) {
g.on('stateupdate', updateState);
}
function unSubscribeState(g: Relay) {
g.off('stateupdate', updateState);
}
onUnmounted(() => { onUnmounted(() => {
if (copySelectGraphic) { if (copySelectGraphic) {
unSubscribeState(copySelectGraphic); unSubscribeState(copySelectGraphic);

View File

@ -41,7 +41,7 @@
style="margin-top: 10px; margin-left: 10px" style="margin-top: 10px; margin-left: 10px"
v-model="screenDoorState.obstacle" v-model="screenDoorState.obstacle"
outlined outlined
label="屏蔽门有障碍物" label="间隙探测障碍物"
:disable="true" :disable="true"
/> />
<div class="q-gutter-sm border-box"> <div class="q-gutter-sm border-box">
@ -113,7 +113,7 @@
</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, watch, onMounted } from 'vue'; import { ref, watch, onMounted, onUnmounted, toRaw } from 'vue';
import { ScreenDoor } from 'src/graphics/screenDoor/ScreenDoor'; import { ScreenDoor } from 'src/graphics/screenDoor/ScreenDoor';
import { request } from 'src/protos/request'; import { request } from 'src/protos/request';
import { ScreenDoorState } from 'src/drawApp/graphics/ScreenDoorInteraction'; import { ScreenDoorState } from 'src/drawApp/graphics/ScreenDoorInteraction';
@ -158,18 +158,32 @@ const screenDoorFaultOption = [
]; ];
const asdCodes = ref<number[]>([]); const asdCodes = ref<number[]>([]);
const asdOptions = ref<number[]>([]); const asdOptions = ref<number[]>([]);
let copySelectGraphic: ScreenDoor | null = null;
watch( watch(
() => lineStore.selectedGraphics, () => lineStore.selectedGraphics,
(val) => { (val, oldVal) => {
if (val?.length == 1 && val[0].type == ScreenDoor.Type) { if (oldVal?.length == 1 && oldVal[0] instanceof ScreenDoor) {
initScreenDoorState(val[0] as ScreenDoor); unSubscribeState(oldVal[0]);
}
if (val?.length == 1 && val[0] instanceof ScreenDoor) {
copySelectGraphic = toRaw(val[0]);
initScreenDoorState(val[0]);
} else { } else {
copySelectGraphic = null;
screenDoorState.value = new ScreenDoorState(); screenDoorState.value = new ScreenDoorState();
} }
} }
); );
onMounted(() => {
if (lineStore.selectedGraphics) {
initScreenDoorState(lineStore.selectedGraphics[0] as ScreenDoor);
}
});
function initScreenDoorState(screenDoor: ScreenDoor) { function initScreenDoorState(screenDoor: ScreenDoor) {
copySelectGraphic = toRaw(screenDoor);
code.value = screenDoor.datas.code; code.value = screenDoor.datas.code;
asdOptions.value = []; asdOptions.value = [];
sonDoorAmount.value = screenDoor.datas.sonDoorAmount; sonDoorAmount.value = screenDoor.datas.sonDoorAmount;
@ -178,6 +192,11 @@ function initScreenDoorState(screenDoor: ScreenDoor) {
asdOptions.value.push(i); asdOptions.value.push(i);
} }
} }
updateState(screenDoor);
subscribeState(screenDoor);
}
function updateState(screenDoor: ScreenDoor) {
screenDoorState.value = screenDoor.states.clone() as ScreenDoorState; screenDoorState.value = screenDoor.states.clone() as ScreenDoorState;
asdCodes.value = screenDoorState.value.param.asdCodes; asdCodes.value = screenDoorState.value.param.asdCodes;
screenDoorForce.value = screenDoorState.value.param.force; screenDoorForce.value = screenDoorState.value.param.force;
@ -209,31 +228,19 @@ function doScreenDoorOperation(item: {
} }
} }
onMounted(() => { function subscribeState(g: ScreenDoor) {
if (lineStore.selectedGraphics) { g.on('stateupdate', updateState);
initScreenDoorState(lineStore.selectedGraphics[0] as ScreenDoor); }
function unSubscribeState(g: ScreenDoor) {
g.off('stateupdate', updateState);
}
onUnmounted(() => {
if (copySelectGraphic) {
unSubscribeState(copySelectGraphic);
} }
}); });
watch(
() => lineStore.socketStates,
(val) => {
if (val && screenDoorState.value.code) {
const find = val.find((item) => {
return (
item.graphicType == ScreenDoor.Type &&
(item as ScreenDoorState).code == screenDoorState.value.code
);
});
if (find) {
screenDoorState.value = find.clone() as ScreenDoorState;
asdCodes.value = screenDoorState.value.param.asdCodes;
screenDoorForce.value = screenDoorState.value.param.force;
screenDoorFault.value = screenDoorState.value.param.fault;
}
}
}
);
</script> </script>
<style scoped> <style scoped>

View File

@ -81,11 +81,10 @@
</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, watch, onMounted } from 'vue'; import { ref, watch, onMounted, onUnmounted, toRaw } from 'vue';
import { Section, type ISectionState } from 'src/graphics/section/Section'; import { Section } from 'src/graphics/section/Section';
import { request } from 'src/protos/request'; import { request } from 'src/protos/request';
import { Dialog } from 'quasar'; import { Dialog } from 'quasar';
import { SectionStates } from 'src/drawApp/graphics/SectionInteraction';
import SectionOperation from 'src/components/draw-app/dialogs/SectionOperation.vue'; import SectionOperation from 'src/components/draw-app/dialogs/SectionOperation.vue';
import { setAxleSectionState } from 'src/api/Simulation'; import { setAxleSectionState } from 'src/api/Simulation';
import { errorNotify } from 'src/utils/CommonNotify'; import { errorNotify } from 'src/utils/CommonNotify';
@ -99,13 +98,19 @@ const sectionState = ref({
axleDrst: false, axleDrst: false,
axlePdrst: false, axlePdrst: false,
}); });
let copySelectGraphic: Section | null = null;
watch( watch(
() => lineStore.selectedGraphics, () => lineStore.selectedGraphics,
(val) => { (val, oldVal) => {
if (val?.length == 1 && val[0].type == Section.Type) { if (oldVal?.length == 1 && oldVal[0] instanceof Section) {
setSectionState(val[0] as Section); unSubscribeState(oldVal[0]);
}
if (val?.length == 1 && val[0] instanceof Section) {
copySelectGraphic = toRaw(val[0]);
initSectionState(val[0] as Section);
} else { } else {
copySelectGraphic = null;
sectionState.value = { sectionState.value = {
id: 0, id: 0,
code: '', code: '',
@ -117,7 +122,15 @@ watch(
} }
} }
); );
function setSectionState(section: Section) {
onMounted(() => {
if (lineStore.selectedGraphics) {
initSectionState(lineStore.selectedGraphics[0] as Section);
}
});
function initSectionState(section: Section) {
copySelectGraphic = toRaw(section);
sectionState.value = { sectionState.value = {
id: section.datas.id, id: section.datas.id,
code: section.datas.code, code: section.datas.code,
@ -126,13 +139,19 @@ function setSectionState(section: Section) {
axleDrst: section.states.axleDrst ?? false, axleDrst: section.states.axleDrst ?? false,
axlePdrst: section.states.axlePdrst ?? false, axlePdrst: section.states.axlePdrst ?? false,
}; };
subscribeState(section);
} }
onMounted(() => { function updateState(newVal: Section) {
if (lineStore.selectedGraphics) { sectionState.value = {
setSectionState(lineStore.selectedGraphics[0] as Section); id: newVal.id,
} code: sectionState.value.code,
}); axleFault: newVal.states.axleFault ?? false,
occupied: newVal.states.occupied ?? false,
axleDrst: newVal.states.axleDrst ?? false,
axlePdrst: newVal.states.axlePdrst ?? false,
};
}
const options = [ const options = [
{ {
@ -144,6 +163,7 @@ const options = [
value: request.Section.Operation.SetFaultOcc, value: request.Section.Operation.SetFaultOcc,
}, },
]; ];
function doSectionOperation(item: { label: string; value: number }) { function doSectionOperation(item: { label: string; value: number }) {
if (!lineStore.simulationId) return; if (!lineStore.simulationId) return;
if (item.label == '设置参数') { if (item.label == '设置参数') {
@ -173,27 +193,18 @@ function doSectionOperation(item: { label: string; value: number }) {
); );
} }
} }
watch(
() => lineStore.socketStates, function subscribeState(g: Section) {
(val) => { g.on('stateupdate', updateState);
if (val && sectionState.value.id) { }
const find = val.find((item): item is SectionStates => {
return ( function unSubscribeState(g: Section) {
item.graphicType == Section.Type && g.off('stateupdate', updateState);
(item as ISectionState).id == sectionState.value.id }
);
}); onUnmounted(() => {
if (find) { if (copySelectGraphic) {
sectionState.value = { unSubscribeState(copySelectGraphic);
id: find.id,
code: sectionState.value.code,
axleFault: find.axleFault,
occupied: find.occupied,
axleDrst: find.axleDrst,
axlePdrst: find.axlePdrst,
};
}
}
} }
); });
</script> </script>

View File

@ -160,7 +160,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { Turnout } from 'src/graphics/turnout/Turnout'; import { Turnout } from 'src/graphics/turnout/Turnout';
import { useLineStore } from 'src/stores/line-store'; import { useLineStore } from 'src/stores/line-store';
import { ref, watch, onMounted, onUnmounted } from 'vue'; import { ref, watch, onMounted, onUnmounted, toRaw } from 'vue';
import { Dialog } from 'quasar'; import { Dialog } from 'quasar';
import { TurnoutStates } from 'src/drawApp/graphics/TurnoutInteraction'; import { TurnoutStates } from 'src/drawApp/graphics/TurnoutInteraction';
import TurnoutOperation from 'src/components/draw-app/dialogs/TurnoutOperation.vue'; import TurnoutOperation from 'src/components/draw-app/dialogs/TurnoutOperation.vue';
@ -171,7 +171,6 @@ const lineStore = useLineStore();
const turnoutState = ref<TurnoutStates>(new TurnoutStates()); const turnoutState = ref<TurnoutStates>(new TurnoutStates());
const name = ref(''); const name = ref('');
const forcePosition = ref<request.Points.Force>(0); const forcePosition = ref<request.Points.Force>(0);
const graphic = ref();
const turnoutForceOption = [ const turnoutForceOption = [
{ {
label: '无强制', label: '无强制',
@ -190,6 +189,8 @@ const turnoutForceOption = [
value: request.Points.Force.FP_SB, value: request.Points.Force.FP_SB,
}, },
]; ];
const options = [{ label: '设置参数' }];
let copySelectGraphic: Turnout | null = null;
watch( watch(
() => lineStore.selectedGraphics, () => lineStore.selectedGraphics,
@ -197,31 +198,35 @@ watch(
if (oldVal?.length == 1 && oldVal[0].type == Turnout.Type) { if (oldVal?.length == 1 && oldVal[0].type == Turnout.Type) {
unSubscribeState(oldVal[0] as JlGraphic); unSubscribeState(oldVal[0] as JlGraphic);
} }
if (val?.length == 1 && val[0].type == Turnout.Type) { if (val?.length == 1 && val[0] instanceof Turnout) {
graphic.value = val[0]; copySelectGraphic = toRaw(val[0]);
setTurnoutState(val[0] as Turnout); initTurnoutState(val[0] as Turnout);
} else { } else {
turnoutState.value = new TurnoutStates(); turnoutState.value = new TurnoutStates();
name.value = ''; name.value = '';
graphic.value = null; copySelectGraphic = null;
} }
} }
); );
function setTurnoutState(turnout: Turnout) {
graphic.value = turnout; onMounted(() => {
if (lineStore.selectedGraphics) {
initTurnoutState(lineStore.selectedGraphics[0] as Turnout);
}
});
function initTurnoutState(turnout: Turnout) {
copySelectGraphic = toRaw(turnout);
turnoutState.value = turnout.states.clone() as TurnoutStates; turnoutState.value = turnout.states.clone() as TurnoutStates;
forcePosition.value = turnoutState.value.param?.forcePosition; forcePosition.value = turnoutState.value.param?.forcePosition;
name.value = turnout.datas.code; name.value = turnout.datas.code;
subscribeState(turnout as JlGraphic); subscribeState(turnout as JlGraphic);
} }
onMounted(() => { function updateState(newVal: TurnoutStates) {
if (lineStore.selectedGraphics) { turnoutState.value = newVal.clone() as TurnoutStates;
setTurnoutState(lineStore.selectedGraphics[0] as Turnout); forcePosition.value = turnoutState.value.param?.forcePosition;
} }
});
const options = [{ label: '设置参数' }];
function doTurnoutOperation(item: { label: string }) { function doTurnoutOperation(item: { label: string }) {
if (!lineStore.simulationId) return; if (!lineStore.simulationId) return;
@ -249,19 +254,16 @@ function subscribeState(g: JlGraphic) {
g.on('stateupdate', updateState); g.on('stateupdate', updateState);
} }
} }
function unSubscribeState(g: JlGraphic) { function unSubscribeState(g: JlGraphic) {
if (g) { if (g) {
g.off('stateupdate', updateState); g.off('stateupdate', updateState);
} }
} }
function updateState(newVal: TurnoutStates) {
turnoutState.value = newVal.clone() as TurnoutStates;
forcePosition.value = turnoutState.value.param?.forcePosition;
}
onUnmounted(() => { onUnmounted(() => {
if (graphic.value) { if (copySelectGraphic) {
unSubscribeState(graphic.value as JlGraphic); unSubscribeState(copySelectGraphic);
} }
}); });
</script> </script>