fixPoints.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <FixPointPanel
  3. v-for="point in (fixPoints as FixPoint[])"
  4. :key="point.id"
  5. :data="point"
  6. :active="point === customMap.activeFixPoint && !selectMeasure"
  7. @change-pos="(pos) => changePos(point, pos)"
  8. @focus="(isRaw) => select(point, false, isRaw)"
  9. @blur="(isRaw) => unSelect(point, false, isRaw)"
  10. @focus-measure="select(point, true, true)"
  11. @blur-measure="unSelect(point, true, true)"
  12. />
  13. <div ref="menu" @touchstart.stop class="action-menus">
  14. <!-- <ActionsPanel :menus="activeActionMenus" v-show="customMap.activeFixPoint" />-->
  15. <ActionMenus
  16. v-if="drawstatus !== DrawStatus.ing && customMap.activeFixPoint"
  17. :menus="activeActionMenus"
  18. :type="0"
  19. :active-key="edit ? 'edit' : null"
  20. dire="row"
  21. />
  22. <Confirm
  23. v-if="drawstatus === DrawStatus.ing"
  24. :ok="() => (drawstatus = DrawStatus.complete)"
  25. :cancel="() => (drawstatus = DrawStatus.quit)"
  26. :dis-ok="!ready"
  27. />
  28. <!-- <ActionMenus
  29. v-if="ingActionMenus"
  30. :type="0"
  31. :menus="ingActionMenus"
  32. :active-key="null"
  33. dire="row"
  34. /> -->
  35. </div>
  36. <EditFixPoint
  37. v-if="edit"
  38. @quit="edit = null"
  39. v-model:text="edit.text"
  40. ref="dom"
  41. :key="edit.id"
  42. />
  43. </template>
  44. <script setup lang="ts">
  45. import { fixPoints, FixPoint } from "@/store/fixPoint";
  46. import FixPointPanel from "./fixPoint.vue";
  47. import Confirm from "../../graphic/confirm.vue";
  48. import { computed, ref, toRaw, watch, watchEffect } from "vue";
  49. import { customMap } from "@/hook";
  50. import ActionMenus from "@/components/group-button/index.vue";
  51. import EditFixPoint from "@/components/edit-fix-point/index.vue";
  52. import {
  53. delFix3d,
  54. changePos,
  55. quitMeasure,
  56. drawstatus,
  57. DrawStatus,
  58. drawingFix3d,
  59. selectFix3d,
  60. } from "../fixManage";
  61. const edit = ref<FixPoint>();
  62. watchEffect(() => {
  63. if (edit.value !== customMap.activeFixPoint) {
  64. edit.value = null;
  65. }
  66. });
  67. const selectMeasure = ref(false);
  68. const select = (point: FixPoint, onMeasure: boolean = false, onRaw: boolean = false) => {
  69. selectMeasure.value = onMeasure;
  70. customMap.activeFixPoint = point;
  71. if (!onRaw) {
  72. fixPoints.value.forEach((item) => {
  73. console.log("select", toRaw(item) === toRaw(point));
  74. selectFix3d(point, toRaw(item) === toRaw(point));
  75. });
  76. }
  77. };
  78. const unSelect = (
  79. point: FixPoint,
  80. onMeasure: boolean = false,
  81. onRaw: boolean = false
  82. ) => {
  83. selectMeasure.value = onMeasure;
  84. customMap.activeFixPoint =
  85. customMap.activeFixPoint === point ? null : customMap.activeFixPoint;
  86. if (!onRaw) {
  87. selectFix3d(point, false);
  88. }
  89. };
  90. const activeActionMenus = computed(() =>
  91. selectMeasure.value
  92. ? [
  93. {
  94. key: "delete",
  95. icon: "del",
  96. text: "删除",
  97. color: "#FF4D4F",
  98. iconColor: "#fff",
  99. onClick() {
  100. quitMeasure(customMap.activeFixPoint);
  101. },
  102. },
  103. ]
  104. : [
  105. {
  106. key: "edit",
  107. icon: "edit",
  108. text: "编辑",
  109. color: "#161A1A",
  110. iconColor: "#2F8FFF",
  111. onClick() {
  112. edit.value =
  113. edit.value === customMap.activeFixPoint ? null : customMap.activeFixPoint;
  114. },
  115. },
  116. {
  117. key: "delete",
  118. icon: "del",
  119. text: "删除",
  120. color: "#FF4D4F",
  121. iconColor: "#fff",
  122. onClick() {
  123. if (delFix3d(customMap.activeFixPoint)) {
  124. customMap.activeFixPoint = null;
  125. edit.value = null;
  126. }
  127. },
  128. },
  129. ]
  130. );
  131. const ready = ref(false);
  132. watchEffect(() => {
  133. if (drawstatus.value === DrawStatus.ing) {
  134. ready.value = false;
  135. drawingFix3d.value[0].bus.on(
  136. "graphChange",
  137. (data) => (ready.value = data.path.length > 1)
  138. );
  139. }
  140. });
  141. const dom = ref<HTMLDivElement>();
  142. const menu = ref<HTMLDivElement>();
  143. watchEffect((onCleanup) => {
  144. if (edit.value && dom.value) {
  145. const handler = (ev) => {
  146. if (!dom.value.contains(ev.target) && !menu.value.contains(ev.target)) {
  147. edit.value = null;
  148. }
  149. };
  150. // document.documentElement.addEventListener("click", handler)
  151. document.documentElement.addEventListener("touchstart", handler);
  152. onCleanup(() => {
  153. // document.documentElement.removeEventListener("click", handler)
  154. document.documentElement.removeEventListener("touchstart", handler);
  155. });
  156. }
  157. });
  158. </script>
  159. <style lang="scss" scoped>
  160. .action-menus {
  161. position: absolute;
  162. bottom: var(--boundMargin);
  163. left: 50%;
  164. transform: translateX(-50%);
  165. display: flex;
  166. z-index: 2;
  167. .menus {
  168. position: static;
  169. }
  170. }
  171. </style>
  172. <style>
  173. .action-menus .menu.active {
  174. background: none;
  175. }
  176. .search-fix.ui-input .text.suffix input {
  177. padding-right: 50px;
  178. }
  179. </style>