useGraphic.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {computed, reactive, Ref, ref, watch, watchEffect} from "vue";
  2. import { structureDraw } from "@/graphic";
  3. import VectorType from '@/graphic/enum/VectorType'
  4. import UIType from '@/graphic/enum/UIEvents'
  5. import type {RoadPhoto} from '@/store/roadPhotos'
  6. import type {AccidentPhoto} from '@/store/accidentPhotos'
  7. import {getStaticFile} from "@/dbo/main";
  8. export type UITypeT = typeof UIType
  9. export type VectorTypeT = typeof VectorType
  10. export type FocusVector = {
  11. type: VectorTypeT[keyof VectorTypeT],
  12. category?: VectorTypeT[keyof VectorTypeT],
  13. vectorId: string
  14. }
  15. const newsletter = ref<{
  16. selectUI?: UITypeT[keyof UITypeT]
  17. focusVector?: FocusVector
  18. }>({ selectUI: null, focusVector: null });
  19. export const graphicState = ref({
  20. canRevoke: false,
  21. canRecovery: false,
  22. showBackImage: false
  23. })
  24. export const setCanvas = async (canvas: HTMLCanvasElement, data: Ref<AccidentPhoto | RoadPhoto>) => {
  25. await import("../graphic/index.js").then((model) => {
  26. drawRef.value = model.structureDraw(canvas, newsletter, graphicState);
  27. watch(
  28. () => data.value?.id,
  29. (id, oldId) => {
  30. if (data.value) {
  31. oldId && drawRef.value.load.clear()
  32. console.log("load", data.value)
  33. drawRef.value.load.load(data.value.data, {
  34. ...data.value.sceneData,
  35. backImage: getStaticFile(data.value.photoUrl)
  36. })
  37. } else {
  38. drawRef.value.load.clear()
  39. }
  40. },
  41. { immediate: true }
  42. )
  43. });
  44. };
  45. export const drawRef = ref<ReturnType<typeof structureDraw>>();
  46. export const uiType = reactive({
  47. current: computed(() => newsletter.value.selectUI),
  48. change: (type: UITypeT[keyof UITypeT]) => {
  49. drawRef.value.uiControl.selectUI = type
  50. }
  51. })
  52. export const currentVector = computed(() => newsletter.value.focusVector)
  53. export { VectorType, UIType }