index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // 处理位置
  40. if (x > startX && y > startY) {
  41. // 右下方向
  42. attr.x = startX
  43. attr.y = startY
  44. attr.w = Math.round((x - startX) / scale.value)
  45. attr.h = Math.round((y - startY) / scale.value)
  46. } else if (x > startX && y < startY) {
  47. // 右上方向
  48. attr.x = startX
  49. attr.w = Math.round((x - startX) / scale.value)
  50. attr.h = Math.round((startY - y) / scale.value)
  51. attr.y = startY - attr.h
  52. } else if (x < startX && y > startY) {
  53. // 左下方向
  54. attr.y = startY
  55. attr.w = Math.round((startX - x) / scale.value)
  56. attr.h = Math.round((y - startY) / scale.value)
  57. attr.x = startX - attr.w
  58. } else {
  59. // 左上方向
  60. attr.w = Math.round((startX - x) / scale.value)
  61. attr.h = Math.round((startY - y) / scale.value)
  62. attr.x = startX - attr.w
  63. attr.y = startY - attr.h
  64. }
  65. positionStyle.value = {
  66. ...useComponentStyle(attr, selectBoxIndex),
  67. ...useSizeStyle(attr)
  68. }
  69. },
  70. {
  71. deep: true
  72. }
  73. )
  74. </script>
  75. <style lang="scss" scoped>
  76. @include go('edit-select') {
  77. position: absolute;
  78. .select-border,
  79. .select-background {
  80. position: absolute;
  81. width: 100%;
  82. height: 100%;
  83. border-radius: 10px;
  84. overflow: hidden;
  85. }
  86. .select-border {
  87. left: 0;
  88. top: 0;
  89. opacity: 0.5;
  90. border-width: 2px;
  91. border-style: solid;
  92. border-color: v-bind('themeColor');
  93. }
  94. .select-background {
  95. top: 2px;
  96. left: 2px;
  97. opacity: 0.03;
  98. background-color: v-bind('themeColor');
  99. }
  100. }
  101. </style>