index.vue
7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<template>
<!-- <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">
<edit-rule>
<!-- 画布主体 -->
<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 as CreateComponentGroupType)"
:groupIndex="index"></edit-group>
<!-- 单组件 -->
<edit-shape-box v-else :data-id="item.id" :index="index" :style="{
...useComponentStyle(item.attr, index),
...getBlendModeStyle(item.styles) as any
}" :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="item.colors ? item.colors : themeColor" :style="{
...useSizeStyle(item.attr),
...getFilterStyle(item.styles),
...getTransformStyle(item.styles),
...item.styles.animationsStyleConfig,
}"></component>
</edit-shape-box>
</div>
</div>
</edit-range>
</div>
</edit-rule>
<!-- 工具栏 -->
<template #aside>
<edit-tools></edit-tools>
</template>
<!-- 底部控制 -->
<template #bottom>
<EditBottom></EditBottom>
</template>
</content-box>
</template>
<script lang="ts" setup>
import { onMounted, computed, provide } from 'vue'
import { MenuEnum } from '@/enums/editPageEnum'
import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
import { animationsClass, getFilterStyle, getTransformStyle, getBlendModeStyle, colorCustomMerge } 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 { SCALE_KEY } from '@/views/preview/hooks/useScale.hook'
import { useLayout } from './hooks/useLayout.hook'
import { useAddKeyboard } from '../hooks/useKeyboard.hook'
import { dragHandle, dragoverHandle, mousedownHandleUnStop, useMouseHandle } from './hooks/useDrag.hook'
import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
// THINGS_KIT 引入同步数据源hook
import { useSyncRemote } from '../hooks/external/useRemote.hook'
import { ContentBox } from '../ContentBox/index'
import { EditGroup } from './components/EditGroup'
import { EditRange } from './components/EditRange'
import { EditRule } from './components/EditRule'
import { EditBottom } from './components/EditBottom'
import { EditShapeBox } from './components/EditShapeBox'
import { EditTools } from './components/EditTools'
import { useBackgroundSelect } from '@/utils/external/useBackgroundImageSelect'
import { initSetI18n } from '@/plugins/initSetI18n'
const chartEditStore = useChartEditStore()
const { handleContextMenu } = useContextMenu()
const { dataSyncFetch, intervalDataSyncUpdate } = useSyncRemote()
// 编辑时注入scale变量,消除警告
provide(SCALE_KEY, null)
// 布局处理
// eslint-disable-next-line @typescript-eslint/no-empty-function
useLayout(async () => { })
// 点击事件
const { mouseenterHandle, mouseleaveHandle, mousedownHandle, mouseClickHandle } = useMouseHandle()
// 右键事件
const optionsHandle = (
targetList: MenuOptionsItemType[],
allList: MenuOptionsItemType[],
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))
}
// 主题色
const themeSetting = computed(() => {
const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting
return chartThemeSetting
})
// 配置项
const themeColor = computed(() => {
const colorCustomMergeData = colorCustomMerge(chartEditStore.getEditCanvasConfig.chartCustomThemeColorInfo)
return colorCustomMergeData[chartEditStore.getEditCanvasConfig.chartThemeColor]
})
// 是否展示渲染
const filterShow = computed(() => {
return chartEditStore.getEditCanvasConfig.filterShow
})
// 背景
// THINGS_KIT 路径转换,同步生产环境与开发环境的保存的静态资源文件路径不一致
const { getBackgroundImagePath } = useBackgroundSelect()
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` }
// THINGS_KIT 路径转换,同步生产环境与开发环境的保存的静态资源文件路径不一致
: { background: `url(${getBackgroundImagePath(backgroundImage!)}) no-repeat center center / cover !important` }
return {
...computedBackground,
width: 'inherit',
height: 'inherit'
}
})
// 键盘事件
onMounted(() => {
useAddKeyboard()
// THINGS_KIT
// 获取数据
dataSyncFetch()
// 定时更新数据
intervalDataSyncUpdate()
// 从地址栏设置当前语言环境
try {
initSetI18n()
} catch (e) {
console.error( e)
}
})
</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;
overflow: hidden;
@extend .go-transition;
@include fetch-theme('box-shadow');
.edit-content-chart {
position: absolute;
overflow: hidden;
}
}
}
</style>