保留app

This commit is contained in:
joylink_fanyuhong 2024-11-08 13:55:21 +08:00
parent 0ecd9aac7c
commit b00010901a
5 changed files with 20 additions and 14 deletions

View File

@ -77,21 +77,25 @@ import { useUserStore } from 'src/stores/user-store';
import { getMonitorPath } from 'src/router/routes'; import { getMonitorPath } from 'src/router/routes';
let lineApp: IGraphicApp | null = null; let lineApp: IGraphicApp | null = null;
const lineAppMap = new Map<number, IGraphicApp>();
export function getLineApp() { export function getLineApp() {
return lineApp; return lineApp;
} }
export function destroyLineApp(): void { export function destroyLineApp(): void {
if (lineApp) { for (const key of lineAppMap.keys()) {
lineApp.destroy(); const app = lineAppMap.get(key);
if (app) {
app.destroy();
}
}
lineApp = null; lineApp = null;
} }
}
export function initLineApp(): IGraphicApp { export function initLineApp(lineId: number): IGraphicApp {
lineApp = lineAppMap.get(lineId) || null;
if (lineApp) return lineApp; if (lineApp) return lineApp;
lineApp = newGraphicApp({ lineApp = newGraphicApp({
interactiveGraphicTypeIncludes: [ interactiveGraphicTypeIncludes: [
Signal.Type, Signal.Type,
@ -109,6 +113,7 @@ export function initLineApp(): IGraphicApp {
}, },
dataLoader: loadLineDatas, dataLoader: loadLineDatas,
}); });
lineAppMap.set(lineId, lineApp);
const graphicTemplate = [ const graphicTemplate = [
new TrainTemplate(new TrainData(), new TrainState()), new TrainTemplate(new TrainData(), new TrainState()),

View File

@ -52,6 +52,7 @@ export function destroyLineNetApp(): void {
} }
export function initLineNetApp(): IGraphicApp { export function initLineNetApp(): IGraphicApp {
if (lineNetApp) return lineNetApp;
lineNetApp = newGraphicApp({ lineNetApp = newGraphicApp({
interactiveGraphicTypeIncludes: [ interactiveGraphicTypeIncludes: [
RunLine.Type, RunLine.Type,

View File

@ -7,7 +7,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, watch, onUnmounted } from 'vue'; import { onMounted, watch } from 'vue';
import { useLineStore } from 'src/stores/line-store'; import { useLineStore } from 'src/stores/line-store';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useLineNetStore } from 'src/stores/line-net-store'; import { useLineNetStore } from 'src/stores/line-net-store';
@ -80,7 +80,7 @@ function centerFaultDevice() {
} }
} }
onUnmounted(() => { // onUnmounted(() => {
lineStore.destroy(); // lineStore.destroy();
}); // });
</script> </script>

View File

@ -7,7 +7,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, watch, onUnmounted } from 'vue'; import { onMounted, watch } from 'vue';
import { useLineNetStore } from 'src/stores/line-net-store'; import { useLineNetStore } from 'src/stores/line-net-store';
import { RunLine } from 'src/graphics/runLine/RunLine'; import { RunLine } from 'src/graphics/runLine/RunLine';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
@ -73,7 +73,7 @@ onMounted(() => {
} }
}); });
onUnmounted(() => { // onUnmounted(() => {
lineNetStore.destroy(); // lineNetStore.destroy();
}); // });
</script> </script>

View File

@ -39,7 +39,7 @@ export const useLineStore = defineStore('line', {
}, },
initLineApp(lineId: number) { initLineApp(lineId: number) {
this.setLineId(lineId); this.setLineId(lineId);
const app = initLineApp(); const app = initLineApp(lineId);
app.on('graphicselected', (graphics) => { app.on('graphicselected', (graphics) => {
this.selectedGraphics = markRaw(graphics); this.selectedGraphics = markRaw(graphics);
}); });