arrow.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <GeoTeleport :menus="menus" class="geo-teleport-use" :active="typeMenus && menus[1]">
  3. <template v-slot="{ data }">
  4. <template v-if="data.key === 'color'">
  5. <Color v-model:color="color">
  6. <span class="color" :style="{backgroundColor: color}"></span>
  7. </Color>
  8. </template>
  9. </template>
  10. </GeoTeleport>
  11. <GeoTeleport :menus="typeMenus" v-if="typeMenus" class="type-geo" :active="typeMenus.find(menu => menu.key === type)" />
  12. </template>
  13. <script setup lang="ts">
  14. import GeoTeleport from "@/views/graphic/geos/geo-teleport.vue";
  15. import {drawRef, FocusVector, uiType, UIType, useChange} from '@/hook/useGraphic'
  16. import {computed, ref, UnwrapRef, watch, watchEffect} from "vue";
  17. import {dataService} from "@/graphic/Service/DataService";
  18. import GeoActions from "@/graphic/enum/GeoActions"
  19. import {debounce} from "@/utils";
  20. import Color from '@/components/color/index.vue'
  21. import VectorCategory from "@/graphic/enum/VectorCategory";
  22. const props = defineProps<{geo: FocusVector}>()
  23. const vector = computed(() => dataService.getLine(props.geo.vectorId))
  24. const color = ref("#000000")
  25. const type = ref(props.geo.category || "SingleArrowLine")
  26. useChange(() => {
  27. color.value = vector.value.color
  28. type.value = vector.value.category
  29. })
  30. const syncVector = ([color, type]) => {
  31. vector.value.setColor(color)
  32. vector.value.setCategory(type)
  33. drawRef.value.renderer.autoRedraw()
  34. drawRef.value.history.save()
  35. }
  36. watch(() => [color.value, type.value], debounce(syncVector, 500))
  37. const typeMenus = ref<UnwrapRef<typeof menus>>()
  38. const menus = ref([
  39. {
  40. key: 'color',
  41. icon: 'del',
  42. text: "颜色"
  43. },
  44. {
  45. key: "type",
  46. icon: "del",
  47. text: "类型",
  48. onClick: () => {
  49. typeMenus.value = !typeMenus.value
  50. ? [
  51. {
  52. key: 'SingleArrowLine',
  53. icon: 'arrows_s',
  54. text: "单向",
  55. onClick: () => type.value = "SingleArrowLine"
  56. },
  57. {
  58. key: 'DoubleArrowLine',
  59. icon: 'arrows_d',
  60. text: "双向",
  61. onClick: () => type.value = "DoubleArrowLine"
  62. },
  63. ]
  64. : null
  65. }
  66. },
  67. {
  68. key: 'copy',
  69. icon: 'copy',
  70. text: "复制",
  71. onClick: () => {
  72. drawRef.value.uiControl.handleGeo(GeoActions.CopyAction)
  73. }
  74. },
  75. {
  76. key: 'del',
  77. icon: 'del',
  78. text: "删除",
  79. onClick: () => {
  80. drawRef.value.uiControl.handleGeo(GeoActions.DeleteAction)
  81. }
  82. }
  83. ])
  84. watchEffect(() => {
  85. menus.value[1].icon = type.value === "SingleArrowLine" ? "arrows_s" : "arrows_d"
  86. })
  87. if (props.geo.category === VectorCategory.Line.NormalLine) {
  88. menus.value.shift()
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. .color {
  93. width: 18px;
  94. height: 18px;
  95. border: 2px solid #fff;
  96. border-radius: 50%;
  97. display: inline-block;
  98. }
  99. .icon {
  100. font-size: 16px;
  101. }
  102. .geo-input {
  103. position: absolute;
  104. left: 0;
  105. right: 0;
  106. top: 0;
  107. bottom: 0;
  108. z-index: 1;
  109. opacity: 0;
  110. }
  111. .type-geo {
  112. margin-bottom: 74px;
  113. }
  114. </style>
  115. <style lang="scss">
  116. .select-floating.select-float.dire-top {
  117. margin-top: -10px;
  118. }
  119. </style>