index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <edit-rule></edit-rule>
  3. <content-box
  4. id="go-chart-edit-layout"
  5. :flex="true"
  6. :showTop="false"
  7. :showBottom="true"
  8. :depth="1"
  9. :xScroll="true"
  10. @drop="dragHandle"
  11. @dragover="dragoverHandle"
  12. @dragenter="dragoverHandle"
  13. >
  14. <!-- 画布主体 -->
  15. <div id="go-chart-edit-content" @contextmenu="handleContextMenu">
  16. <!-- 展示 -->
  17. <edit-range>
  18. <!-- 滤镜预览 -->
  19. <div
  20. :style="{
  21. ...getFilterStyle(chartEditStore.getEditCanvasConfig),
  22. ...rangeStyle
  23. }"
  24. >
  25. <!-- 图表 -->
  26. <div v-for="(item, index) in chartEditStore.getComponentList" :key="item.id">
  27. <!-- 分组 -->
  28. <edit-group
  29. v-if="item.isGroup"
  30. :groupData="(item as CreateComponentGroupType)"
  31. :groupIndex="index"
  32. ></edit-group>
  33. <!-- 单组件 -->
  34. <edit-shape-box
  35. v-else
  36. :data-id="item.id"
  37. :index="index"
  38. :style="useComponentStyle(item.attr, index)"
  39. :item="item"
  40. @click="mouseClickHandle($event, item)"
  41. @mousedown="mousedownHandle($event, item)"
  42. @mouseenter="mouseenterHandle($event, item)"
  43. @mouseleave="mouseleaveHandle($event, item)"
  44. @contextmenu="handleContextMenu($event, item, optionsHandle)"
  45. >
  46. <component
  47. class="edit-content-chart"
  48. :class="animationsClass(item.styles.animations)"
  49. :is="item.chartConfig.chartKey"
  50. :chartConfig="item"
  51. :themeSetting="themeSetting"
  52. :themeColor="themeColor"
  53. :style="{
  54. ...useSizeStyle(item.attr),
  55. ...getFilterStyle(item.styles),
  56. ...getTransformStyle(item.styles)
  57. }"
  58. ></component>
  59. </edit-shape-box>
  60. </div>
  61. </div>
  62. </edit-range>
  63. </div>
  64. <!-- 工具栏 -->
  65. <template #aside>
  66. <edit-tools></edit-tools>
  67. </template>
  68. <!-- 底部控制 -->
  69. <template #bottom>
  70. <EditBottom></EditBottom>
  71. </template>
  72. </content-box>
  73. </template>
  74. <script lang="ts" setup>
  75. import { onMounted, computed } from 'vue'
  76. import { chartColors } from '@/settings/chartThemes/index'
  77. import { MenuEnum } from '@/enums/editPageEnum'
  78. import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
  79. import { animationsClass, getFilterStyle, getTransformStyle } from '@/utils'
  80. import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
  81. import { MenuOptionsItemType } from '@/views/chart/hooks/useContextMenu.hook.d'
  82. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  83. import { useLayout } from './hooks/useLayout.hook'
  84. import { useAddKeyboard } from '../hooks/useKeyboard.hook'
  85. import { dragHandle, dragoverHandle, useMouseHandle } from './hooks/useDrag.hook'
  86. import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
  87. import { ContentBox } from '../ContentBox/index'
  88. import { EditGroup } from './components/EditGroup'
  89. import { EditRange } from './components/EditRange'
  90. import { EditRule } from './components/EditRule'
  91. import { EditBottom } from './components/EditBottom'
  92. import { EditShapeBox } from './components/EditShapeBox'
  93. import { EditTools } from './components/EditTools'
  94. const chartEditStore = useChartEditStore()
  95. const { handleContextMenu } = useContextMenu()
  96. // 布局处理
  97. useLayout()
  98. // 点击事件
  99. const { mouseenterHandle, mouseleaveHandle, mousedownHandle, mouseClickHandle } = useMouseHandle()
  100. // 右键事件
  101. const optionsHandle = (
  102. targetList: MenuOptionsItemType[],
  103. allList: MenuOptionsItemType[],
  104. targetInstance: CreateComponentType
  105. ) => {
  106. // 多选
  107. const moreMenuEnums = [MenuEnum.GROUP, MenuEnum.DELETE]
  108. // 单选
  109. const singleMenuEnums = targetList
  110. // 多选处理
  111. if (chartEditStore.getTargetChart.selectId.length > 1) {
  112. const list: MenuOptionsItemType[] = []
  113. allList.forEach(item => {
  114. // 成组
  115. if (moreMenuEnums.includes(item.key as MenuEnum)) {
  116. list.push(item)
  117. }
  118. })
  119. return list
  120. }
  121. return singleMenuEnums
  122. }
  123. // 主题色
  124. const themeSetting = computed(() => {
  125. const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting
  126. return chartThemeSetting
  127. })
  128. // 配置项
  129. const themeColor = computed(() => {
  130. const chartThemeColor = chartEditStore.getEditCanvasConfig.chartThemeColor
  131. return chartColors[chartThemeColor]
  132. })
  133. // 背景
  134. const rangeStyle = computed(() => {
  135. // 设置背景色和图片背景
  136. const background = chartEditStore.getEditCanvasConfig.background
  137. const backgroundImage = chartEditStore.getEditCanvasConfig.backgroundImage
  138. const selectColor = chartEditStore.getEditCanvasConfig.selectColor
  139. const backgroundColor = background ? background : undefined
  140. const computedBackground = selectColor
  141. ? { background: backgroundColor }
  142. : { background: `url(${backgroundImage}) no-repeat center center / cover !important` }
  143. // @ts-ignore
  144. return {
  145. ...computedBackground,
  146. width: 'inherit',
  147. height: 'inherit'
  148. }
  149. })
  150. // 键盘事件
  151. onMounted(() => {
  152. useAddKeyboard()
  153. })
  154. </script>
  155. <style lang="scss" scoped>
  156. @include goId('chart-edit-layout') {
  157. position: relative;
  158. width: 100%;
  159. overflow: hidden;
  160. @extend .go-point-bg;
  161. @include background-image('background-point');
  162. @include goId('chart-edit-content') {
  163. border-radius: 10px;
  164. margin: 25px;
  165. overflow: hidden;
  166. @extend .go-transition;
  167. @include fetch-theme('box-shadow');
  168. .edit-content-chart {
  169. position: absolute;
  170. overflow: hidden;
  171. }
  172. }
  173. }
  174. </style>