index.vue 2.1 KB

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