index.vue 5.9 KB

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