renderer.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div
  3. class="draw-layout"
  4. @contextmenu.prevent
  5. :style="{ cursor: cursorStyle }"
  6. ref="layout"
  7. >
  8. <div class="mount-mask" :id="DomOutMountId" />
  9. <div
  10. class="draw-content"
  11. :style="fix && { width: size?.width + 'px', height: size?.height + 'px' }"
  12. >
  13. <div class="mount-mask" :id="DomMountId" />
  14. <v-stage ref="stage" :config="size" v-if="layout">
  15. <v-layer :config="viewerConfig" id="formal">
  16. <Back />
  17. <!-- 不可去除,去除后移动端拖拽会有溢出 -->
  18. <BackGrid v-if="expose.config.showGrid" />
  19. <component
  20. :is="GroupComponentMap[type]"
  21. v-for="type in types"
  22. :type="type"
  23. :key="type"
  24. />
  25. </v-layer>
  26. <!-- 临时组,提供临时绘画,以及高频率渲染 -->
  27. <v-layer :config="viewerConfig" id="temp">
  28. <template v-if="mode.include(Mode.draw)">
  29. <TempShapeGroup v-for="type in types" :type="type" :key="type" />
  30. </template>
  31. </v-layer>
  32. <v-layer id="helper">
  33. <Compass v-if="config.showCompass" />
  34. <ActiveBoxs />
  35. <SnapLines />
  36. <SplitLine v-if="expose.config.showLabelLine" />
  37. <Debugger v-if="isDev" />
  38. <Border />
  39. </v-layer>
  40. </v-stage>
  41. </div>
  42. </div>
  43. </template>
  44. <script lang="ts" setup>
  45. import ShapeGroup from "./group.vue";
  46. import Back from "../helper/back.vue";
  47. import Border from "../helper/facade.vue";
  48. import TempShapeGroup from "./draw-group.vue";
  49. import ActiveBoxs from "../helper/active-boxs.vue";
  50. import SnapLines from "../helper/snap-lines.vue";
  51. import BackGrid from "../helper/back-grid.vue";
  52. import SplitLine from "../helper/split-line.vue";
  53. import Debugger from "../helper/debugger.vue";
  54. import Compass from "../helper/compass.vue";
  55. import { ShapeType, components } from "../components";
  56. import {
  57. InstanceProps,
  58. useCursor,
  59. useInstanceProps,
  60. useMode,
  61. useStage,
  62. } from "../hook/use-global-vars.ts";
  63. import { useViewerTransformConfig } from "../hook/use-viewer.ts";
  64. import { useGlobalResize } from "../hook/use-event.ts";
  65. import { useAutoService, useExpose } from "../hook/use-expose.ts";
  66. import { DomMountId, DomOutMountId } from "../../constant";
  67. import { useStore } from "../store/index.ts";
  68. import { Mode } from "@/constant/mode.ts";
  69. import { computed, getCurrentInstance, ref, watch } from "vue";
  70. import { install } from "../../install-lib.ts";
  71. import { useConfig } from "../hook/use-config.ts";
  72. import { getEmptyStoreData } from "../store/store.ts";
  73. const instance = getCurrentInstance();
  74. install(instance!.appContext.app);
  75. const props = defineProps<InstanceProps>();
  76. const store = useStore();
  77. watch(
  78. () => props.data,
  79. (data) => store.setStore(data || getEmptyStoreData())
  80. );
  81. useInstanceProps().set(props);
  82. useAutoService();
  83. const isDev = import.meta.env.DEV;
  84. const stage = useStage();
  85. const { size, fix } = useGlobalResize();
  86. const layout = ref();
  87. const viewerConfig = useViewerTransformConfig();
  88. const types = Object.keys(components) as ShapeType[];
  89. const mode = useMode();
  90. const config = useConfig();
  91. const GroupComponentMap = types.reduce((map, type) => {
  92. map[type] = components[type].GroupComponent || ShapeGroup;
  93. return map;
  94. }, {} as any);
  95. const cursor = useCursor();
  96. const cursorStyle = computed(() => {
  97. if (cursor.value.includes(".")) {
  98. return `url(${cursor.value}), auto`;
  99. } else {
  100. return cursor.value;
  101. }
  102. });
  103. const expose = useExpose();
  104. defineExpose(expose);
  105. </script>
  106. <style scoped lang="scss">
  107. .draw-layout {
  108. width: 100%;
  109. height: 100%;
  110. overflow: hidden;
  111. position: relative;
  112. display: flex;
  113. align-items: center;
  114. justify-content: center;
  115. .draw-content {
  116. position: relative;
  117. width: 100%;
  118. height: 100%;
  119. }
  120. }
  121. .mount-mask {
  122. position: absolute;
  123. inset: 0;
  124. overflow: hidden;
  125. pointer-events: none;
  126. z-index: 999;
  127. }
  128. </style>