fix: 修改预览页面动态注册方式

This commit is contained in:
MTrun 2022-03-10 14:34:26 +08:00
parent 790cc7b878
commit c29ecc8b0b
7 changed files with 24 additions and 32 deletions

View File

@ -101,7 +101,6 @@ const props = defineProps({
})
const positonHandle = (key: string) => {
console.log(key)
switch (key) {
//
case positionList[0]['key']:

View File

@ -3,7 +3,7 @@ import App from './App.vue'
import router, { setupRouter } from '@/router'
import i18n from '@/i18n/index'
import { setupStore } from '@/store'
import { setupNaive, setupDirectives, setupCustomComponents, setupPreviewPackages } from '@/plugins'
import { setupNaive, setupDirectives, setupCustomComponents } from '@/plugins'
import { AppProvider } from '@/components/AppProvider/index'
import { setHtmlTheme } from '@/utils'
import 'animate.css/animate.min.css'
@ -22,9 +22,6 @@ async function appInit() {
// 注册全局自定义组件
setupCustomComponents(app)
// 预览页面注册()
setupPreviewPackages(app)
// 挂载状态管理
setupStore(app)

View File

@ -1,26 +1,6 @@
import type { App } from 'vue'
import { Skeleton } from '@/components/Skeleton'
import { LoadingComponent } from '@/components/LoadingComponent'
import { getLocalStorageInfo } from '@/views/preview/utils/index'
import { fetchChartComponent } from '@/packages/index'
import { CreateComponentType } from '@/packages/index.d'
/**
* * package
* @param app
*/
export const setupPreviewPackages = (app: App) => {
if (document.location.hash.includes('preview')) {
const localStorageInfo = getLocalStorageInfo()
if (!localStorageInfo) return
localStorageInfo.componentList.forEach(async (e: CreateComponentType) => {
if (!app.component(e.key)) {
const chart = fetchChartComponent(e.chartConfig)
app.component(e.key, chart)
}
})
}
}
/**
*

View File

@ -1,4 +1,4 @@
export { setupNaive } from '@/plugins/naive'
export { setupDirectives } from '@/plugins/directives'
export { setupCustomComponents, setupPreviewPackages } from '@/plugins/customComponents'
export { setupCustomComponents } from '@/plugins/customComponents'
export { icon } from '@/plugins/icon'

View File

@ -20,7 +20,7 @@
</template>
<script setup lang="ts">
import { PropType, toRaw } from 'vue'
import { PropType } from 'vue'
import { MacOsControlBtn } from '@/components/MacOsControlBtn/index'
import { componentInstall } from '@/utils'
import { DragKeyEnum } from '@/enums/editPageEnum'

View File

@ -7,7 +7,7 @@
:style="{ ...useComponentAttrStyle(item.attr, index), ...useSizeStyle(item.attr), ...useStyle(item.styles)}"
>
<component
:is="item.key"
:is="item.chartConfig.chartKey"
:chartConfig="item"
:themeSetting="themeSetting"
:themeColor="themeColor"

View File

@ -3,7 +3,7 @@
<!-- 缩放层 -->
<div ref="previewRef">
<!-- 展示层 -->
<div :style="previewRefStyle">
<div :style="previewRefStyle" v-if="show">
<!-- 渲染层 -->
<RenderList :localStorageInfo="localStorageInfo" />
</div>
@ -18,6 +18,8 @@ import { RenderList } from './components/RenderList/index'
import { ChartEditStorageType } from './index.d'
import { getLocalStorageInfo } from './utils/index'
import { useEditCanvasConfigStyle } from './utils'
import { CreateComponentType } from '@/packages/index.d'
import { fetchChartComponent } from '@/packages/index'
const previewRef = ref()
@ -25,15 +27,29 @@ const localStorageInfo: ChartEditStorageType = getLocalStorageInfo() as ChartEdi
const width = ref(localStorageInfo?.editCanvasConfig.width)
const height = ref(localStorageInfo?.editCanvasConfig.height)
const show = ref(false)
const previewRefStyle: any = computed(() => {
return useEditCanvasConfigStyle(localStorageInfo.editCanvasConfig)
})
if (!localStorageInfo) {
window['$message'].warning('获取数据失败')
}
// (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)
//
nextTick(() => {
const { calcRate, windowResize, unWindowResize } = usePreviewScale(
width.value as number,