index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <RightFillPano>
  3. <h3>{{ tagging?.title }}放置位置</h3>
  4. <Collapse v-model:activeKey="showId" ghost accordion expandIconPosition="end">
  5. <template v-for="(position, i) in positions" :key="position.id">
  6. <PositionSign
  7. v-show="!(unKeepAdding && position.id !== showId)"
  8. :position="position"
  9. :title="`位置${i + 1}`"
  10. @applyGlobal="(keys) => applyGlobal(position, keys)"
  11. @delete="deletePosition(position)"
  12. @show="showId = position.id"
  13. />
  14. </template>
  15. </Collapse>
  16. <Teleport to="#layout-app">
  17. <span
  18. @click="unKeepAdding ? unKeepAdding() : keepAdding()"
  19. class="pin-position strengthen fun-ctrl"
  20. >
  21. <ui-icon
  22. :style="{ color: unKeepAdding ? 'var(--color-main-normal)' : 'currentColor' }"
  23. type="pin1"
  24. size="22px"
  25. />
  26. </span>
  27. </Teleport>
  28. </RightFillPano>
  29. </template>
  30. <script lang="ts" setup>
  31. import PositionSign from "./sign.vue";
  32. import { router } from "@/router";
  33. import { Dialog, Message } from "bill/index";
  34. import { RightFillPano } from "@/layout";
  35. import { asyncTimeout } from "@/utils";
  36. import { useViewStack } from "@/hook";
  37. import {
  38. computed,
  39. nextTick,
  40. onUnmounted,
  41. ref,
  42. shallowRef,
  43. watch,
  44. watchEffect,
  45. } from "vue";
  46. import { getTaggingPosNode, sdk, taggingsGroup } from "@/sdk";
  47. import { custom, showTaggingPositionsStack } from "@/env";
  48. import {
  49. autoSaveTaggings,
  50. getFuseModel,
  51. getFuseModelShowVariable,
  52. getTaggingPositions,
  53. taggingPositions,
  54. createTaggingPosition,
  55. getTagging,
  56. enterEdit,
  57. } from "@/store";
  58. import { Collapse } from "ant-design-vue";
  59. import type { TaggingPosition } from "@/store";
  60. import { clickListener } from "@/utils/event";
  61. const showId = ref<TaggingPosition["id"]>();
  62. const tagging = computed(() => getTagging(router.currentRoute.value.params.id as string));
  63. const positions = computed(() => tagging.value && getTaggingPositions(tagging.value));
  64. onUnmounted(() => unKeepAdding.value && unKeepAdding.value());
  65. useViewStack(autoSaveTaggings);
  66. useViewStack(() => {
  67. taggingsGroup.changeCanMove(true);
  68. taggingsGroup.showDelete(true);
  69. enterEdit(() => router.back());
  70. return () => {
  71. taggingsGroup.changeCanMove(false);
  72. taggingsGroup.showDelete(false);
  73. };
  74. });
  75. watch(showId, (id) => {
  76. const position = positions.value?.find((item) => item.id === id);
  77. console.log(custom.showMode);
  78. if (custom.showMode === "fuse") {
  79. position && flyTaggingPosition(position);
  80. }
  81. });
  82. let pop: () => void;
  83. const flyTaggingPosition = (position: TaggingPosition) => {
  84. pop && pop();
  85. const model = getFuseModel(position.modelId);
  86. if (!model || !getFuseModelShowVariable(model).value) {
  87. return;
  88. }
  89. pop = showTaggingPositionsStack.push(ref(new WeakSet([position])));
  90. sdk.comeTo({
  91. position: getTaggingPosNode(position)!.getImageCenter(),
  92. modelId: position.modelId,
  93. dur: 300,
  94. // distance: 3,
  95. maxDis: 15,
  96. });
  97. };
  98. onUnmounted(() => pop && pop());
  99. const deletePosition = (position: TaggingPosition) => {
  100. const index = taggingPositions.value.indexOf(position);
  101. if (~index) {
  102. taggingPositions.value.splice(index, 1);
  103. }
  104. };
  105. const applyGlobal = async (position: TaggingPosition, keys: string | string[]) => {
  106. if (!(await Dialog.confirm("确定要将此属性应用到所有位置?"))) return;
  107. keys = Array.isArray(keys) ? keys : [keys];
  108. for (const current of positions.value!) {
  109. let val: any = current;
  110. let newVal: any = position;
  111. for (let i = 0; i < keys.length; i++) {
  112. if (i === keys.length - 1) {
  113. val[keys[i]] = newVal[keys[i]];
  114. } else {
  115. val = val[keys[i]];
  116. newVal = newVal[keys[i]];
  117. }
  118. }
  119. }
  120. };
  121. let unKeepAdding = shallowRef<() => void>();
  122. const keepAdding = () => {
  123. unKeepAdding.value && unKeepAdding.value();
  124. sdk.startAddSth();
  125. const hide = Message.show({ msg: "请在模型上单击选择标签位置", type: "warning" });
  126. showId.value = void 0;
  127. const removeListener = clickListener(sdk.layout, async (pos) => {
  128. await nextTick();
  129. await asyncTimeout();
  130. const position = sdk.getPositionByScreen(pos);
  131. if (!position) {
  132. Message.error("当前位置无法添加");
  133. } else {
  134. const storePosition = createTaggingPosition({
  135. ...position,
  136. normal: position.localNormal,
  137. taggingId: tagging.value!.id,
  138. });
  139. taggingPositions.value.push(storePosition);
  140. showId.value = storePosition.id;
  141. nextTick(() => {
  142. getTaggingPosNode(storePosition)!.changeCanMove(true);
  143. });
  144. }
  145. });
  146. unKeepAdding.value = () => {
  147. hide();
  148. sdk.endAddSth();
  149. removeListener();
  150. unKeepAdding.value = void 0;
  151. };
  152. };
  153. keepAdding();
  154. </script>
  155. <style lang="scss" scoped>
  156. h3 {
  157. font-family: Microsoft YaHei, Microsoft YaHei;
  158. font-weight: bold;
  159. font-size: 16px;
  160. color: #999999;
  161. margin-bottom: 4px;
  162. }
  163. .pin-position {
  164. position: absolute;
  165. left: 50%;
  166. transform: translate(-50%);
  167. width: 64px;
  168. height: 64px;
  169. background: rgba(27, 27, 28, 0.8);
  170. border-radius: 50%;
  171. bottom: 20px;
  172. z-index: 9;
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. }
  177. </style>
  178. <style lang="scss">
  179. .position-group .group-title {
  180. margin-bottom: 0;
  181. }
  182. </style>