index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 } 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. const active = useActive();
  82. const othActions = reactive([
  83. {
  84. icon: "rectification",
  85. text: "配准",
  86. single: true,
  87. disabled: computed(() => isOld.value || !!currentItem.value),
  88. action: () => {
  89. router.push({
  90. name: RoutesName.registration,
  91. params: { id: custom.currentModel!.id, save: "1" },
  92. });
  93. },
  94. },
  95. {
  96. icon: "reset",
  97. text: "恢复默认",
  98. single: true,
  99. action: () => {
  100. reset();
  101. },
  102. },
  103. ]);
  104. const currentAction = ref<any>();
  105. watchEffect(() => {
  106. if (!custom.currentModel) {
  107. currentItem.value = null;
  108. }
  109. });
  110. watch(
  111. () => custom.currentModel,
  112. () => {
  113. let old = currentItem.value;
  114. currentItem.value = null;
  115. console.error("currentItem", currentItem.value, old);
  116. asyncTimeout(16).then(() => {
  117. currentItem.value = old;
  118. console.log("change", currentItem.value);
  119. });
  120. },
  121. { flush: "post" }
  122. );
  123. const reset = async () => {
  124. if (custom.currentModel && (await Dialog.confirm("确定恢复默认?此操作无法撤销"))) {
  125. const rotation = getSceneModel(custom.currentModel)!.getDefaultRotation();
  126. Object.assign(custom.currentModel, {
  127. ...defaultFuseModelAttrs,
  128. rotation: {
  129. x: rotation.x,
  130. y: rotation.y,
  131. z: rotation.z,
  132. },
  133. });
  134. await nextTick();
  135. custom.currentModel && (custom.currentModel.bottom = 0);
  136. }
  137. };
  138. let unMount: (() => void) | null = null;
  139. useViewStack(() =>
  140. togetherCallback([
  141. showLeftPanoStack.push(ref(true)),
  142. showRightPanoStack.push(computed(() => !!custom.currentModel)),
  143. modelsChangeStoreStack.push(ref(true)),
  144. clickListener(
  145. document.querySelector("#layout-app") as HTMLDivElement,
  146. (pixel) => {
  147. const pos = sdk.getPositionByScreen(pixel);
  148. if (!custom.currentModel) return;
  149. unMount && unMount();
  150. setTimeout(() => {
  151. unMount = useRMenus(pixel, [
  152. {
  153. label: "移动到这里",
  154. icon: "move",
  155. handler() {
  156. getSceneModel(custom.currentModel!)?.moveModelTo(pixel, pos?.worldPos);
  157. },
  158. },
  159. ]);
  160. });
  161. },
  162. 2
  163. ),
  164. () => (currentItem.value = null),
  165. ])
  166. );
  167. watchEffect(() => console.error(currentItem.value), { flush: "sync" });
  168. useViewStack(autoSaveFuseModels);
  169. useViewStack(() => {
  170. const stopWatch = watchEffect(() => {
  171. if (custom.showMode === "pano") {
  172. sdk.hideGrid();
  173. } else {
  174. sdk.showGrid();
  175. }
  176. });
  177. return () => {
  178. sdk.hideGrid();
  179. stopWatch();
  180. };
  181. });
  182. </script>
  183. <style lang="scss" scoped>
  184. .actions-group {
  185. position: absolute;
  186. bottom: 100%;
  187. left: 0;
  188. width: 100%;
  189. margin-bottom: 10px;
  190. gap: 10px;
  191. display: flex;
  192. }
  193. .model-header {
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. margin-bottom: 10px;
  198. p {
  199. font-size: 14px;
  200. color: #fff;
  201. }
  202. }
  203. .model-desc {
  204. color: rgba(255, 255, 255, 0.6);
  205. line-height: 18px;
  206. font-size: 12px;
  207. }
  208. .model-action {
  209. display: flex;
  210. align-items: center;
  211. > * {
  212. margin-left: 20px;
  213. }
  214. }
  215. </style>
  216. <style lang="scss">
  217. .merge-layout {
  218. position: relative;
  219. overflow: initial !important;
  220. top: calc(var(--editor-head-height) + var(--header-top) + 70px) !important;
  221. .ui-input .text.suffix input {
  222. padding-left: 5px;
  223. padding-right: 15px;
  224. }
  225. .ui-input .text.suffix .retouch {
  226. right: 5px;
  227. }
  228. }
  229. .set-prop {
  230. cursor: pointer;
  231. }
  232. .scale-input input {
  233. text-align: right;
  234. padding-right: 20px !important;
  235. }
  236. </style>