index.vue 6.1 KB

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