index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. }
  69. &.l,
  70. &.r {
  71. height: 30px;
  72. }
  73. &.r,
  74. &.rt,
  75. &.rb
  76. {
  77. transform: translate(-30%, -30%);
  78. }
  79. }
  80. /* 选中 */
  81. .shape-modal {
  82. position: absolute;
  83. top: 0;
  84. left: 0;
  85. .shape-modal-select,
  86. .shape-modal-change {
  87. position: absolute;
  88. width: 100%;
  89. height: 100%;
  90. border-radius: 10px;
  91. }
  92. .shape-modal-select {
  93. opacity: 0.1;
  94. top: 2px;
  95. left: 2px;
  96. &.active {
  97. background-color: v-bind('themeColor');
  98. }
  99. }
  100. .shape-modal-change {
  101. border: 2px solid rgba(0, 0, 0, 0);
  102. &.selectActive,
  103. &.hoverActive {
  104. border-color: v-bind('themeColor');
  105. border-width: 2px;
  106. }
  107. &.hoverActive {
  108. border-style: dotted;
  109. }
  110. &.selectActive {
  111. border-style: solid;
  112. }
  113. }
  114. }
  115. }
  116. </style>