index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <ui-editor-toolbar toolbar v-if="sceneModel">
  3. <span>长度:</span>
  4. <ui-input
  5. type="number"
  6. width="120px"
  7. class="leng-input"
  8. :ctrl="false"
  9. :max="10000000"
  10. v-model="length"
  11. >
  12. <template #icon>m</template>
  13. </ui-input>
  14. <ui-button type="submit" width="160px" @click="resetMeasure">重新选点</ui-button>
  15. </ui-editor-toolbar>
  16. </template>
  17. <script lang="ts" setup>
  18. import { Message } from "bill/index";
  19. import { useViewStack } from "@/hook";
  20. import { router, RoutesName } from "@/router";
  21. import { ref, computed, watch, watchEffect } from "vue";
  22. import { getSceneModel } from "@/sdk";
  23. import { autoSaveFuseModels, FuseModel, getFuseModel, leave } from "@/store";
  24. import {
  25. currentModelStack,
  26. showLeftCtrlPanoStack,
  27. showLeftPanoStack,
  28. showSearchStack,
  29. } from "@/env";
  30. import type { ScaleSet } from "@/sdk";
  31. import { round } from "@/utils";
  32. import { mergeFuns } from "@/components/drawing/hook";
  33. const isCurrent = computed(
  34. () => router.currentRoute.value.name === RoutesName.proportion
  35. );
  36. const model = computed(() => {
  37. if (isCurrent.value) {
  38. const modelId = router.currentRoute.value.params.id as string;
  39. if (modelId) {
  40. return getFuseModel(modelId);
  41. }
  42. }
  43. });
  44. const sceneModel = computed(() => model.value && getSceneModel(model.value));
  45. let scaleSet: ScaleSet | null = null;
  46. const length = ref<number | null>(null);
  47. watch(length, () => {
  48. const len = length.value;
  49. if (len !== null) {
  50. scaleSet?.setLength(len);
  51. length.value = round(len, 2);
  52. }
  53. });
  54. const resetMeasure = () => {
  55. scaleSet?.startMeasure();
  56. };
  57. watchEffect((onCleanup) => {
  58. const smodel = sceneModel.value;
  59. if (smodel) {
  60. scaleSet = smodel.enterScaleSet();
  61. scaleSet.startMeasure();
  62. const pop = currentModelStack.push(model as any);
  63. onCleanup(() => {
  64. smodel.leaveScaleSet();
  65. scaleSet = null;
  66. pop();
  67. });
  68. } else if (isCurrent.value) {
  69. leave();
  70. }
  71. });
  72. useViewStack(() => {
  73. const hide = Message.show({ msg: "请选择两点标记一段已知长度,并输入真实长度" });
  74. const cleanups = mergeFuns([
  75. showLeftPanoStack.push(ref(false)),
  76. showLeftCtrlPanoStack.push(ref(false)),
  77. showSearchStack.push(ref(false)),
  78. ]);
  79. return () => {
  80. hide();
  81. cleanups();
  82. length.value = null;
  83. };
  84. });
  85. useViewStack(autoSaveFuseModels);
  86. </script>
  87. <style lang="scss" scoped>
  88. .leng-input {
  89. margin: 0 20px 0 10px;
  90. }
  91. </style>