FenceItem.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 && props.currentGroupId === group.uid"
  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. currentGroupId: string;
  30. }>();
  31. const emits = defineEmits<{ (e: 'selectGroup', groupId: string): unknown }>();
  32. const handleCircleDragMove = (circleConfig: FenceCircleConfig, e) => {
  33. console.log('circle move', e);
  34. console.log('circle move circleConfig', circleConfig);
  35. const lineAttrs = e.target.parent.find('Line')[0].attrs;
  36. const { x, y, idx } = e.target.attrs;
  37. lineAttrs.points[idx * 2] = x;
  38. lineAttrs.points[idx * 2 + 1] = y;
  39. circleConfig.x = x;
  40. circleConfig.y = y;
  41. };
  42. const handleCircleMouseDown = (e: { cancelBubble: boolean }) => {
  43. /** 阻止冒泡 */
  44. e.cancelBubble = true;
  45. };
  46. const handleGroupMouseDown = (e) => {
  47. if (!props.isEdit) return;
  48. e.target.parent.moveToTop();
  49. emits('selectGroup', e.target.parent.attrs.groupId);
  50. };
  51. </script>
  52. <style scoped></style>