index.vue 5.3 KB

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