mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 16:22:57 +08:00
feat:新增预览页面位置图表位置渲染功能
This commit is contained in:
parent
4405ebd30d
commit
75232ee902
@ -29,21 +29,14 @@ export const usePreviewScale = (
|
|||||||
if (scaleDom) {
|
if (scaleDom) {
|
||||||
if (currentRate > baseProportion) {
|
if (currentRate > baseProportion) {
|
||||||
// 表示更宽
|
// 表示更宽
|
||||||
scale.width = (
|
scale.width = ((window.innerHeight * baseProportion) / baseWidth).toFixed(5)
|
||||||
(window.innerHeight * baseProportion) /
|
|
||||||
baseWidth
|
|
||||||
).toFixed(5)
|
|
||||||
scale.height = (window.innerHeight / baseHeight).toFixed(5)
|
scale.height = (window.innerHeight / baseHeight).toFixed(5)
|
||||||
scaleDom.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
|
scaleDom.style.transform = `scale(${scale.width}, ${scale.height})`
|
||||||
} else {
|
} else {
|
||||||
// 表示更高
|
// 表示更高
|
||||||
scale.height = (
|
scale.height = (window.innerWidth / baseProportion / baseHeight).toFixed(5)
|
||||||
window.innerWidth /
|
|
||||||
baseProportion /
|
|
||||||
baseHeight
|
|
||||||
).toFixed(5)
|
|
||||||
scale.width = (window.innerWidth / baseWidth).toFixed(5)
|
scale.width = (window.innerWidth / baseWidth).toFixed(5)
|
||||||
scaleDom.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
|
scaleDom.style.transform = `scale(${scale.width}, ${scale.height})`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.7;
|
opacity: 0.3;
|
||||||
&.visible {
|
&.visible {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,6 @@ import { handleDrag, handleDragOver, useMouseHandle } from './hooks/useDrag.hook
|
|||||||
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
|
import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
|
||||||
import { CreateComponentType } from '@/packages/index.d'
|
|
||||||
import { chartColors } from '@/settings/chartThemes/index'
|
import { chartColors } from '@/settings/chartThemes/index'
|
||||||
|
|
||||||
const chartEditStore = useChartEditStore()
|
const chartEditStore = useChartEditStore()
|
||||||
|
3
src/views/preview/components/RenderList/index.ts
Normal file
3
src/views/preview/components/RenderList/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import RenderList from './index.vue'
|
||||||
|
|
||||||
|
export { RenderList }
|
48
src/views/preview/components/RenderList/index.vue
Normal file
48
src/views/preview/components/RenderList/index.vue
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="chart-item"
|
||||||
|
v-for="(item, index) in localStorageInfo.componentList"
|
||||||
|
:key="item.id"
|
||||||
|
:style="{ ...useComponentStyle(item.attr, index), ...useSizeStyle(item.attr) }"
|
||||||
|
>
|
||||||
|
<component
|
||||||
|
:is="item.key"
|
||||||
|
:chartConfig="item"
|
||||||
|
:themeSetting="themeSetting"
|
||||||
|
:themeColor="themeColor"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { PropType, computed } from 'vue'
|
||||||
|
import { ChartEditStorageType } from '../../index.d'
|
||||||
|
import { chartColors } from '@/settings/chartThemes/index'
|
||||||
|
import { useSizeStyle, useComponentStyle } from '../../hooks/useStyle.hook'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
localStorageInfo: {
|
||||||
|
type: Object as PropType<ChartEditStorageType>,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 主题色
|
||||||
|
const themeSetting = computed(() => {
|
||||||
|
const chartThemeSetting = props.localStorageInfo.editCanvasConfig.chartThemeSetting
|
||||||
|
return chartThemeSetting
|
||||||
|
})
|
||||||
|
|
||||||
|
// 配置项
|
||||||
|
const themeColor = computed(() => {
|
||||||
|
const chartThemeColor = props.localStorageInfo.editCanvasConfig.chartThemeColor
|
||||||
|
return chartColors[chartThemeColor]
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.chart-item {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
</style>
|
21
src/views/preview/hooks/useStyle.hook.ts
Normal file
21
src/views/preview/hooks/useStyle.hook.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { PickCreateComponentType } from '@/packages/index.d'
|
||||||
|
|
||||||
|
type AttrType = PickCreateComponentType<'attr'>
|
||||||
|
|
||||||
|
export const useComponentStyle = (attr: AttrType, index: number) => {
|
||||||
|
const componentStyle = {
|
||||||
|
zIndex: index + 1,
|
||||||
|
left: `${attr.x}px`,
|
||||||
|
top: `${attr.y}px`
|
||||||
|
}
|
||||||
|
return componentStyle
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSizeStyle = (attr: AttrType, scale?: number) => {
|
||||||
|
const sizeStyle = {
|
||||||
|
width: `${scale ? scale * attr.w : attr.w}px`,
|
||||||
|
height: `${scale ? scale * attr.h : attr.h}px`,
|
||||||
|
border: '1px solid red'
|
||||||
|
}
|
||||||
|
return sizeStyle
|
||||||
|
}
|
5
src/views/preview/index.d.ts
vendored
Normal file
5
src/views/preview/index.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
|
|
||||||
|
export interface ChartEditStorageType extends ChartEditStorage {
|
||||||
|
id: string
|
||||||
|
}
|
@ -1,21 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="go-preview">
|
<div class="go-preview">
|
||||||
|
<!-- 缩放层 -->
|
||||||
<div ref="previewRef">
|
<div ref="previewRef">
|
||||||
<h1>预览</h1>
|
<!-- 展示层 -->
|
||||||
|
<div :style="previewRefStyle">
|
||||||
|
<!-- 渲染层 -->
|
||||||
|
<RenderList :localStorageInfo="localStorageInfo" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onUnmounted, ref, nextTick } 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 { getLocalStorage, fetchRouteParams } from '@/utils'
|
||||||
import { StorageEnum } from '@/enums/storageEnum'
|
import { StorageEnum } from '@/enums/storageEnum'
|
||||||
import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
|
import { RenderList } from './components/RenderList/index'
|
||||||
|
import { ChartEditStorageType } from './index.d'
|
||||||
interface ChartEditStorageType extends ChartEditStorage {
|
import { useSizeStyle } from './hooks/useStyle.hook'
|
||||||
id: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const previewRef = ref()
|
const previewRef = ref()
|
||||||
|
|
||||||
@ -35,16 +38,26 @@ const getLocalStorageInfo: () => ChartEditStorageType | undefined = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const localStorageInfo: ChartEditStorageType | undefined = getLocalStorageInfo()
|
const localStorageInfo: ChartEditStorageType = getLocalStorageInfo() as ChartEditStorageType
|
||||||
const width = localStorageInfo?.editCanvasConfig.width
|
|
||||||
const height = localStorageInfo?.editCanvasConfig.height
|
const width = ref(localStorageInfo?.editCanvasConfig.width)
|
||||||
|
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%',
|
||||||
|
border: '1px solid red'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if (!localStorageInfo) {
|
if (!localStorageInfo) {
|
||||||
window['$message'].warning('获取数据失败')
|
window['$message'].warning('获取数据失败')
|
||||||
}
|
}
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
const { calcRate, windowResize, unWindowResize } = usePreviewScale(width as number, height as number, previewRef.value)
|
const { calcRate, windowResize, unWindowResize } = usePreviewScale(width.value as number, height.value as number, previewRef.value)
|
||||||
|
|
||||||
calcRate()
|
calcRate()
|
||||||
windowResize()
|
windowResize()
|
||||||
@ -58,6 +71,7 @@ nextTick(() => {
|
|||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@include go("preview") {
|
@include go("preview") {
|
||||||
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
Loading…
Reference in New Issue
Block a user