index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <RightPano
  3. v-if="custom.currentModel && active && custom.showMode === 'fuse'"
  4. class="merge-layout"
  5. >
  6. <div class="actions-group">
  7. <Actions :items="actionItems" v-model:current="currentItem" />
  8. <Actions class="merge-action" :items="othActions" single />
  9. </div>
  10. <ui-group>
  11. <ui-group-option label="等比缩放">
  12. <template #icon>
  13. <ui-icon
  14. class="set-prop"
  15. ctrl
  16. :class="{ disabled: isOld || currentItem }"
  17. @click="router.push({
  18. name: RoutesName.proportion,
  19. params: { id: custom.currentModel!.id, save: '1' },
  20. })"
  21. type="ratio"
  22. tip="设置比例"
  23. />
  24. </template>
  25. <ui-input
  26. type="number"
  27. class="scale-input"
  28. v-model="custom.currentModel.scale"
  29. v-bind="modelRange.scaleRange"
  30. :ctrl="false"
  31. width="100%"
  32. >
  33. <template #preIcon><ui-icon type="a-1b1" /></template>
  34. <template #icon>%</template>
  35. </ui-input>
  36. </ui-group-option>
  37. <ui-group-option label="不透明度">
  38. <ui-input
  39. type="range"
  40. v-model="custom.currentModel.opacity"
  41. v-bind="modelRange.opacityRange"
  42. :ctrl="false"
  43. width="100%"
  44. >
  45. <template #icon>%</template>
  46. </ui-input>
  47. </ui-group-option>
  48. </ui-group>
  49. </RightPano>
  50. </template>
  51. <script lang="ts" setup>
  52. import { RoutesName, router } from "@/router";
  53. import { RightPano } from "@/layout";
  54. import { autoSaveFuseModels, defaultFuseModelAttrs, isOld } from "@/store";
  55. import { togetherCallback } from "@/utils";
  56. import { sdk, getSceneModel, modelRange, getFuseModel } from "@/sdk";
  57. import { useViewStack, useActive } from "@/hook";
  58. import {
  59. showLeftPanoStack,
  60. custom,
  61. modelsChangeStoreStack,
  62. showRightPanoStack,
  63. } from "@/env";
  64. import { ref, nextTick, watchEffect, computed, watch, reactive } from "vue";
  65. import { Dialog } from "bill/expose-common";
  66. import Actions from "@/components/actions-merge/index.vue";
  67. import type { ActionsProps, ActionsItem } from "@/components/actions/index.vue";
  68. import { listener } from "@/components/drawing/hook";
  69. import { clickListener, getOffset } from "@/utils/event";
  70. import { useRMenus } from "@/components/right-menu";
  71. import { actionItems, currentItem } from ".";
  72. const active = useActive();
  73. const othActions = reactive([
  74. {
  75. icon: "rectification",
  76. text: "配准",
  77. single: true,
  78. disabled: computed(() => isOld.value || !!currentItem.value),
  79. action: () => {
  80. router.push({
  81. name: RoutesName.registration,
  82. params: { id: custom.currentModel!.id, save: "1" },
  83. });
  84. },
  85. },
  86. {
  87. icon: "reset",
  88. text: "恢复默认",
  89. single: true,
  90. action: () => {
  91. reset();
  92. },
  93. },
  94. ]);
  95. watchEffect(() => {
  96. if (!custom.currentModel) {
  97. currentItem.value = null;
  98. }
  99. });
  100. // watch(
  101. // () => custom.currentModel,
  102. // () => {
  103. // currentItem.value = null;
  104. // }
  105. // );
  106. const reset = async () => {
  107. if (custom.currentModel && (await Dialog.confirm("确定恢复默认?此操作无法撤销"))) {
  108. const rotation = getSceneModel(custom.currentModel)!.getDefaultRotation();
  109. Object.assign(custom.currentModel, {
  110. ...defaultFuseModelAttrs,
  111. rotation: {
  112. x: rotation.x,
  113. y: rotation.y,
  114. z: rotation.z,
  115. },
  116. });
  117. await nextTick();
  118. custom.currentModel && (custom.currentModel.bottom = 0);
  119. }
  120. };
  121. let unMount: (() => void) | null = null;
  122. useViewStack(() =>
  123. togetherCallback([
  124. showLeftPanoStack.push(ref(true)),
  125. showRightPanoStack.push(computed(() => !!custom.currentModel)),
  126. modelsChangeStoreStack.push(ref(true)),
  127. clickListener(
  128. document.querySelector("#layout-app") as HTMLDivElement,
  129. (pixel) => {
  130. const pos = sdk.getPositionByScreen(pixel);
  131. if (!custom.currentModel) return;
  132. unMount && unMount();
  133. setTimeout(() => {
  134. unMount = useRMenus(pixel, [
  135. {
  136. label: "移动到这里",
  137. icon: "move",
  138. handler() {
  139. getSceneModel(custom.currentModel!)?.moveModelTo(pixel, pos?.worldPos);
  140. },
  141. },
  142. ]);
  143. });
  144. },
  145. 2
  146. ),
  147. () => (currentItem.value = null),
  148. ])
  149. );
  150. useViewStack(autoSaveFuseModels);
  151. useViewStack(() => {
  152. const stopWatch = watchEffect(() => {
  153. if (custom.showMode === "pano") {
  154. sdk.hideGrid();
  155. } else {
  156. sdk.showGrid();
  157. }
  158. });
  159. return () => {
  160. sdk.hideGrid();
  161. stopWatch();
  162. };
  163. });
  164. </script>
  165. <style lang="scss" scoped>
  166. .actions-group {
  167. position: absolute;
  168. bottom: 100%;
  169. left: 0;
  170. width: 100%;
  171. margin-bottom: 10px;
  172. gap: 10px;
  173. display: flex;
  174. }
  175. .model-header {
  176. display: flex;
  177. justify-content: space-between;
  178. align-items: center;
  179. margin-bottom: 10px;
  180. p {
  181. font-size: 14px;
  182. color: #fff;
  183. }
  184. }
  185. .model-desc {
  186. color: rgba(255, 255, 255, 0.6);
  187. line-height: 18px;
  188. font-size: 12px;
  189. }
  190. .model-action {
  191. display: flex;
  192. align-items: center;
  193. > * {
  194. margin-left: 20px;
  195. }
  196. }
  197. </style>
  198. <style lang="scss">
  199. .merge-layout {
  200. position: relative;
  201. overflow: initial !important;
  202. top: calc(var(--editor-head-height) + var(--header-top) + 70px) !important;
  203. .ui-input .text.suffix input {
  204. padding-left: 5px;
  205. padding-right: 15px;
  206. }
  207. .ui-input .text.suffix .retouch {
  208. right: 5px;
  209. }
  210. }
  211. .set-prop {
  212. cursor: pointer;
  213. }
  214. .scale-input input {
  215. text-align: right;
  216. padding-right: 20px !important;
  217. }
  218. </style>