| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <template>
- <content-box
- id="go-chart-edit-layout"
- :flex="true"
- :showTop="false"
- :showBottom="true"
- :depth="1"
- :xScroll="true"
- @drop="dragHandle"
- @dragover="dragoverHandle"
- @dragenter="dragoverHandle"
- >
- <!-- 画布主体 -->
- <div id="go-chart-edit-content" @contextmenu="handleContextMenu">
- <!-- 展示 -->
- <edit-range>
- <!-- 滤镜预览 -->
- <div
- :style="{
- ...getFilterStyle(chartEditStore.getEditCanvasConfig),
- ...rangeStyle
- }"
- >
- <!-- 图表 -->
- <div v-for="(item, index) in chartEditStore.getComponentList" :key="item.id">
- <!-- 分组 -->
- <edit-group v-if="item.isGroup" :groupData="item" :groupIndex="index"></edit-group>
-
- <!-- 单组件 -->
- <edit-shape-box
- v-if="!item.isGroup"
- :data-id="item.id"
- :index="index"
- :style="useComponentStyle(item.attr, index)"
- :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>
- </edit-range>
- </div>
- <!-- 工具栏 -->
- <template #aside>
- <edit-tools></edit-tools>
- </template>
- <!-- 底部控制 -->
- <template #bottom>
- <EditBottom></EditBottom>
- </template>
- </content-box>
- </template>
- <script lang="ts" setup>
- import { onMounted, computed } from 'vue'
- import { chartColors } from '@/settings/chartThemes/index'
- import { MenuEnum } from '@/enums/editPageEnum'
- import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
- import { animationsClass, getFilterStyle, getTransformStyle } from '@/utils'
- import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
- import { MenuOptionsItemType } from '@/views/chart/hooks/useContextMenu.hook.d'
- import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
- import { useLayout } from './hooks/useLayout.hook'
- import { useAddKeyboard } from '../hooks/useKeyboard.hook'
- import { dragHandle, dragoverHandle, useMouseHandle } from './hooks/useDrag.hook'
- import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
- import { ContentBox } from '../ContentBox/index'
- import { EditGroup } from './components/EditGroup'
- import { EditRange } from './components/EditRange'
- import { EditBottom } from './components/EditBottom'
- import { EditShapeBox } from './components/EditShapeBox'
- import { EditTools } from './components/EditTools'
- const chartEditStore = useChartEditStore()
- const { handleContextMenu } = useContextMenu()
- // 布局处理
- useLayout()
- // 点击事件
- const { mouseenterHandle, mouseleaveHandle, mousedownHandle, mouseClickHandle } = useMouseHandle()
- // 右键事件
- const optionsHandle = (
- targetList: MenuOptionsItemType[],
- allList: MenuOptionsItemType[],
- item: CreateComponentType
- ) => {
- // 多选处理
- if (chartEditStore.getTargetChart.selectId.length > 1) {
- const list: MenuOptionsItemType[] = []
- targetList.forEach(item => {
- // 成组
- if (item.key === MenuEnum.GROUP) {
- list.push(item)
- }
- })
- return list
- }
- return targetList
- }
- // 主题色
- const themeSetting = computed(() => {
- const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting
- return chartThemeSetting
- })
- // 配置项
- const themeColor = computed(() => {
- const chartThemeColor = chartEditStore.getEditCanvasConfig.chartThemeColor
- return chartColors[chartThemeColor]
- })
- // 背景
- 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'
- }
- })
- // 键盘事件
- onMounted(() => {
- useAddKeyboard()
- })
- </script>
- <style lang="scss" scoped>
- @include goId('chart-edit-layout') {
- position: relative;
- width: 100%;
- overflow: hidden;
- @extend .go-point-bg;
- @include background-image('background-point');
- @include goId('chart-edit-content') {
- border-radius: 10px;
- margin: 15px;
- overflow: hidden;
- @extend .go-transition;
- @include fetch-theme('box-shadow');
- .edit-content-chart {
- position: absolute;
- overflow: hidden;
- }
- }
- }
- </style>
|