index.vue 2.7 KB

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