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
@@ -20,7 +20,7 @@
</template>
<script setup lang="ts">
import { PropType } from 'vue'
import { PropType, toRaw } from 'vue'
import { MacOsControlBtn } from '@/components/MacOsControlBtn/index'
import { componentInstall } from '@/utils'
import { DragKeyEnum } from '@/enums/editPageEnum'
@@ -37,9 +37,10 @@ defineProps({
// 拖拽处理
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>
@@ -16,7 +16,7 @@
<!-- 位置 -->
<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" />
</div>
@@ -24,15 +24,11 @@
<script setup lang="ts">
import { computed, Ref } from 'vue'
import { loadAsyncComponent } from '@/utils'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { GlobalSetting, PositionSetting, SizeSetting } from '@/components/ChartItemSetting/index'
import { CreateComponentType } from '@/packages/index.d'
import { SettingItemBox } from '@/components/ChartItemSetting/index'
const GlobalSettingCom = loadAsyncComponent(() =>
import('@/components/ChartItemSetting/index')
)
const chartEditStore = useChartEditStore()
const targetData: Ref<CreateComponentType> = computed(() => {
@@ -312,7 +312,7 @@ watch(
border-width: 1px;
border-style: solid;
border-color: v-bind('themeColor');
opacity: 0.3;
opacity: 0.7;
&.visible {
display: block;
}
@@ -19,8 +19,6 @@ import { PropType, computed } from 'vue'
import { ChartEditStorageType } from '../../index.d'
import { chartColors } from '@/settings/chartThemes/index'
import { useSizeStyle, useComponentStyle } from '../../hooks/useStyle.hook'
import { componentPackageInstall } from '@/utils'
import { CreateComponentType } from '@/packages/index.d'
const props = defineProps({
localStorageInfo: {
@@ -29,10 +27,6 @@ const props = defineProps({
}
})
// 动态注册
props.localStorageInfo.componentList.forEach((e: CreateComponentType) => {
componentPackageInstall(e.chartConfig)
});
// 主题色
const themeSetting = computed(() => {
+11 -25
View File
@@ -14,29 +14,12 @@
<script setup lang="ts">
import { onUnmounted, ref, nextTick, computed } from 'vue'
import { usePreviewScale } from '@/hooks/index'
import { getLocalStorage, fetchRouteParams } from '@/utils'
import { StorageEnum } from '@/enums/storageEnum'
import { RenderList } from './components/RenderList/index'
import { ChartEditStorageType } from './index.d'
import { getLocalStorageInfo } from './utils/index'
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 width = ref(localStorageInfo?.editCanvasConfig.width)
@@ -45,8 +28,8 @@ const height = ref(localStorageInfo?.editCanvasConfig.height)
const previewRefStyle = computed(() => {
return {
position: 'relative',
width: width.value? `${width.value || 100}px` : '100%',
height: height.value? `${height.value}px` : '100%',
width: width.value ? `${width.value || 100}px` : '100%',
height: height.value ? `${height.value}px` : '100%',
border: '1px solid red'
}
})
@@ -56,7 +39,11 @@ if (!localStorageInfo) {
}
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()
windowResize()
@@ -65,11 +52,10 @@ nextTick(() => {
unWindowResize()
})
})
</script>
<style lang="scss" scoped>
@include go("preview") {
@include go('preview') {
position: relative;
display: flex;
align-items: center;
@@ -77,6 +63,6 @@ nextTick(() => {
height: 100vh;
width: 100vw;
overflow: hidden;
@include background-image("background-image");
@include background-image('background-image');
}
</style>
</style>
+5 -5
View File
@@ -1,4 +1,4 @@
import { getLocalStorage, fetchRouteParams } from '@/utils'
import { getLocalStorage } from '@/utils'
import { StorageEnum } from '@/enums/storageEnum'
import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
@@ -6,10 +6,10 @@ export interface ChartEditStorageType extends ChartEditStorage {
id: string
}
export const getLocalStorageInfo: () => ChartEditStorageType | undefined = () => {
const routeParamsRes = fetchRouteParams()
if (!routeParamsRes) return
const { id } = routeParamsRes
export const getLocalStorageInfo = () => {
const urlHash = document.location.hash
const toPathArray = urlHash.split('/')
const id = toPathArray && toPathArray[toPathArray.length - 1]
const storageList: ChartEditStorageType[] = getLocalStorage(
StorageEnum.GO_CHART_STORAGE_LIST