index.vue 5.4 KB

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