图层显示弹窗调整

This commit is contained in:
dong 2023-08-03 10:00:33 +08:00
parent dd471e3a5e
commit 410230669a
4 changed files with 49 additions and 47 deletions

View File

@ -1,6 +1,6 @@
<!-- eslint-disable vue/no-mutating-props --> <!-- eslint-disable vue/no-mutating-props -->
<template> <template>
<q-dialog ref="dialogRef"> <q-dialog v-model="lineStore.showLayerDialog">
<q-card class="q-pa-md"> <q-card class="q-pa-md">
<q-card-section> <div class="text-h6">显示控制</div> </q-card-section> <q-card-section> <div class="text-h6">显示控制</div> </q-card-section>
<q-card-section> <q-card-section>
@ -16,7 +16,7 @@
<div class="row"> <div class="row">
<q-checkbox <q-checkbox
class="col-4" class="col-4"
v-for="(item, index) in props.layerList" v-for="(item, index) in layerList"
:key="index" :key="index"
v-model="list" v-model="list"
:label="item.label" :label="item.label"
@ -26,35 +26,25 @@
</q-card-section> </q-card-section>
<q-card-actions align="right" class="text-primary"> <q-card-actions align="right" class="text-primary">
<q-btn flat label="取消" @click="onDialogCancel" v-close-popup /> <q-btn flat label="取消" @click="onDialogCancel" v-close-popup />
<q-btn flat label="确认" @click="onDialogOK(list)" v-close-popup /> <!-- <q-btn flat label="确认" @click="onDialogOK(list)" v-close-popup /> -->
</q-card-actions> </q-card-actions>
</q-card> </q-card>
</q-dialog> </q-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useDialogPluginComponent } from 'quasar'; import { ref, watch } from 'vue';
import { onMounted, ref, watch } from 'vue'; import { layerList } from 'src/drawApp/lineApp';
interface ItemData { import { useLineStore } from 'src/stores/line-store';
label: string; const lineStore = useLineStore();
value: string;
}
const props = defineProps<{
layerList: ItemData[];
showLayer: string[];
}>();
const list = ref<string[]>([]); const list = ref<string[]>([]);
const allList = ref(false); const allList = ref(false);
onMounted(() => {
list.value = props.showLayer;
allList.value = props.layerList.length == props.showLayer.length;
});
function allListFn() { function allListFn() {
const arr: string[] = []; const arr: string[] = [];
if (allList.value) { if (allList.value) {
props.layerList.forEach((item) => { layerList.forEach((item) => {
arr.push(item.value); arr.push(item.value);
}); });
list.value = arr; list.value = arr;
@ -64,14 +54,34 @@ function allListFn() {
} }
watch( watch(
() => list.value, () => lineStore.showLayerDialog,
(val) => { (val) => {
allList.value = props.layerList.length == val.length; if (val) {
list.value = lineStore.showLayer;
allList.value = layerList.length == lineStore.showLayer.length;
}
} }
); );
defineEmits([...useDialogPluginComponent.emits]); watch(
() => list.value,
(val) => {
lineStore.setShowLayer(val);
allList.value = layerList.length == val.length;
const lineApp = lineStore.getLineApp();
const alllGraphic = lineApp.queryStore.getAllGraphics();
alllGraphic.forEach((g) => {
if (val.includes(g.type)) {
g.visible = true;
} else {
g.visible = false;
}
});
}
);
const { dialogRef, onDialogOK, onDialogCancel } = useDialogPluginComponent(); function onDialogCancel() {
lineStore.setShowLayerDialog(false);
}
</script> </script>
<style scoped></style> <style scoped></style>

View File

@ -67,7 +67,7 @@ import {
} from './graphics/SectionLinkInteraction'; } from './graphics/SectionLinkInteraction';
import { AxleCountingSectionData } from './graphics/AxleCountingSectionInteraction'; import { AxleCountingSectionData } from './graphics/AxleCountingSectionInteraction';
import { LogicSectionData } from './graphics/LogicSectionInteraction'; import { LogicSectionData } from './graphics/LogicSectionInteraction';
import { Dialog, Notify, QNotifyUpdateOptions } from 'quasar'; import { Notify, QNotifyUpdateOptions } from 'quasar';
import { import {
StopPosition, StopPosition,
StopPositionTemplate, StopPositionTemplate,
@ -87,7 +87,6 @@ import {
TransponderTemplate, TransponderTemplate,
} from 'src/graphics/transponder/Transponder'; } from 'src/graphics/transponder/Transponder';
import { TransponderData } from './graphics/TransponderInteraction'; import { TransponderData } from './graphics/TransponderInteraction';
import LayerControlDialog from 'src/components/draw-app/dialogs/LayerControlDialog.vue';
let lineApp: GraphicApp | null = null; let lineApp: GraphicApp | null = null;
@ -129,8 +128,7 @@ const showType = [
]; ];
const physicShowType = [...showType, Section.Type]; const physicShowType = [...showType, Section.Type];
let showLayer = [...physicShowType]; export const layerList = [
const layerList = [
{ label: '区段', value: Section.Type }, { label: '区段', value: Section.Type },
{ label: 'link', value: SectionLink.Type }, { label: 'link', value: SectionLink.Type },
{ label: '计轴', value: AxleCounting.Type }, { label: '计轴', value: AxleCounting.Type },
@ -198,25 +196,9 @@ export function initLineApp(dom: HTMLElement): GraphicApp {
// 画布右键菜单 // 画布右键菜单
lineApp.registerMenu(DefaultCanvasMenu); lineApp.registerMenu(DefaultCanvasMenu);
lineApp.canvas.on('_rightclick', (e) => { lineApp.canvas.on('_rightclick', (e) => {
const alllGraphic = (lineApp as GraphicApp).queryStore.getAllGraphics(); const lineStore = useLineStore();
showOptions.handler = () => { showOptions.handler = () => {
Dialog.create({ lineStore.setShowLayerDialog(true);
title: '显示控制',
message: '',
component: LayerControlDialog,
componentProps: { layerList, showLayer },
cancel: true,
persistent: true,
}).onOk((data: string[]) => {
alllGraphic.forEach((g) => {
if (data.includes(g.type)) {
g.visible = true;
} else {
g.visible = false;
}
});
showLayer = data;
});
}; };
DefaultCanvasMenu.open(e.global); DefaultCanvasMenu.open(e.global);
}); });
@ -295,7 +277,7 @@ export async function loadLineDatas(app: GraphicApp) {
const alllGraphic = (lineApp as GraphicApp).queryStore.getAllGraphics(); const alllGraphic = (lineApp as GraphicApp).queryStore.getAllGraphics();
alllGraphic.forEach((g) => { alllGraphic.forEach((g) => {
if (showLayer.includes(g.type)) { if (physicShowType.includes(g.type)) {
g.visible = true; g.visible = true;
} else { } else {
g.visible = false; g.visible = false;
@ -305,7 +287,7 @@ export async function loadLineDatas(app: GraphicApp) {
(g as Transponder).labelGraphic.visible = false; (g as Transponder).labelGraphic.visible = false;
} }
}); });
lineStore.setShowLayer(physicShowType);
app.enableWsMassaging({ app.enableWsMassaging({
engine: ClientEngine.Centrifugo, engine: ClientEngine.Centrifugo,
wsUrl: `${getWebsocketUrl()}`, wsUrl: `${getWebsocketUrl()}`,

View File

@ -21,6 +21,7 @@
<q-page-container> <q-page-container>
<div id="line-app-container"></div> <div id="line-app-container"></div>
</q-page-container> </q-page-container>
<LayerControlDialog></LayerControlDialog>
</q-layout> </q-layout>
</template> </template>
@ -33,6 +34,7 @@ import { destroySimulation } from 'src/api/Simulation';
import StateProperties from 'src/components/line-app/StateProperties.vue'; import StateProperties from 'src/components/line-app/StateProperties.vue';
// import { Train } from 'src/graphics/train/Train'; // import { Train } from 'src/graphics/train/Train';
// import { Turnout } from 'src/graphics/turnout/Turnout'; // import { Turnout } from 'src/graphics/turnout/Turnout';
import LayerControlDialog from 'src/components/draw-app/dialogs/LayerControlDialog.vue';
const canvasWidth = ref(0); const canvasWidth = ref(0);
const canvasHeight = ref(0); const canvasHeight = ref(0);

View File

@ -10,6 +10,8 @@ export const useLineStore = defineStore('line', {
simulationId: null as string | null, simulationId: null as string | null,
socketStates: null as GraphicState[] | null, socketStates: null as GraphicState[] | null,
stateProCount: 0, stateProCount: 0,
showLayer: [] as string[], // 显示的图层
showLayerDialog: false, // 显示图层控制弹窗
}), }),
getters: { getters: {
selectedGraphicType: (state) => { selectedGraphicType: (state) => {
@ -58,5 +60,11 @@ export const useLineStore = defineStore('line', {
stateProCountIncrease() { stateProCountIncrease() {
this.stateProCount++; this.stateProCount++;
}, },
setShowLayer(v: string[]) {
this.showLayer = v;
},
setShowLayerDialog(v: boolean) {
this.showLayerDialog = v;
},
}, },
}); });