index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="go-shape-box">
  3. <slot></slot>
  4. <!-- 锚点 -->
  5. <div
  6. :class="`shape-point ${point}`"
  7. v-for="(point, index) in (select? pointList : [])"
  8. :key="index"
  9. :style="usePointStyle(point, index, item.attr, cursorResize)"
  10. @mousedown="useMousePointHandle($event, point, item.attr)"
  11. ></div>
  12. <!-- 选中 -->
  13. <div class="shape-modal" :style="useSizeStyle(item.attr)">
  14. <div class="shape-modal-select" :class="{ active: select }"></div>
  15. <div
  16. class="shape-modal-change"
  17. :class="{ selectActive: select, hoverActive: hover }"
  18. ></div>
  19. </div>
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. import { ref, computed, PropType, toRefs } from 'vue'
  24. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  25. import { useDesignStore } from '@/store/modules/designStore/designStore'
  26. import { CreateComponentType } from '@/packages/index.d'
  27. import { useSizeStyle, usePointStyle } from '../../hooks/useStyle.hook'
  28. import { useMousePointHandle } from '../../hooks/useDrag.hook'
  29. const props = defineProps({
  30. item: {
  31. type: Object as PropType<CreateComponentType>,
  32. required: true
  33. }
  34. })
  35. // 全局颜色
  36. const designStore = useDesignStore()
  37. const themeColor = ref(designStore.getAppTheme)
  38. const chartEditStore = useChartEditStore()
  39. // 锚点
  40. const pointList = ['t', 'r', 'b', 'l', 'lt', 'rt', 'lb', 'rb']
  41. // 光标朝向
  42. const cursorResize = ['n', 'e', 's', 'w', 'nw', 'ne', 'sw', 'se']
  43. // 计算当前选中目标
  44. const hover = computed(() => {
  45. return props.item.id === chartEditStore.getTargetChart.hoverId
  46. })
  47. const select = computed(() => {
  48. return props.item.id === chartEditStore.getTargetChart.selectId
  49. })
  50. </script>
  51. <style lang="scss" scoped>
  52. @include go(shape-box) {
  53. position: absolute;
  54. cursor: move;
  55. /* 锚点 */
  56. .shape-point {
  57. z-index: 1;
  58. position: absolute;
  59. width: 7px;
  60. height: 7px;
  61. border: 3px solid v-bind('themeColor');
  62. border-radius: 5px;
  63. background-color: #fff;
  64. transform: translate(-40%, -30%);
  65. &.t,
  66. &.b {
  67. width: 30px;
  68. transform: translate(-50%, -50%);
  69. }
  70. &.l,
  71. &.r {
  72. height: 30px;
  73. }
  74. &.r {
  75. transform: translate(-20%, -50%);
  76. }
  77. &.l {
  78. transform: translate(-45%, -50%);
  79. }
  80. &.rt,
  81. &.rb
  82. {
  83. transform: translate(-30%, -30%);
  84. }
  85. }
  86. /* 选中 */
  87. .shape-modal {
  88. position: absolute;
  89. top: 0;
  90. left: 0;
  91. .shape-modal-select,
  92. .shape-modal-change {
  93. position: absolute;
  94. width: 100%;
  95. height: 100%;
  96. border-radius: 10px;
  97. }
  98. .shape-modal-select {
  99. opacity: 0.1;
  100. top: 2px;
  101. left: 2px;
  102. &.active {
  103. background-color: v-bind('themeColor');
  104. }
  105. }
  106. .shape-modal-change {
  107. border: 2px solid rgba(0, 0, 0, 0);
  108. &.selectActive,
  109. &.hoverActive {
  110. border-color: v-bind('themeColor');
  111. border-width: 2px;
  112. }
  113. &.hoverActive {
  114. border-style: dotted;
  115. }
  116. &.selectActive {
  117. border-style: solid;
  118. }
  119. }
  120. }
  121. }
  122. </style>