index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. isFlyToTag: true,
  97. });
  98. };
  99. onUnmounted(() => pop && pop());
  100. const deletePosition = (position: TaggingPosition) => {
  101. const index = taggingPositions.value.indexOf(position);
  102. if (~index) {
  103. taggingPositions.value.splice(index, 1);
  104. }
  105. };
  106. const applyGlobal = async (position: TaggingPosition, keys: string | string[]) => {
  107. if (!(await Dialog.confirm("确定要将此属性应用到所有位置?"))) return;
  108. keys = Array.isArray(keys) ? keys : [keys];
  109. for (const current of positions.value!) {
  110. let val: any = current;
  111. let newVal: any = position;
  112. for (let i = 0; i < keys.length; i++) {
  113. if (i === keys.length - 1) {
  114. val[keys[i]] = newVal[keys[i]];
  115. } else {
  116. val = val[keys[i]];
  117. newVal = newVal[keys[i]];
  118. }
  119. }
  120. }
  121. };
  122. let unKeepAdding = shallowRef<() => void>();
  123. const keepAdding = () => {
  124. unKeepAdding.value && unKeepAdding.value();
  125. sdk.startAddSth();
  126. const hide = Message.show({ msg: "请在模型上单击选择标签位置", type: "warning" });
  127. showId.value = void 0;
  128. const removeListener = clickListener(sdk.layout, async (pos) => {
  129. await nextTick();
  130. await asyncTimeout();
  131. const position = sdk.getPositionByScreen(pos);
  132. if (!position) {
  133. Message.error("当前位置无法添加");
  134. } else {
  135. const storePosition = createTaggingPosition({
  136. ...position,
  137. normal: position.localNormal,
  138. taggingId: tagging.value!.id,
  139. });
  140. taggingPositions.value.push(storePosition);
  141. showId.value = storePosition.id;
  142. nextTick(() => {
  143. getTaggingPosNode(storePosition)!.changeCanMove(true);
  144. });
  145. }
  146. });
  147. unKeepAdding.value = () => {
  148. hide();
  149. sdk.endAddSth();
  150. removeListener();
  151. unKeepAdding.value = void 0;
  152. };
  153. };
  154. keepAdding();
  155. </script>
  156. <style lang="scss" scoped>
  157. h3 {
  158. font-family: Microsoft YaHei, Microsoft YaHei;
  159. font-weight: bold;
  160. font-size: 16px;
  161. color: #999999;
  162. margin-bottom: 4px;
  163. }
  164. .pin-position {
  165. position: absolute;
  166. left: 50%;
  167. transform: translate(-50%);
  168. width: 64px;
  169. height: 64px;
  170. background: rgba(27, 27, 28, 0.8);
  171. border-radius: 50%;
  172. bottom: 20px;
  173. z-index: 9;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. }
  178. </style>
  179. <style lang="scss">
  180. .position-group .group-title {
  181. margin-bottom: 0;
  182. }
  183. </style>