useGraphic.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. const changeIndex = ref(0)
  20. export const changeStore = () => changeIndex.value++
  21. export const useChange = (fn: () => void) => {
  22. return watchEffect(() => {
  23. changeIndex.value;
  24. fn()
  25. })
  26. }
  27. export const graphicState = ref({
  28. canRevoke: false,
  29. canRecovery: false,
  30. showBackImage: true,
  31. canAngleLocationMode: false,
  32. canAllLocationMode: false,
  33. existsBaseLine: false,
  34. })
  35. export const setCanvas = async (canvas: HTMLCanvasElement, data: Ref<AccidentPhoto | RoadPhoto>) => {
  36. await import("../graphic/index.js").then((model) => {
  37. drawRef.value = model.structureDraw(canvas, newsletter, graphicState);
  38. watch(
  39. () => data.value?.id,
  40. (id, oldId) => {
  41. if (data.value) {
  42. oldId && drawRef.value.load.clear()
  43. console.log("load", data.value)
  44. drawRef.value.load.load(data.value.data, {
  45. ...data.value.sceneData,
  46. backImage: getStaticFile(data.value.photoUrl)
  47. })
  48. } else {
  49. drawRef.value.load.clear()
  50. }
  51. },
  52. { immediate: true }
  53. )
  54. });
  55. };
  56. export const drawRef = ref<ReturnType<typeof structureDraw>>();
  57. export const uiType = reactive({
  58. current: computed(() => newsletter.value.selectUI),
  59. change: (type: UITypeT[keyof UITypeT]) => {
  60. drawRef.value.uiControl.selectUI = type
  61. }
  62. })
  63. export const currentVector = computed(() => newsletter.value.focusVector)
  64. export { VectorType, UIType }