80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { QTable } from 'quasar';
|
|
import { getIBPDrawApp, initIBPDrawApp } from 'src/drawApp/ibpDrawApp';
|
|
import { DrawAssistant, IDrawApp, IJlCanvas, JlGraphic } from 'src/jl-graphic';
|
|
import { markRaw } from 'vue';
|
|
|
|
export const useIBPDrawStore = defineStore('ibpDraw', {
|
|
state: () => ({
|
|
drawAssistant: null as DrawAssistant | null,
|
|
selectedGraphics: null as JlGraphic[] | null,
|
|
draftId: null as number | null,
|
|
draftType: 'IBP',
|
|
showRelateDeviceConfig: false,
|
|
table: undefined as QTable | undefined,
|
|
}),
|
|
getters: {
|
|
selectedObjName: (state) => {
|
|
if (state.selectedGraphics) {
|
|
if (state.selectedGraphics.length == 0) {
|
|
return '画布';
|
|
} else if (state.selectedGraphics.length == 1) {
|
|
return state.selectedGraphics[0].type;
|
|
}
|
|
return '多选';
|
|
}
|
|
return '';
|
|
},
|
|
selectedGraphicType: (state) => {
|
|
if (state.selectedGraphics) {
|
|
if (state.selectedGraphics.length === 1) {
|
|
return state.selectedGraphics[0].type;
|
|
}
|
|
}
|
|
},
|
|
selectedGraphic: (state) => {
|
|
if (state.selectedGraphics) {
|
|
if (state.selectedGraphics.length === 1) {
|
|
return state.selectedGraphics[0];
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
},
|
|
actions: {
|
|
getDrawApp(): IDrawApp {
|
|
const app = getIBPDrawApp();
|
|
if (app == null) {
|
|
throw new Error('未初始化app');
|
|
}
|
|
return app;
|
|
},
|
|
getJlCanvas(): IJlCanvas {
|
|
return this.getDrawApp().canvas;
|
|
},
|
|
initDrawApp() {
|
|
const app = initIBPDrawApp();
|
|
app.on('interaction-plugin-resume', (plugin) => {
|
|
if (plugin.isAppPlugin()) {
|
|
if (Object.hasOwn(plugin, '__GraphicDrawAssistant')) {
|
|
this.drawAssistant = plugin as DrawAssistant;
|
|
} else {
|
|
this.drawAssistant = null;
|
|
}
|
|
}
|
|
});
|
|
app.on('graphicselectedchange', () => {
|
|
this.selectedGraphics = markRaw(app.selectedGraphics);
|
|
});
|
|
this.selectedGraphics = [];
|
|
return app;
|
|
},
|
|
setDraftId(id: number | null) {
|
|
this.draftId = id;
|
|
},
|
|
setDraftType(type: string) {
|
|
this.draftType = type;
|
|
},
|
|
},
|
|
});
|