176 lines
5.9 KiB
Vue
Raw Normal View History

2022-01-20 21:25:35 +08:00
<template>
2022-12-16 19:08:34 +08:00
<!-- <edit-rule></edit-rule> -->
<content-box id="go-chart-edit-layout" :flex="true" :showTop="false" :showBottom="true" :depth="1" :xScroll="true" :disabledScroll="true"
@mousedown="mousedownHandleUnStop" @drop="dragHandle" @dragover="dragoverHandle" @dragenter="dragoverHandle">
<ruler>
<!-- 画布主体 -->
<div id="go-chart-edit-content" @contextmenu="handleContextMenu">
<!-- 展示 -->
<edit-range>
<!-- 滤镜预览 -->
<div :style="{
...getFilterStyle(chartEditStore.getEditCanvasConfig),
...rangeStyle
2022-12-16 19:08:34 +08:00
}">
<!-- 图表 -->
<div v-for="(item, index) in chartEditStore.getComponentList" :key="item.id">
<!-- 分组 -->
<edit-group v-if="item.isGroup" :groupData="(item as CreateComponentGroupType)"
:groupIndex="index"></edit-group>
<!-- 单组件 -->
<edit-shape-box v-else :data-id="item.id" :index="index" :style="{
2022-10-08 20:49:08 +08:00
...useComponentStyle(item.attr, index),
...getBlendModeStyle(item.styles) as any
2022-12-16 19:08:34 +08:00
}" :item="item" @click="mouseClickHandle($event, item)" @mousedown="mousedownHandle($event, item)"
@mouseenter="mouseenterHandle($event, item)" @mouseleave="mouseleaveHandle($event, item)"
@contextmenu="handleContextMenu($event, item, optionsHandle)">
<component class="edit-content-chart" :class="animationsClass(item.styles.animations)"
:is="item.chartConfig.chartKey" :chartConfig="item" :themeSetting="themeSetting"
:themeColor="themeColor" :style="{
...useSizeStyle(item.attr),
...getFilterStyle(item.styles),
...getTransformStyle(item.styles)
}"></component>
</edit-shape-box>
</div>
</div>
2022-12-16 19:08:34 +08:00
</edit-range>
</div>
</ruler>
<!-- 工具栏 -->
<template #aside>
<edit-tools></edit-tools>
</template>
2022-01-20 21:25:35 +08:00
<!-- 底部控制 -->
<template #bottom>
<EditBottom></EditBottom>
2022-01-21 17:55:35 +08:00
</template>
2022-03-14 19:52:01 +08:00
</content-box>
2022-01-20 21:25:35 +08:00
</template>
<script lang="ts" setup>
2022-03-15 17:49:02 +08:00
import { onMounted, computed } from 'vue'
2022-05-03 16:43:23 +08:00
import { chartColors } from '@/settings/chartThemes/index'
import { MenuEnum } from '@/enums/editPageEnum'
import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
import { animationsClass, getFilterStyle, getTransformStyle, getBlendModeStyle } from '@/utils'
2022-05-03 16:43:23 +08:00
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { MenuOptionsItemType } from '@/views/chart/hooks/useContextMenu.hook.d'
2022-05-03 16:43:23 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
2022-01-27 22:30:35 +08:00
2022-01-30 19:38:12 +08:00
import { useLayout } from './hooks/useLayout.hook'
2022-02-04 18:28:02 +08:00
import { useAddKeyboard } from '../hooks/useKeyboard.hook'
2022-09-08 21:04:13 +08:00
import { dragHandle, dragoverHandle, mousedownHandleUnStop, useMouseHandle } from './hooks/useDrag.hook'
2022-01-27 20:47:22 +08:00
import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
2022-05-03 16:43:23 +08:00
import { ContentBox } from '../ContentBox/index'
import { EditGroup } from './components/EditGroup'
2022-05-03 16:43:23 +08:00
import { EditRange } from './components/EditRange'
2022-12-16 19:08:34 +08:00
// import { EditRule } from './components/EditRule'
import Ruler from './components/EditRule/ruler.vue'
2022-05-03 16:43:23 +08:00
import { EditBottom } from './components/EditBottom'
import { EditShapeBox } from './components/EditShapeBox'
import { EditTools } from './components/EditTools'
2022-01-25 18:19:44 +08:00
2022-03-04 20:57:36 +08:00
const chartEditStore = useChartEditStore()
const { handleContextMenu } = useContextMenu()
2022-01-29 23:58:56 +08:00
2022-01-24 16:25:43 +08:00
// 布局处理
useLayout()
2022-01-30 14:20:28 +08:00
// 点击事件
const { mouseenterHandle, mouseleaveHandle, mousedownHandle, mouseClickHandle } = useMouseHandle()
2022-02-03 22:54:31 +08:00
// 右键事件
const optionsHandle = (
targetList: MenuOptionsItemType[],
allList: MenuOptionsItemType[],
2022-08-14 01:04:03 +08:00
targetInstance: CreateComponentType
) => {
// 多选处理
if (chartEditStore.getTargetChart.selectId.length > 1) {
return allList.filter(i => [MenuEnum.GROUP, MenuEnum.DELETE].includes(i.key as MenuEnum))
}
const statusMenuEnums: MenuEnum[] = []
if (targetInstance.status.lock) {
statusMenuEnums.push(MenuEnum.LOCK)
} else {
statusMenuEnums.push(MenuEnum.UNLOCK)
}
if (targetInstance.status.hide) {
statusMenuEnums.push(MenuEnum.HIDE)
} else {
statusMenuEnums.push(MenuEnum.SHOW)
}
return targetList.filter(i => !statusMenuEnums.includes(i.key as MenuEnum))
}
2022-02-21 19:45:11 +08:00
// 主题色
const themeSetting = computed(() => {
const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting
return chartThemeSetting
})
// 配置项
const themeColor = computed(() => {
const chartThemeColor = chartEditStore.getEditCanvasConfig.chartThemeColor
return chartColors[chartThemeColor]
2022-02-06 01:04:05 +08:00
})
// 是否展示渲染
const filterShow = computed(() => {
return chartEditStore.getEditCanvasConfig.filterShow
})
// 背景
const rangeStyle = computed(() => {
// 设置背景色和图片背景
const background = chartEditStore.getEditCanvasConfig.background
const backgroundImage = chartEditStore.getEditCanvasConfig.backgroundImage
const selectColor = chartEditStore.getEditCanvasConfig.selectColor
const backgroundColor = background ? background : undefined
const computedBackground = selectColor
? { background: backgroundColor }
: { background: `url(${backgroundImage}) no-repeat center center / cover !important` }
// @ts-ignore
return {
...computedBackground,
width: 'inherit',
height: 'inherit'
}
})
2022-02-03 22:54:31 +08:00
// 键盘事件
onMounted(() => {
useAddKeyboard()
})
2022-01-20 21:25:35 +08:00
</script>
<style lang="scss" scoped>
@include goId('chart-edit-layout') {
2022-01-20 21:25:35 +08:00
position: relative;
width: 100%;
2022-01-21 17:55:35 +08:00
overflow: hidden;
2022-01-20 21:25:35 +08:00
@extend .go-point-bg;
@include background-image('background-point');
2022-12-16 19:08:34 +08:00
@include goId('chart-edit-content') {
2022-04-05 20:16:59 +08:00
border-radius: 10px;
2022-08-21 14:42:31 +08:00
margin: 25px;
overflow: hidden;
2022-01-20 21:25:35 +08:00
@extend .go-transition;
@include fetch-theme('box-shadow');
2022-12-16 19:08:34 +08:00
2022-01-27 20:47:22 +08:00
.edit-content-chart {
2022-01-25 22:41:12 +08:00
position: absolute;
overflow: hidden;
}
2022-01-20 21:25:35 +08:00
}
}
</style>