index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="go-edit-select" v-if="isSelect" :style="positionStyle">
  3. <div class="select-background"></div>
  4. <div class="select-border"></div>
  5. </div>
  6. </template>
  7. <script setup lang="ts">
  8. import { ref, toRefs, watch, computed } from 'vue'
  9. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  10. import { useDesignStore } from '@/store/modules/designStore/designStore'
  11. import { useSizeStyle, useComponentStyle } from '../../hooks/useStyle.hook'
  12. import { selectBoxIndex } from '@/settings/designSetting'
  13. // 全局颜色
  14. const designStore = useDesignStore()
  15. const chartEditStore = useChartEditStore()
  16. const { isSelect, scale } = toRefs(chartEditStore.getEditCanvas)
  17. const themeColor = computed(() => {
  18. return designStore.getAppTheme
  19. })
  20. // 位置
  21. const positionStyle = ref()
  22. watch(
  23. () => chartEditStore.getMousePosition,
  24. positionInfo => {
  25. if (!isSelect.value) return
  26. // 这里的 x,y 是已经计算过的相对位移值
  27. const { startX, startY, x, y } = positionInfo
  28. const attr = {
  29. zIndex: selectBoxIndex,
  30. // left
  31. x: 0,
  32. // top
  33. y: 0,
  34. // 宽
  35. w: 0,
  36. // 高
  37. h: 0,
  38. // 偏移
  39. offsetX: 0,
  40. offsetY: 0
  41. }
  42. // 处理位置
  43. if (x > startX && y > startY) {
  44. // 右下方向
  45. attr.x = startX
  46. attr.y = startY
  47. attr.w = Math.round((x - startX) / scale.value)
  48. attr.h = Math.round((y - startY) / scale.value)
  49. } else if (x > startX && y < startY) {
  50. // 右上方向
  51. attr.x = startX
  52. attr.w = Math.round((x - startX) / scale.value)
  53. attr.h = Math.round((startY - y) / scale.value)
  54. attr.y = startY - attr.h
  55. } else if (x < startX && y > startY) {
  56. // 左下方向
  57. attr.y = startY
  58. attr.w = Math.round((startX - x) / scale.value)
  59. attr.h = Math.round((y - startY) / scale.value)
  60. attr.x = startX - attr.w
  61. } else {
  62. // 左上方向
  63. attr.w = Math.round((startX - x) / scale.value)
  64. attr.h = Math.round((startY - y) / scale.value)
  65. attr.x = startX - attr.w
  66. attr.y = startY - attr.h
  67. }
  68. positionStyle.value = {
  69. ...useComponentStyle(attr, selectBoxIndex),
  70. ...useSizeStyle(attr)
  71. }
  72. },
  73. {
  74. deep: true
  75. }
  76. )
  77. </script>
  78. <style lang="scss" scoped>
  79. @include go('edit-select') {
  80. position: absolute;
  81. .select-border,
  82. .select-background {
  83. position: absolute;
  84. width: 100%;
  85. height: 100%;
  86. border-radius: 10px;
  87. overflow: hidden;
  88. }
  89. .select-border {
  90. left: 0;
  91. top: 0;
  92. opacity: 0.5;
  93. border-width: 2px;
  94. border-style: solid;
  95. border-color: v-bind('themeColor');
  96. }
  97. .select-background {
  98. top: 2px;
  99. left: 2px;
  100. opacity: 0.03;
  101. background-color: v-bind('themeColor');
  102. }
  103. }
  104. </style>