Files
ai-agent-admin/web/apps/web-ele/src/components/zq-draw/composables/use-draw-engine.ts
T
2026-06-08 18:14:59 +08:00

35 lines
639 B
TypeScript

import { onMounted, onBeforeUnmount, watch } from 'vue';
import type { DrawData } from '../types';
import { useDrawStore } from '../store/draw-store';
export function useDrawEngine(opts: {
initialData?: DrawData | null;
readonly?: boolean;
}) {
const store = useDrawStore();
onMounted(() => {
store.init();
if (opts.initialData) {
store.loadDrawData(opts.initialData);
}
store.requestRender();
});
watch(
() => opts.readonly,
(val) => {
store.viewModeEnabled = !!val;
store.requestRender();
},
);
onBeforeUnmount(() => {
store.destroy();
});
return { store };
}