index.vue 3.3 KB

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