mirror of
https://gitee.com/dromara/go-view.git
synced 2024-12-04 20:59:26 +08:00
fix: 修改预览页面动态注册方式
This commit is contained in:
parent
790cc7b878
commit
c29ecc8b0b
@ -101,7 +101,6 @@ const props = defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const positonHandle = (key: string) => {
|
const positonHandle = (key: string) => {
|
||||||
console.log(key)
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
// 局左
|
// 局左
|
||||||
case positionList[0]['key']:
|
case positionList[0]['key']:
|
||||||
|
@ -3,7 +3,7 @@ import App from './App.vue'
|
|||||||
import router, { setupRouter } from '@/router'
|
import router, { setupRouter } from '@/router'
|
||||||
import i18n from '@/i18n/index'
|
import i18n from '@/i18n/index'
|
||||||
import { setupStore } from '@/store'
|
import { setupStore } from '@/store'
|
||||||
import { setupNaive, setupDirectives, setupCustomComponents, setupPreviewPackages } from '@/plugins'
|
import { setupNaive, setupDirectives, setupCustomComponents } from '@/plugins'
|
||||||
import { AppProvider } from '@/components/AppProvider/index'
|
import { AppProvider } from '@/components/AppProvider/index'
|
||||||
import { setHtmlTheme } from '@/utils'
|
import { setHtmlTheme } from '@/utils'
|
||||||
import 'animate.css/animate.min.css'
|
import 'animate.css/animate.min.css'
|
||||||
@ -22,9 +22,6 @@ async function appInit() {
|
|||||||
// 注册全局自定义组件
|
// 注册全局自定义组件
|
||||||
setupCustomComponents(app)
|
setupCustomComponents(app)
|
||||||
|
|
||||||
// 预览页面注册()
|
|
||||||
setupPreviewPackages(app)
|
|
||||||
|
|
||||||
// 挂载状态管理
|
// 挂载状态管理
|
||||||
setupStore(app)
|
setupStore(app)
|
||||||
|
|
||||||
|
@ -1,26 +1,6 @@
|
|||||||
import type { App } from 'vue'
|
import type { App } from 'vue'
|
||||||
import { Skeleton } from '@/components/Skeleton'
|
import { Skeleton } from '@/components/Skeleton'
|
||||||
import { LoadingComponent } from '@/components/LoadingComponent'
|
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局注册自定义组件
|
* 全局注册自定义组件
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export { setupNaive } from '@/plugins/naive'
|
export { setupNaive } from '@/plugins/naive'
|
||||||
export { setupDirectives } from '@/plugins/directives'
|
export { setupDirectives } from '@/plugins/directives'
|
||||||
export { setupCustomComponents, setupPreviewPackages } from '@/plugins/customComponents'
|
export { setupCustomComponents } from '@/plugins/customComponents'
|
||||||
export { icon } from '@/plugins/icon'
|
export { icon } from '@/plugins/icon'
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { PropType, toRaw } from 'vue'
|
import { PropType } from 'vue'
|
||||||
import { MacOsControlBtn } from '@/components/MacOsControlBtn/index'
|
import { MacOsControlBtn } from '@/components/MacOsControlBtn/index'
|
||||||
import { componentInstall } from '@/utils'
|
import { componentInstall } from '@/utils'
|
||||||
import { DragKeyEnum } from '@/enums/editPageEnum'
|
import { DragKeyEnum } from '@/enums/editPageEnum'
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
:style="{ ...useComponentAttrStyle(item.attr, index), ...useSizeStyle(item.attr), ...useStyle(item.styles)}"
|
:style="{ ...useComponentAttrStyle(item.attr, index), ...useSizeStyle(item.attr), ...useStyle(item.styles)}"
|
||||||
>
|
>
|
||||||
<component
|
<component
|
||||||
:is="item.key"
|
:is="item.chartConfig.chartKey"
|
||||||
:chartConfig="item"
|
:chartConfig="item"
|
||||||
:themeSetting="themeSetting"
|
:themeSetting="themeSetting"
|
||||||
:themeColor="themeColor"
|
:themeColor="themeColor"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<!-- 缩放层 -->
|
<!-- 缩放层 -->
|
||||||
<div ref="previewRef">
|
<div ref="previewRef">
|
||||||
<!-- 展示层 -->
|
<!-- 展示层 -->
|
||||||
<div :style="previewRefStyle">
|
<div :style="previewRefStyle" v-if="show">
|
||||||
<!-- 渲染层 -->
|
<!-- 渲染层 -->
|
||||||
<RenderList :localStorageInfo="localStorageInfo" />
|
<RenderList :localStorageInfo="localStorageInfo" />
|
||||||
</div>
|
</div>
|
||||||
@ -18,6 +18,8 @@ import { RenderList } from './components/RenderList/index'
|
|||||||
import { ChartEditStorageType } from './index.d'
|
import { ChartEditStorageType } from './index.d'
|
||||||
import { getLocalStorageInfo } from './utils/index'
|
import { getLocalStorageInfo } from './utils/index'
|
||||||
import { useEditCanvasConfigStyle } from './utils'
|
import { useEditCanvasConfigStyle } from './utils'
|
||||||
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
|
import { fetchChartComponent } from '@/packages/index'
|
||||||
|
|
||||||
const previewRef = ref()
|
const previewRef = ref()
|
||||||
|
|
||||||
@ -25,15 +27,29 @@ const localStorageInfo: ChartEditStorageType = getLocalStorageInfo() as ChartEdi
|
|||||||
|
|
||||||
const width = ref(localStorageInfo?.editCanvasConfig.width)
|
const width = ref(localStorageInfo?.editCanvasConfig.width)
|
||||||
const height = ref(localStorageInfo?.editCanvasConfig.height)
|
const height = ref(localStorageInfo?.editCanvasConfig.height)
|
||||||
|
const show = ref(false)
|
||||||
|
|
||||||
const previewRefStyle: any = computed(() => {
|
const previewRefStyle: any = computed(() => {
|
||||||
return useEditCanvasConfigStyle(localStorageInfo.editCanvasConfig)
|
return useEditCanvasConfigStyle(localStorageInfo.editCanvasConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!localStorageInfo) {
|
// 注册组件(一开始无法获取window['$vue'])
|
||||||
window['$message'].warning('获取数据失败')
|
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(() => {
|
nextTick(() => {
|
||||||
const { calcRate, windowResize, unWindowResize } = usePreviewScale(
|
const { calcRate, windowResize, unWindowResize } = usePreviewScale(
|
||||||
width.value as number,
|
width.value as number,
|
||||||
|
Loading…
Reference in New Issue
Block a user