处理订阅

This commit is contained in:
joylink_fanyuhong 2024-11-11 18:16:10 +08:00
parent 2f815a0707
commit 425d8e986b
6 changed files with 43 additions and 12 deletions

View File

@ -95,7 +95,10 @@ export function destroyLineApp(): void {
export function initLineApp(lineId: number): IGraphicApp { export function initLineApp(lineId: number): IGraphicApp {
lineApp = lineAppMap.get(lineId) || null; lineApp = lineAppMap.get(lineId) || null;
if (lineApp) return lineApp; if (lineApp) {
handleSubscribe(lineApp);
return lineApp;
}
lineApp = newGraphicApp({ lineApp = newGraphicApp({
interactiveGraphicTypeIncludes: [ interactiveGraphicTypeIncludes: [
Signal.Type, Signal.Type,
@ -258,6 +261,14 @@ export async function loadLineDatas(): Promise<IGraphicStorage> {
} }
} }
export function cancelSubscribe(lineApp: IGraphicApp) {
const lineStore = useLineStore();
const lineId = lineStore.lineId;
if (lineId) {
lineApp.unsubscribe(`/queue/line/${lineId}/device`);
lineApp.unsubscribe(`/queue/line/${lineId}/train`);
}
}
function handleSubscribe(lineApp: IGraphicApp) { function handleSubscribe(lineApp: IGraphicApp) {
const lineStore = useLineStore(); const lineStore = useLineStore();
const lineId = lineStore.lineId; const lineId = lineStore.lineId;

View File

@ -52,7 +52,10 @@ export function destroyLineNetApp(): void {
} }
export function initLineNetApp(): IGraphicApp { export function initLineNetApp(): IGraphicApp {
if (lineNetApp) return lineNetApp; if (lineNetApp) {
handleSubscribe(lineNetApp);
return lineNetApp;
}
lineNetApp = newGraphicApp({ lineNetApp = newGraphicApp({
interactiveGraphicTypeIncludes: [ interactiveGraphicTypeIncludes: [
RunLine.Type, RunLine.Type,
@ -146,7 +149,10 @@ export async function loadLineNetDatas(): Promise<IGraphicStorage> {
} }
} }
function handleSubscribe(lineNetApp: IGraphicApp) { export function cancelSubscribe(lineApp: IGraphicApp) {
lineApp.unsubscribe('/queue/lineNet');
}
export function handleSubscribe(lineNetApp: IGraphicApp) {
const lineNetStore = useLineNetStore(); const lineNetStore = useLineNetStore();
lineNetApp.enableWsMassaging({ lineNetApp.enableWsMassaging({
wsUrl: `${getWebsocketUrl()}`, wsUrl: `${getWebsocketUrl()}`,

View File

@ -7,7 +7,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, watch } from 'vue'; import { onMounted, onUnmounted, 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.cancelSubscribe();
// }); });
</script> </script>

View File

@ -7,7 +7,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, watch } from 'vue'; import { onMounted, onUnmounted, 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.cancelSubscribe();
// }); });
</script> </script>

View File

@ -4,6 +4,7 @@ import {
initLineNetApp, initLineNetApp,
getLineNetApp, getLineNetApp,
destroyLineNetApp, destroyLineNetApp,
cancelSubscribe,
} from 'src/drawApp/lineNetApp'; } from 'src/drawApp/lineNetApp';
import { markRaw } from 'vue'; import { markRaw } from 'vue';
import { QTable } from 'quasar'; import { QTable } from 'quasar';
@ -72,6 +73,10 @@ export const useLineNetStore = defineStore('lineNet', {
this.selectedGraphics = []; this.selectedGraphics = [];
return app; return app;
}, },
cancelSubscribe() {
const app = this.getLineNetApp();
cancelSubscribe(app);
},
destroy() { destroy() {
this.selectedGraphics = null; this.selectedGraphics = null;
destroyLineNetApp(); destroyLineNetApp();

View File

@ -1,6 +1,11 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { IJlCanvas, JlGraphic, IGraphicApp } from 'jl-graphic'; import { IJlCanvas, JlGraphic, IGraphicApp } from 'jl-graphic';
import { initLineApp, getLineApp, destroyLineApp } from 'src/drawApp/lineApp'; import {
initLineApp,
getLineApp,
destroyLineApp,
cancelSubscribe,
} from 'src/drawApp/lineApp';
import { markRaw } from 'vue'; import { markRaw } from 'vue';
export const useLineStore = defineStore('line', { export const useLineStore = defineStore('line', {
@ -50,6 +55,10 @@ export const useLineStore = defineStore('line', {
this.selectedGraphics = null; this.selectedGraphics = null;
destroyLineApp(); destroyLineApp();
}, },
cancelSubscribe() {
const app = this.getLineApp();
cancelSubscribe(app);
},
setLineId(id: number | null) { setLineId(id: number | null) {
this.lineId = id; this.lineId = id;
}, },