AlignmentLine.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div class="alignment-line" :style="{ left, top }">
  3. <div :class="['line', type]" :style="sizeStyle"></div>
  4. </div>
  5. </template>
  6. <script lang="ts" setup>
  7. import { computed } from 'vue'
  8. import type { AlignmentLineAxis } from '@/types/edit'
  9. const props = defineProps<{
  10. type: 'vertical' | 'horizontal'
  11. axis: AlignmentLineAxis
  12. length: number
  13. canvasScale: number
  14. }>()
  15. // 吸附对齐线的位置
  16. const left = computed(() => props.axis.x * props.canvasScale + 'px')
  17. const top = computed(() => props.axis.y * props.canvasScale + 'px')
  18. // 吸附对齐线的长度
  19. const sizeStyle = computed(() => {
  20. if (props.type === 'vertical') return { height: props.length * props.canvasScale + 'px' }
  21. return { width: props.length * props.canvasScale + 'px' }
  22. })
  23. </script>
  24. <style lang="scss" scoped>
  25. .alignment-line {
  26. position: absolute;
  27. z-index: 100;
  28. .line {
  29. width: 0;
  30. height: 0;
  31. border: 0 dashed $themeColor;
  32. &.vertical {
  33. transform: translateY(-0.5px);
  34. border-left-width: 1px;
  35. }
  36. &.horizontal {
  37. transform: translateX(-0.5px);
  38. border-top-width: 1px;
  39. }
  40. }
  41. }
  42. </style>