index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <div class="go-preview">
  3. <!-- 缩放层 -->
  4. <div ref="previewRef">
  5. <!-- 展示层 -->
  6. <div :style="previewRefStyle">
  7. <!-- 渲染层 -->
  8. <RenderList :localStorageInfo="localStorageInfo" />
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script setup lang="ts">
  14. import { onUnmounted, ref, nextTick, computed } from 'vue'
  15. import { usePreviewScale } from '@/hooks/index'
  16. import { RenderList } from './components/RenderList/index'
  17. import { ChartEditStorageType } from './index.d'
  18. import { getLocalStorageInfo } from './utils/index'
  19. const previewRef = ref()
  20. const localStorageInfo: ChartEditStorageType = getLocalStorageInfo() as ChartEditStorageType
  21. const width = ref(localStorageInfo?.editCanvasConfig.width)
  22. const height = ref(localStorageInfo?.editCanvasConfig.height)
  23. const previewRefStyle = computed(() => {
  24. return {
  25. position: 'relative',
  26. width: width.value ? `${width.value || 100}px` : '100%',
  27. height: height.value ? `${height.value}px` : '100%',
  28. border: '1px solid red'
  29. }
  30. })
  31. if (!localStorageInfo) {
  32. window['$message'].warning('获取数据失败')
  33. }
  34. nextTick(() => {
  35. const { calcRate, windowResize, unWindowResize } = usePreviewScale(
  36. width.value as number,
  37. height.value as number,
  38. previewRef.value
  39. )
  40. calcRate()
  41. windowResize()
  42. onUnmounted(() => {
  43. unWindowResize()
  44. })
  45. })
  46. </script>
  47. <style lang="scss" scoped>
  48. @include go('preview') {
  49. position: relative;
  50. display: flex;
  51. align-items: center;
  52. justify-content: center;
  53. height: 100vh;
  54. width: 100vw;
  55. overflow: hidden;
  56. @include background-image('background-image');
  57. }
  58. </style>