feat: 新增组件预览

This commit is contained in:
MTrun 2022-03-07 12:33:05 +08:00
parent 8aa4490ea9
commit e6a99302d6
32 changed files with 102 additions and 93 deletions

View File

@ -30,7 +30,7 @@ import { SettingItemBox } from '@/components/ChartItemSetting/index'
const props = defineProps({ const props = defineProps({
chartAttr: { chartAttr: {
type: Object as PropType<Omit<PickCreateComponentType<'attr'>, 'node'>>, type: Object as PropType<Omit<PickCreateComponentType<'attr'>, 'node' | 'conNode'>>,
required: true required: true
} }
}) })

View File

@ -30,7 +30,7 @@ import { SettingItemBox } from '@/components/ChartItemSetting/index'
const props = defineProps({ const props = defineProps({
chartAttr: { chartAttr: {
type: Object as PropType<Omit<PickCreateComponentType<'attr'>, 'node'>>, type: Object as PropType<Omit<PickCreateComponentType<'attr'>, 'node' | 'conNode'>>,
required: true required: true
} }
}) })

View File

@ -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 } from '@/plugins' import { setupNaive, setupDirectives, setupCustomComponents, setupPreviewPackages } from '@/plugins'
import { AppProvider } from '@/components/AppProvider/index' import { AppProvider } from '@/components/AppProvider/index'
import { setHtmlTheme } from '@/utils' import { setHtmlTheme } from '@/utils'
@ -24,6 +24,9 @@ async function appInit() {
// 注册全局自定义组件 // 注册全局自定义组件
setupCustomComponents(app) setupCustomComponents(app)
// 预览页面注册()
setupPreviewPackages(app)
// 挂载状态管理 // 挂载状态管理
setupStore(app) setupStore(app)

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const BarCommonConfig: ConfigType = { export const BarCommonConfig: ConfigType = {
key: 'VBarCommon', key: 'VBarCommon',
conKey: 'VCBarCommon',
title: '柱状图', title: '柱状图',
category: ChatCategoryEnum.BAR, category: ChatCategoryEnum.BAR,
categoryName: ChatCategoryEnumName.BAR, categoryName: ChatCategoryEnumName.BAR,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: BarCommon, node: () => BarCommon,
conNode: () => Configuration, conNode: () => Configuration,
image: image, image: image,
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const BarCrossrangefig: ConfigType = { export const BarCrossrangefig: ConfigType = {
key: 'VBarCrossrange', key: 'VBarCrossrange',
conKey: 'VCBarCrossrange',
title: '横向柱状图', title: '横向柱状图',
category: ChatCategoryEnum.BAR, category: ChatCategoryEnum.BAR,
categoryName: ChatCategoryEnumName.BAR, categoryName: ChatCategoryEnumName.BAR,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: BarCrossrange, node: () => BarCrossrange,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const LineCommonConfig: ConfigType = { export const LineCommonConfig: ConfigType = {
key: 'VLineCommon', key: 'VLineCommon',
conKey: 'VCLineCommon',
title: '折线图', title: '折线图',
category: ChatCategoryEnum.LINE, category: ChatCategoryEnum.LINE,
categoryName: ChatCategoryEnumName.LINE, categoryName: ChatCategoryEnumName.LINE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: LineCommon, node: () => LineCommon,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const LineGradientSingleConfig: ConfigType = { export const LineGradientSingleConfig: ConfigType = {
key: 'VLineGradientSingle', key: 'VLineGradientSingle',
conKey: 'VCLineGradientSingle',
title: '折线面积图', title: '折线面积图',
category: ChatCategoryEnum.LINE, category: ChatCategoryEnum.LINE,
categoryName: ChatCategoryEnumName.LINE, categoryName: ChatCategoryEnumName.LINE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: LineGradientSingle, node: () => LineGradientSingle,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const LineGradientsConfig: ConfigType = { export const LineGradientsConfig: ConfigType = {
key: 'VLineGradients', key: 'VLineGradients',
conKey: 'VCLineGradients',
title: '折线面积图', title: '折线面积图',
category: ChatCategoryEnum.LINE, category: ChatCategoryEnum.LINE,
categoryName: ChatCategoryEnumName.LINE, categoryName: ChatCategoryEnumName.LINE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: LineGradients, node: () => LineGradients,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const MapChineConfig: ConfigType = { export const MapChineConfig: ConfigType = {
key: 'VMapChine', key: 'VMapChine',
conKey: 'VCMapChine',
title: '北京地图', title: '北京地图',
category: ChatCategoryEnum.MAP, category: ChatCategoryEnum.MAP,
categoryName: ChatCategoryEnumName.MAP, categoryName: ChatCategoryEnumName.MAP,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: MapChine, node: () => MapChine,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const FunnelConfig: ConfigType = { export const FunnelConfig: ConfigType = {
key: 'VFunnel', key: 'VFunnel',
conKey: 'VCFunnel',
title: '漏斗图', title: '漏斗图',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: Funnel, node: () => Funnel,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const HeatmapConfig: ConfigType = { export const HeatmapConfig: ConfigType = {
key: 'VHeatmap', key: 'VHeatmap',
conKey: 'VCHeatmap',
title: '热力图', title: '热力图',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: Heatmap, node: () => Heatmap,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const PointConfig: ConfigType = { export const PointConfig: ConfigType = {
key: 'VPoint', key: 'VPoint',
conKey: 'VCPoint',
title: '热力图', title: '热力图',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: Point, node: () => Point,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const RadarConfig: ConfigType = { export const RadarConfig: ConfigType = {
key: 'VRadar', key: 'VRadar',
conKey: 'VCRadar',
title: '雷达', title: '雷达',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: Radar, node: () => Radar,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const TreeMapConfig: ConfigType = { export const TreeMapConfig: ConfigType = {
key: 'VTreeMap', key: 'VTreeMap',
conKey: 'VCTreeMap',
title: '树形分布', title: '树形分布',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: TreeMap, node: () => TreeMap,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const VariableConfig: ConfigType = { export const VariableConfig: ConfigType = {
key: 'VVariable', key: 'VVariable',
conKey: 'VCVariable',
title: '折线面积图', title: '折线面积图',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: Variable, node: () => Variable,
conNode: () => Configuration, conNode: () => Configuration,
image: image image: image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const PieCommonConfig: ConfigType = { export const PieCommonConfig: ConfigType = {
key: 'VPieCommon', key: 'VPieCommon',
conKey: 'VCPieCommon',
title: '饼图', title: '饼图',
category: ChatCategoryEnum.PIE, category: ChatCategoryEnum.PIE,
categoryName: ChatCategoryEnumName.PIE, categoryName: ChatCategoryEnumName.PIE,
package: PackagesCategoryEnum.CHARTS, package: PackagesCategoryEnum.CHARTS,
node: PieCommon, node: () => PieCommon,
conNode: () => Configuration, conNode: () => Configuration,
image image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum,ChatCategoryEnumName } from '../../index.d'
export const BorderCommonConfig: ConfigType = { export const BorderCommonConfig: ConfigType = {
key: 'VBorderCommon', key: 'VBorderCommon',
conKey: 'VCBorderCommon',
title: '边框', title: '边框',
category: ChatCategoryEnum.BORDER, category: ChatCategoryEnum.BORDER,
categoryName: ChatCategoryEnumName.BORDER, categoryName: ChatCategoryEnumName.BORDER,
package: PackagesCategoryEnum.DECORATES, package: PackagesCategoryEnum.DECORATES,
node: BorderCommon, node: () => BorderCommon,
conNode: () => Configuration, conNode: () => Configuration,
image image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum,ChatCategoryEnumName } from '../../index.d'
export const NumberConfig: ConfigType = { export const NumberConfig: ConfigType = {
key: 'VNumber', key: 'VNumber',
conKey: 'VCNumber',
title: '数字翻牌', title: '数字翻牌',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.DECORATES, package: PackagesCategoryEnum.DECORATES,
node: Number, node: () => Number,
conNode: () => Configuration, conNode: () => Configuration,
image image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum,ChatCategoryEnumName } from '../../index.d'
export const TimeConfig: ConfigType = { export const TimeConfig: ConfigType = {
key: 'VTime', key: 'VTime',
conKey: 'VCTime',
title: '时间', title: '时间',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.DECORATES, package: PackagesCategoryEnum.DECORATES,
node: Time, node: () => Time,
conNode: () => Configuration, conNode: () => Configuration,
image image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum,ChatCategoryEnumName } from '../../index.d'
export const WeatherConfig: ConfigType = { export const WeatherConfig: ConfigType = {
key: 'VWeather', key: 'VWeather',
conKey: 'VCWeather',
title: '天气', title: '天气',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.DECORATES, package: PackagesCategoryEnum.DECORATES,
node: Weather, node: () => Weather,
conNode: () => Configuration, conNode: () => Configuration,
image image
} }

View File

@ -6,11 +6,12 @@ import { ChatCategoryEnum,ChatCategoryEnumName } from '../../index.d'
export const WeatherTimeConfig: ConfigType = { export const WeatherTimeConfig: ConfigType = {
key: 'VWeatherTime', key: 'VWeatherTime',
conKey: 'VCWeatherTime',
title: '天气和时间', title: '天气和时间',
category: ChatCategoryEnum.MORE, category: ChatCategoryEnum.MORE,
categoryName: ChatCategoryEnumName.MORE, categoryName: ChatCategoryEnumName.MORE,
package: PackagesCategoryEnum.DECORATES, package: PackagesCategoryEnum.DECORATES,
node: WeatherTime, node: () => WeatherTime,
conNode: () => Configuration, conNode: () => Configuration,
image image
} }

View File

@ -4,11 +4,12 @@ import { GlobalThemeJsonType } from '@/settings/chartThemes/index'
// 组件配置 // 组件配置
export type ConfigType = { export type ConfigType = {
key: string key: string
conKey: string,
title: string title: string
category: string category: string
categoryName: string categoryName: string
package: string package: string
node: Component node: () => Component
conNode: () => Component conNode: () => Component
image: string | (() => Promise<typeof import('*.png')>) image: string | (() => Promise<typeof import('*.png')>)
} }
@ -22,7 +23,7 @@ export interface PublicConfigType {
} }
export interface CreateComponentType extends PublicConfigType { export interface CreateComponentType extends PublicConfigType {
key: string key: string
chartConfig: Omit<ConfigType, 'node'> chartConfig: Omit<ConfigType, 'node' | 'conNode'>
option: GlobalThemeJsonType option: GlobalThemeJsonType
} }

View File

@ -10,18 +10,25 @@ import { InformationList } from '@/packages/components/Informations/index'
import { TableList } from '@/packages/components/Tables/index' import { TableList } from '@/packages/components/Tables/index'
// * 所有图表 // * 所有图表
let packagesList: PackagesType = { export let packagesList: PackagesType = {
[PackagesCategoryEnum.CHARTS]: ChartList, [PackagesCategoryEnum.CHARTS]: ChartList,
[PackagesCategoryEnum.INFORMATION]: InformationList, [PackagesCategoryEnum.INFORMATION]: InformationList,
[PackagesCategoryEnum.TABLES]: TableList, [PackagesCategoryEnum.TABLES]: TableList,
[PackagesCategoryEnum.DECORATES]: DecorateList [PackagesCategoryEnum.DECORATES]: DecorateList
} }
export const packgeInstall = (app:App) => {
ChartList.forEach(e=>{
console.log(e)
app.component(e.key, e.node)
})
}
/** /**
* * * *
* @param dropData * @param dropData
*/ */
const createComponent = async (dropData: ConfigType) => { export const createComponent = async (dropData: ConfigType) => {
const { category } = dropData const { category } = dropData
const key = dropData.key.substring(1) const key = dropData.key.substring(1)
const chart = await import(`./components/${dropData.package}/${category}/${key}/config.ts`) const chart = await import(`./components/${dropData.package}/${category}/${key}/config.ts`)
@ -30,11 +37,9 @@ const createComponent = async (dropData: ConfigType) => {
/** /**
* * * *
* * import.meta.globEager 使
*/ */
const fetchChartComponent = async (dropData: ConfigType | Omit<ConfigType, "node">) => { export const fetchChartComponent = (dropData: ConfigType | Omit<ConfigType, "node" | 'conNode'>) => {
const key = dropData.key.substring(1) const { key, package:packageName } = dropData
const { category } = dropData return packagesList[packageName as PackagesCategoryEnum].filter(e=> e.key === key)[0].node()
return await import(`../packages/components/${dropData.package}/${category}/${key}/index.vue`) }
}
export { packagesList, createComponent, fetchChartComponent }

View File

@ -1,6 +1,24 @@
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) => {
const localStorageInfo = getLocalStorageInfo()
if(!document.location.hash.includes('preview') || !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 { setupNaive } from '@/plugins/naive'
export { setupDirectives } from '@/plugins/directives' export { setupDirectives } from '@/plugins/directives'
export { setupCustomComponents } from '@/plugins/customComponents' export { setupCustomComponents, setupPreviewPackages } from '@/plugins/customComponents'
export { icon } from '@/plugins/icon' export { icon } from '@/plugins/icon'

View File

@ -1,19 +1,6 @@
import { defineAsyncComponent, AsyncComponentLoader } from 'vue' import { defineAsyncComponent, AsyncComponentLoader } from 'vue'
import { AsyncLoading, AsyncSkeletonLoading } from '@/components/LoadingComponent' import { AsyncLoading, AsyncSkeletonLoading } from '@/components/LoadingComponent'
import { ConfigType } from '@/packages/index.d'
import { fetchChartComponent } from '@/packages/index'
/**
* * package
* @param {ConfigType} dropData
*/
export const componentPackageInstall = async (dropData: Omit<ConfigType, "node">) => {
const key = dropData.key.substring(1)
console.log(window['$vue']);
if (!window['$vue'].component(key)) {
const chart = await fetchChartComponent(dropData)
window['$vue'].component(key, chart)
}
}
/** /**
* * * *
*/ */

View File

@ -20,7 +20,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { PropType } from 'vue' import { PropType, toRaw } 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'
@ -37,9 +37,10 @@ defineProps({
// //
const handleDragStart = (e: DragEvent, item: ConfigType) => { const handleDragStart = (e: DragEvent, item: ConfigType) => {
// //
componentInstall(item.key, item.node) componentInstall(item.key, item.node())
componentInstall(item.conKey, item.conNode())
// //
e!.dataTransfer!.setData(DragKeyEnum.DROG_KEY, JSON.stringify(omit(item, ['node', 'image']))) e!.dataTransfer!.setData(DragKeyEnum.DROG_KEY, JSON.stringify(omit(item, ['node', 'conNode', 'image'])))
} }
</script> </script>

View File

@ -16,7 +16,7 @@
<!-- 位置 --> <!-- 位置 -->
<PositionSetting :chartAttr="targetData.attr" /> <PositionSetting :chartAttr="targetData.attr" />
<!-- 自定义配置项 --> <!-- 自定义配置项 -->
<component :is="targetData.chartConfig.conNode()" :optionData="targetData.option"></component> <component :is="targetData.chartConfig.conKey" :optionData="targetData.option"></component>
<!-- 全局设置 --> <!-- 全局设置 -->
<GlobalSetting :optionData="targetData.option" :in-chart="true" /> <GlobalSetting :optionData="targetData.option" :in-chart="true" />
</div> </div>
@ -24,15 +24,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, Ref } from 'vue' import { computed, Ref } from 'vue'
import { loadAsyncComponent } from '@/utils'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { GlobalSetting, PositionSetting, SizeSetting } from '@/components/ChartItemSetting/index' import { GlobalSetting, PositionSetting, SizeSetting } from '@/components/ChartItemSetting/index'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { SettingItemBox } from '@/components/ChartItemSetting/index' import { SettingItemBox } from '@/components/ChartItemSetting/index'
const GlobalSettingCom = loadAsyncComponent(() =>
import('@/components/ChartItemSetting/index')
)
const chartEditStore = useChartEditStore() const chartEditStore = useChartEditStore()
const targetData: Ref<CreateComponentType> = computed(() => { const targetData: Ref<CreateComponentType> = computed(() => {

View File

@ -312,7 +312,7 @@ watch(
border-width: 1px; border-width: 1px;
border-style: solid; border-style: solid;
border-color: v-bind('themeColor'); border-color: v-bind('themeColor');
opacity: 0.3; opacity: 0.7;
&.visible { &.visible {
display: block; display: block;
} }

View File

@ -19,8 +19,6 @@ import { PropType, computed } from 'vue'
import { ChartEditStorageType } from '../../index.d' import { ChartEditStorageType } from '../../index.d'
import { chartColors } from '@/settings/chartThemes/index' import { chartColors } from '@/settings/chartThemes/index'
import { useSizeStyle, useComponentStyle } from '../../hooks/useStyle.hook' import { useSizeStyle, useComponentStyle } from '../../hooks/useStyle.hook'
import { componentPackageInstall } from '@/utils'
import { CreateComponentType } from '@/packages/index.d'
const props = defineProps({ const props = defineProps({
localStorageInfo: { localStorageInfo: {
@ -29,10 +27,6 @@ const props = defineProps({
} }
}) })
//
props.localStorageInfo.componentList.forEach((e: CreateComponentType) => {
componentPackageInstall(e.chartConfig)
});
// //
const themeSetting = computed(() => { const themeSetting = computed(() => {

View File

@ -14,29 +14,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { onUnmounted, ref, nextTick, computed } from 'vue' import { onUnmounted, ref, nextTick, computed } from 'vue'
import { usePreviewScale } from '@/hooks/index' import { usePreviewScale } from '@/hooks/index'
import { getLocalStorage, fetchRouteParams } from '@/utils'
import { StorageEnum } from '@/enums/storageEnum'
import { RenderList } from './components/RenderList/index' import { RenderList } from './components/RenderList/index'
import { ChartEditStorageType } from './index.d' import { ChartEditStorageType } from './index.d'
import { getLocalStorageInfo } from './utils/index'
const previewRef = ref() const previewRef = ref()
const getLocalStorageInfo: () => ChartEditStorageType | undefined = () => {
const routeParamsRes = fetchRouteParams()
if (!routeParamsRes) return
const { id } = routeParamsRes
const storageList: ChartEditStorageType[] = getLocalStorage(
StorageEnum.GO_CHART_STORAGE_LIST
)
for (let i = 0; i < storageList.length; i++) {
if (id.toString() === storageList[i]['id']) {
return storageList[i]
}
}
}
const localStorageInfo: ChartEditStorageType = getLocalStorageInfo() as ChartEditStorageType const localStorageInfo: ChartEditStorageType = getLocalStorageInfo() as ChartEditStorageType
const width = ref(localStorageInfo?.editCanvasConfig.width) const width = ref(localStorageInfo?.editCanvasConfig.width)
@ -45,8 +28,8 @@ const height = ref(localStorageInfo?.editCanvasConfig.height)
const previewRefStyle = computed(() => { const previewRefStyle = computed(() => {
return { return {
position: 'relative', position: 'relative',
width: width.value? `${width.value || 100}px` : '100%', width: width.value ? `${width.value || 100}px` : '100%',
height: height.value? `${height.value}px` : '100%', height: height.value ? `${height.value}px` : '100%',
border: '1px solid red' border: '1px solid red'
} }
}) })
@ -56,7 +39,11 @@ if (!localStorageInfo) {
} }
nextTick(() => { nextTick(() => {
const { calcRate, windowResize, unWindowResize } = usePreviewScale(width.value as number, height.value as number, previewRef.value) const { calcRate, windowResize, unWindowResize } = usePreviewScale(
width.value as number,
height.value as number,
previewRef.value
)
calcRate() calcRate()
windowResize() windowResize()
@ -65,11 +52,10 @@ nextTick(() => {
unWindowResize() unWindowResize()
}) })
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@include go("preview") { @include go('preview') {
position: relative; position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
@ -77,6 +63,6 @@ nextTick(() => {
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
overflow: hidden; overflow: hidden;
@include background-image("background-image"); @include background-image('background-image');
} }
</style> </style>

View File

@ -1,4 +1,4 @@
import { getLocalStorage, fetchRouteParams } from '@/utils' import { getLocalStorage } from '@/utils'
import { StorageEnum } from '@/enums/storageEnum' import { StorageEnum } from '@/enums/storageEnum'
import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d' import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
@ -6,10 +6,10 @@ export interface ChartEditStorageType extends ChartEditStorage {
id: string id: string
} }
export const getLocalStorageInfo: () => ChartEditStorageType | undefined = () => { export const getLocalStorageInfo = () => {
const routeParamsRes = fetchRouteParams() const urlHash = document.location.hash
if (!routeParamsRes) return const toPathArray = urlHash.split('/')
const { id } = routeParamsRes const id = toPathArray && toPathArray[toPathArray.length - 1]
const storageList: ChartEditStorageType[] = getLocalStorage( const storageList: ChartEditStorageType[] = getLocalStorage(
StorageEnum.GO_CHART_STORAGE_LIST StorageEnum.GO_CHART_STORAGE_LIST