FenceItem.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!-- eslint-disable vue/no-use-v-if-with-v-for -->
  2. <template>
  3. <v-group
  4. v-for="group in props.fenceGroups"
  5. :key="group.uid"
  6. :groupId="group.uid"
  7. :draggable="props.draggable && props.isEdit"
  8. :name="group.name"
  9. @mouse-down="handleGroupMouseDown"
  10. >
  11. <v-line :config="group.lineConfig" />
  12. <v-circle
  13. v-if="props.isEdit"
  14. v-for="circleConfig in group.circleConfigs"
  15. :config="circleConfig"
  16. :key="circleConfig"
  17. @mouse-down="handleCircleMouseDown"
  18. @drag-move="handleCircleDragMove(circleConfig, $event)"
  19. />
  20. </v-group>
  21. </template>
  22. <script lang="ts" setup>
  23. import { FenceCircleConfig, FenceGroup } from './types';
  24. const props = defineProps<{
  25. fenceGroups: FenceGroup[];
  26. draggable: boolean;
  27. isEdit: boolean;
  28. }>();
  29. const emits = defineEmits<{ (e: 'selectGroup', groupId: string): unknown }>();
  30. const handleCircleDragMove = (circleConfig: FenceCircleConfig, e) => {
  31. console.log('circle move', e);
  32. console.log('circle move circleConfig', circleConfig);
  33. const lineAttrs = e.target.parent.find('Line')[0].attrs;
  34. const { x, y, idx } = e.target.attrs;
  35. lineAttrs.points[idx * 2] = x;
  36. lineAttrs.points[idx * 2 + 1] = y;
  37. circleConfig.x = x;
  38. circleConfig.y = y;
  39. };
  40. const handleCircleMouseDown = (e: { cancelBubble: boolean }) => {
  41. /** 阻止冒泡 */
  42. e.cancelBubble = true;
  43. };
  44. const handleGroupMouseDown = (e) => {
  45. if (!props.isEdit) return;
  46. e.target.parent.moveToTop();
  47. emits('selectGroup', e.target.parent.attrs.groupId);
  48. };
  49. </script>
  50. <style scoped></style>