index.vue 6.1 KB

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