home.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="layout" :class="{ full }">
  3. <Header class="header" v-if="draw" @full="fullHandler" @save="saveHandler" />
  4. <div class="container">
  5. <Slide class="slide" v-if="draw" />
  6. <div class="content" ref="drawEle">
  7. <DrawBoard
  8. id="asd"
  9. v-if="drawEle"
  10. :ref="(e: any) => draw = e.draw"
  11. :data="(data as any)"
  12. />
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script lang="ts" setup>
  18. import Header from "./header/header.vue";
  19. import Slide from "./slide/slide.vue";
  20. import { onUnmounted, ref, watch, watchEffect } from "vue";
  21. import { DrawExpose, DrawBoard } from "@/index";
  22. import { data, save } from "./init.ts";
  23. import { installDraw } from "./use-draw.ts";
  24. import { listener } from "@/utils/event.ts";
  25. import { ElMessage } from "element-plus";
  26. import { startAnimation } from "@/utils/shared.ts";
  27. const drawEle = ref<HTMLDivElement | null>(null);
  28. const draw = ref<DrawExpose>();
  29. installDraw(draw);
  30. const saveHandler = () => {
  31. save(draw.value?.getData());
  32. };
  33. const full = ref(false);
  34. watch(full, (_f1, _f2, onCleanup) => {
  35. onCleanup(
  36. startAnimation(() => {
  37. draw.value?.updateSize();
  38. }, 400)
  39. );
  40. });
  41. const fullHandler = () => {
  42. full.value = true;
  43. ElMessage.warning({ message: "按ESC键可退出全屏模式", duration: 3000 });
  44. };
  45. onUnmounted(
  46. listener(document.documentElement, "keyup", (ev) => {
  47. if (ev.key === "Escape") {
  48. full.value = false;
  49. }
  50. })
  51. );
  52. </script>
  53. <style lang="scss" scoped>
  54. @use '../styles/global';
  55. .layout {
  56. display: flex;
  57. flex-direction: column;
  58. align-items: stretch;
  59. height: 100vh;
  60. background: #f0f2f5;
  61. --top: 0px;
  62. --left: 0px;
  63. overflow: hidden;
  64. .header {
  65. margin-top: var(--top);
  66. transition: margin-top 0.3s ease;
  67. height: global.$headerSize;
  68. flex: 0 0 auto;
  69. }
  70. .container {
  71. flex: 1;
  72. display: flex;
  73. align-items: stretch;
  74. }
  75. .slide {
  76. flex: 0 0 auto;
  77. width: global.$slideSize;
  78. margin-left: var(--left);
  79. overflow-y: auto;
  80. background: #fff;
  81. transition: margin-left 0.3s ease;
  82. }
  83. .content {
  84. flex: 1;
  85. }
  86. &.full {
  87. --top: calc(-1 * #{global.$headerSize});
  88. --left: calc(-1 * #{global.$slideSize});
  89. }
  90. }
  91. </style>