renderer.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="draw-layout">
  3. <div class="mount-mask" :id="DomMountId" />
  4. <v-stage ref="stage" :config="size">
  5. <v-layer :config="viewerConfig" id="formal">
  6. <!-- 不可去除,去除后移动端拖拽会有溢出 -->
  7. <!-- <v-rect
  8. :config="{
  9. ...size,
  10. fill: 'rgba(0,0,0,0)',
  11. listener: false,
  12. ...invertViewerConfig,
  13. }"
  14. /> -->
  15. <ShapeGroup v-for="type in types" :type="type" :key="type" />
  16. </v-layer>
  17. <!-- 临时组,提供临时绘画,以及高频率渲染 -->
  18. <v-layer :config="viewerConfig" id="temp">
  19. <TempShapeGroup v-for="type in types" :type="type" :key="type" />
  20. </v-layer>
  21. <v-layer id="helper">
  22. <ActiveBoxs />
  23. <SnapLines />
  24. </v-layer>
  25. </v-stage>
  26. </div>
  27. </template>
  28. <script lang="ts" setup>
  29. import ShapeGroup from "./group.vue";
  30. import TempShapeGroup from "./draw-group.vue";
  31. import { DrawData, ShapeType, components } from "../components";
  32. import { useStage } from "../hook/use-global-vars.ts";
  33. import { useViewerTransformConfig } from "../hook/use-viewer.ts";
  34. import { useListener, useResize } from "../hook/use-event.ts";
  35. import { useExpose } from "../hook/use-expose.ts";
  36. import { useInteractiveShapeAPI } from "../hook/use-interactive.ts";
  37. import { DomMountId } from "../../constant";
  38. import ActiveBoxs from "../helper/active-boxs.vue";
  39. import SnapLines from "../helper/snap-lines.vue";
  40. import { useStore } from "../store/index.ts";
  41. const props = defineProps<{
  42. data: DrawData;
  43. }>();
  44. const store = useStore();
  45. store.setStore(props.data);
  46. const stage = useStage();
  47. const size = useResize();
  48. const viewerConfig = useViewerTransformConfig();
  49. const types = Object.keys(components) as ShapeType[];
  50. // 退出添加模式
  51. const { quitMouseAddShape } = useInteractiveShapeAPI();
  52. useListener(
  53. "contextmenu",
  54. (ev) => {
  55. ev.preventDefault();
  56. quitMouseAddShape();
  57. },
  58. document.documentElement
  59. );
  60. defineExpose(useExpose());
  61. </script>
  62. <style scoped lang="scss">
  63. .draw-layout {
  64. width: 100%;
  65. height: 100%;
  66. overflow: hidden;
  67. position: relative;
  68. }
  69. .mount-mask {
  70. position: absolute;
  71. inset: 0;
  72. overflow: hidden;
  73. pointer-events: none;
  74. z-index: 999;
  75. }
  76. </style>