diff --git a/src/views/preview/components/PreviewRenderList/index.vue b/src/views/preview/components/PreviewRenderList/index.vue index f381f58b..8f1372f8 100644 --- a/src/views/preview/components/PreviewRenderList/index.vue +++ b/src/views/preview/components/PreviewRenderList/index.vue @@ -4,7 +4,7 @@ :class="animationsClass(item.styles.animations)" v-for="(item, index) in localStorageInfo.componentList" :key="item.id" - :style="{ ...useComponentAttrStyle(item.attr, index), ...useSizeStyle(item.attr), ...useStyle(item.styles)}" + :style="{ ...getComponentAttrStyle(item.attr, index), ...getSizeStyle(item.attr), ...getStyle(item.styles)}" > { + const show = ref(false) + + // 注册组件(一开始无法获取window['$vue']) + const intervalTiming = setInterval(() => { + if (window['$vue'].component) { + clearInterval(intervalTiming) + show.value = true + localStorageInfo.componentList.forEach(async (e: CreateComponentType) => { + if (!window['$vue'].component(e.chartConfig.chartKey)) { + window['$vue'].component( + e.chartConfig.chartKey, + fetchChartComponent(e.chartConfig) + ) + } + }) + } + }, 200) + + return { + show + } +} diff --git a/src/views/preview/hooks/useScale.hook.ts b/src/views/preview/hooks/useScale.hook.ts new file mode 100644 index 00000000..bdf4ed3d --- /dev/null +++ b/src/views/preview/hooks/useScale.hook.ts @@ -0,0 +1,31 @@ +import { onUnmounted, ref, nextTick, computed } from 'vue' +import { usePreviewScale } from '@/hooks/index' +import type { ChartEditStorageType } from '..' + +export const useScale = (localStorageInfo: ChartEditStorageType) => { + + const previewRef = ref() + + const width = ref(localStorageInfo?.editCanvasConfig.width) + const height = ref(localStorageInfo?.editCanvasConfig.height) + + // 屏幕适配 + nextTick(() => { + const { calcRate, windowResize, unWindowResize } = usePreviewScale( + width.value as number, + height.value as number, + previewRef.value + ) + + calcRate() + windowResize() + + onUnmounted(() => { + unWindowResize() + }) + }) + + return { + previewRef + } +} diff --git a/src/views/preview/index.vue b/src/views/preview/index.vue index 04043752..c82cfc1c 100644 --- a/src/views/preview/index.vue +++ b/src/views/preview/index.vue @@ -5,64 +5,30 @@
- +