index.vue 6.2 KB

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