index.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <RightFillPano>
  3. <template #header>
  4. <div class="btns header-btns">
  5. <ui-button class="start" @click="getView">
  6. <ui-icon type="add" />
  7. 视图提取
  8. </ui-button>
  9. </div>
  10. </template>
  11. <ui-group title="全部视图" class="tree">
  12. <Draggable :list="views" draggable=".sign" itemKey="id">
  13. <template #item="{ element: view }">
  14. <Sign
  15. :view="view"
  16. :key="view.id"
  17. @delete="() => deleteView(view)"
  18. @updateTitle="(title) => (view.title = title)"
  19. @updateCover="(cover) => (view.cover = cover)"
  20. />
  21. </template>
  22. </Draggable>
  23. </ui-group>
  24. </RightFillPano>
  25. </template>
  26. <script lang="ts" setup>
  27. import {
  28. views,
  29. createView,
  30. autoSaveViews,
  31. // initialViews,
  32. initialTaggingStyles,
  33. initialTaggings,
  34. initialMeasures,
  35. } from "@/store";
  36. import { RightFillPano } from "@/layout";
  37. import { useViewStack } from "@/hook";
  38. import Draggable from "vuedraggable";
  39. import Sign from "./sign.vue";
  40. import { loadModel, currentModel, fuseModel } from "@/model";
  41. import { loadPack, togetherCallback } from "@/utils";
  42. import { Message } from "bill/index";
  43. import { showLeftPanoStack, showRightPanoStack } from "@/env";
  44. import { ref, watch } from "vue";
  45. import type { View } from "@/store";
  46. // initialViews();
  47. initialTaggingStyles(), initialTaggings(), initialMeasures();
  48. const getView = async () => {
  49. try {
  50. const { image, flyData } = await loadPack(async () => {
  51. const modelSDK = await loadModel(currentModel.value);
  52. return await modelSDK.getView();
  53. });
  54. const type =
  55. currentModel.value !== fuseModel
  56. ? { numType: currentModel.value.type, num: currentModel.value.num }
  57. : {};
  58. views.value.push(
  59. createView({
  60. flyData,
  61. cover: {
  62. blob: image,
  63. url: URL.createObjectURL(image),
  64. },
  65. ...type,
  66. })
  67. );
  68. } catch (e: any) {
  69. console.error(e);
  70. Message.error(e.message);
  71. }
  72. };
  73. const deleteView = (record: View) => {
  74. const index = views.value.indexOf(record);
  75. if (~index) {
  76. views.value.splice(index, 1);
  77. }
  78. };
  79. const showLeftPano = ref(true);
  80. watch(currentModel, () => {
  81. if (currentModel.value) {
  82. showLeftPano.value = false;
  83. }
  84. });
  85. useViewStack(autoSaveViews);
  86. useViewStack(() => togetherCallback([showLeftPanoStack.push(showLeftPano)]));
  87. </script>
  88. <style lang="scss" src="./style.scss" scoped></style>