AlignmentLine.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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">
  7. import { computed, PropType, defineComponent } from 'vue'
  8. import { useStore } from 'vuex'
  9. import { State } from '@/store'
  10. import { AlignmentLineAxis } from '@/types/edit'
  11. export default defineComponent({
  12. name: 'alignment-line',
  13. props: {
  14. type: {
  15. type: String as PropType<'vertical' | 'horizontal'>,
  16. required: true,
  17. },
  18. axis: {
  19. type: Object as PropType<AlignmentLineAxis>,
  20. required: true,
  21. },
  22. length: {
  23. type: Number,
  24. required: true,
  25. },
  26. offsetX: {
  27. type: Number,
  28. required: true,
  29. },
  30. offsetY: {
  31. type: Number,
  32. required: true,
  33. },
  34. },
  35. setup(props) {
  36. const store = useStore<State>()
  37. const canvasScale = computed(() => store.state.canvasScale)
  38. const left = computed(() => props.axis.x * canvasScale.value + props.offsetX + 'px')
  39. const top = computed(() => props.axis.y * canvasScale.value + props.offsetY + 'px')
  40. const sizeStyle = computed(() => {
  41. if(props.type === 'vertical') return { height: props.length * canvasScale.value + 'px' }
  42. return { width: props.length * canvasScale.value + 'px' }
  43. })
  44. return {
  45. left,
  46. top,
  47. sizeStyle,
  48. }
  49. },
  50. })
  51. </script>
  52. <style lang="scss" scoped>
  53. .alignment-line {
  54. position: absolute;
  55. z-index: 100;
  56. .line {
  57. width: 0;
  58. height: 0;
  59. border: 0 dashed $themeColor;
  60. &.vertical {
  61. margin-left: -0.5px;
  62. border-left-width: 1px;
  63. }
  64. &.horizontal {
  65. margin-top: -0.5px;
  66. border-top-width: 1px;
  67. }
  68. }
  69. }
  70. </style>