diff --git a/src/components/DrawAppFormUtils.ts b/src/components/DrawAppFormUtils.ts new file mode 100644 index 0000000..33f13eb --- /dev/null +++ b/src/components/DrawAppFormUtils.ts @@ -0,0 +1,27 @@ +import { type GraphicDataBase } from 'src/drawApp/graphics/GraphicDataBase'; +import { IDrawApp } from 'jl-graphic'; +import { onMounted, onUnmounted, reactive, toRaw } from 'vue'; + +export function useFormData( + source: T, + app: IDrawApp +) { + const data = reactive(source); + + onMounted(() => { + app.bindFormData(data); + }); + + onUnmounted(() => { + app.unbindFormData(data); + }); + + function onUpdate() { + const graphic = app.queryStore.queryById(data.id); + if (graphic) { + app.updateGraphicAndRecord(graphic, toRaw(data)); + } + } + + return { data, onUpdate }; +} diff --git a/src/components/draw-app/DrawProperties.vue b/src/components/draw-app/DrawProperties.vue index 349ff48..dbc804f 100644 --- a/src/components/draw-app/DrawProperties.vue +++ b/src/components/draw-app/DrawProperties.vue @@ -22,7 +22,11 @@