+
import('layouts/DrawLayout.vue'),
},
+ {
+ path: '/linemap/:id',
+ name: 'linemap',
+ component: () => import('layouts/LineLayout.vue'),
+ },
// Always leave this as last one,
// but you can also remove it
diff --git a/src/stores/line-store.ts b/src/stores/line-store.ts
new file mode 100644
index 0000000..7d88c94
--- /dev/null
+++ b/src/stores/line-store.ts
@@ -0,0 +1,46 @@
+import { defineStore } from 'pinia';
+import { JlCanvas, JlGraphic, GraphicApp } from 'src/jl-graphic';
+import { initLineApp, getLineApp, destroyLineApp } from 'src/drawApp/lineApp';
+
+export const useLineStore = defineStore('line', {
+ state: () => ({
+ selectedGraphics: null as JlGraphic[] | null,
+ lineId: null as number | null,
+ }),
+ getters: {
+ selectedGraphicType: (state) => {
+ if (state.selectedGraphics) {
+ if (state.selectedGraphics.length === 1) {
+ return state.selectedGraphics[0].type;
+ }
+ }
+ },
+ },
+ actions: {
+ getLineApp(): GraphicApp {
+ const app = getLineApp();
+ if (app == null) {
+ throw new Error('未初始化app');
+ }
+ return app;
+ },
+ getJlCanvas(): JlCanvas {
+ return this.getLineApp().canvas;
+ },
+ initLineApp(dom: HTMLElement) {
+ const app = initLineApp(dom);
+ app.on('graphicselectedchange', () => {
+ this.selectedGraphics = app.selectedGraphics;
+ });
+ this.selectedGraphics = [];
+ return app;
+ },
+ destroy() {
+ this.selectedGraphics = null;
+ destroyLineApp();
+ },
+ setLineId(id: number | null) {
+ this.lineId = id;
+ },
+ },
+});