61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { store } from "@/store";
|
|
|
|
interface IPathDrawingState {
|
|
active: boolean;
|
|
template: Record<string, any> | null;
|
|
submit: ((payload: IPathDrawingResult) => void) | null;
|
|
}
|
|
|
|
export interface IPathDrawingResult {
|
|
worldPoints: Array<{ x: number; y: number; z: number }>;
|
|
origin: { x: number; y: number; z: number };
|
|
options: Record<string, any>;
|
|
}
|
|
|
|
export interface IPathDrawingRequest {
|
|
template?: Record<string, any> | null;
|
|
submit?: (payload: IPathDrawingResult) => void;
|
|
}
|
|
|
|
function isPathDrawingRequest(payload: Record<string, any> | IPathDrawingRequest) {
|
|
return Object.prototype.hasOwnProperty.call(payload, "template") || Object.prototype.hasOwnProperty.call(payload, "submit");
|
|
}
|
|
|
|
export const usePathDrawingStore = defineStore({
|
|
id: "pathDrawing",
|
|
state: (): IPathDrawingState => ({
|
|
active: false,
|
|
template: null,
|
|
submit: null,
|
|
}),
|
|
getters: {
|
|
isActive: state => state.active,
|
|
getTemplate: state => state.template,
|
|
getSubmit: state => state.submit,
|
|
},
|
|
actions: {
|
|
start(payload: Record<string, any> | IPathDrawingRequest) {
|
|
const request = isPathDrawingRequest(payload) ? payload : { template: payload };
|
|
|
|
this.template = request.template ? JSON.parse(JSON.stringify(request.template)) : null;
|
|
this.submit = typeof request.submit === "function" ? request.submit : null;
|
|
this.active = true;
|
|
},
|
|
cancel() {
|
|
this.active = false;
|
|
this.template = null;
|
|
this.submit = null;
|
|
},
|
|
finish() {
|
|
this.active = false;
|
|
this.template = null;
|
|
this.submit = null;
|
|
},
|
|
},
|
|
});
|
|
|
|
export function usePathDrawingStoreWithOut() {
|
|
return usePathDrawingStore(store);
|
|
}
|