index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 { ref, computed, PropType, toRefs } 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. // 全局颜色
  39. const designStore = useDesignStore()
  40. const themeColor = ref(designStore.getAppTheme)
  41. const chartEditStore = useChartEditStore()
  42. // 锚点
  43. const pointList = ['t', 'r', 'b', 'l', 'lt', 'rt', 'lb', 'rb']
  44. // 光标朝向
  45. const cursorResize = ['n', 'e', 's', 'w', 'nw', 'ne', 'sw', 'se']
  46. // 计算当前选中目标
  47. const hover = computed(() => {
  48. return props.item.id === chartEditStore.getTargetChart.hoverId
  49. })
  50. // 兼容多值场景
  51. const select = computed(() => {
  52. const id = props.item.id
  53. return chartEditStore.getTargetChart.selectId.find((e: string) => e === id)
  54. })
  55. </script>
  56. <style lang="scss" scoped>
  57. @include go(shape-box) {
  58. position: absolute;
  59. cursor: move;
  60. /* 锚点 */
  61. .shape-point {
  62. z-index: 1;
  63. position: absolute;
  64. width: 7px;
  65. height: 7px;
  66. border: 3px solid v-bind('themeColor');
  67. border-radius: 5px;
  68. background-color: #fff;
  69. transform: translate(-40%, -30%);
  70. &.t {
  71. width: 30px;
  72. transform: translate(-50%, -50%);
  73. }
  74. &.b {
  75. width: 30px;
  76. transform: translate(-50%, -30%);
  77. }
  78. &.l,
  79. &.r {
  80. height: 30px;
  81. }
  82. &.r {
  83. transform: translate(-20%, -50%);
  84. }
  85. &.l {
  86. transform: translate(-45%, -50%);
  87. }
  88. &.rt,
  89. &.rb {
  90. transform: translate(-30%, -30%);
  91. }
  92. }
  93. /* 选中 */
  94. .shape-modal {
  95. position: absolute;
  96. top: 0;
  97. left: 0;
  98. .shape-modal-select,
  99. .shape-modal-change {
  100. position: absolute;
  101. width: 100%;
  102. height: 100%;
  103. border-radius: 10px;
  104. }
  105. .shape-modal-select {
  106. opacity: 0.1;
  107. top: 2px;
  108. left: 2px;
  109. &.active {
  110. background-color: v-bind('themeColor');
  111. }
  112. }
  113. .shape-modal-change {
  114. border: 2px solid rgba(0, 0, 0, 0);
  115. &.selectActive,
  116. &.hoverActive {
  117. border-color: v-bind('themeColor');
  118. border-width: 2px;
  119. }
  120. &.hoverActive {
  121. border-style: dotted;
  122. }
  123. &.selectActive {
  124. border-style: solid;
  125. }
  126. }
  127. }
  128. }
  129. </style>