index.vue 3.1 KB

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