arrow.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. <ui-input type="color" class="geo-input" v-model="color" />
  6. <span class="color" :style="{backgroundColor: color}"></span>
  7. </template>
  8. </template>
  9. </GeoTeleport>
  10. <GeoTeleport :menus="typeMenus" v-if="typeMenus" class="type-geo" />
  11. </template>
  12. <script setup lang="ts">
  13. import GeoTeleport from "@/views/graphic/geos/geo-teleport.vue";
  14. import UiInput from "@/components/base/components/input/index.vue";
  15. import UiIcon from "@/components/base/components/icon/index.vue";
  16. import {drawRef, FocusVector, uiType, UIType, useChange} from '@/hook/useGraphic'
  17. import {computed, ref, UnwrapRef, watch, watchEffect} from "vue";
  18. import {dataService} from "@/graphic/Service/DataService";
  19. import GeoActions from "@/graphic/enum/GeoActions"
  20. import {debounce} from "@/utils";
  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. console.log(type.value)
  27. useChange(() => {
  28. color.value = vector.value.color
  29. color.value = vector.value.category
  30. })
  31. const syncVector = ([color, type]) => {
  32. vector.value.setColor(color)
  33. vector.value.setCategory(type)
  34. drawRef.value.renderer.autoRedraw()
  35. drawRef.value.history.save()
  36. }
  37. watch(() => [color.value, type.value], debounce(syncVector, 500))
  38. const typeMenus = ref<UnwrapRef<typeof menus>>()
  39. const menus = ref([
  40. {
  41. key: 'color',
  42. icon: 'del',
  43. text: "颜色"
  44. },
  45. {
  46. key: "type",
  47. icon: "del",
  48. text: "类型",
  49. onClick: () => {
  50. typeMenus.value = !typeMenus.value
  51. ? [
  52. {
  53. key: 'color',
  54. icon: 'arrows_s',
  55. text: "单向",
  56. onClick: () => type.value = "SingleArrowLine"
  57. },
  58. {
  59. key: 'color',
  60. icon: 'arrows_d',
  61. text: "双向",
  62. onClick: () => type.value = "DoubleArrowLine"
  63. },
  64. ]
  65. : null
  66. }
  67. },
  68. {
  69. key: 'copy',
  70. icon: 'copy',
  71. text: "复制",
  72. onClick: () => {
  73. drawRef.value.uiControl.handleGeo(GeoActions.CopyAction)
  74. }
  75. },
  76. {
  77. key: 'del',
  78. icon: 'del',
  79. text: "删除",
  80. onClick: () => {
  81. drawRef.value.uiControl.handleGeo(GeoActions.DeleteAction)
  82. }
  83. }
  84. ])
  85. watchEffect(() => {
  86. menus.value[1].icon = type.value === "SingleArrowLine" ? "arrows_s" : "arrows_d"
  87. })
  88. if (props.geo.category === VectorCategory.Line.NormalLine) {
  89. menus.value.shift()
  90. }
  91. </script>
  92. <style scoped lang="scss">
  93. .color {
  94. width: 18px;
  95. height: 18px;
  96. border: 2px solid #fff;
  97. border-radius: 50%;
  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>