index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 { useSync } from '../hooks/useSync.hook'
  87. import { dragHandle, dragoverHandle, mousedownHandleUnStop, useMouseHandle } from './hooks/useDrag.hook'
  88. import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
  89. import { ContentBox } from '../ContentBox/index'
  90. import { EditGroup } from './components/EditGroup'
  91. import { EditRange } from './components/EditRange'
  92. import { EditRule } from './components/EditRule'
  93. import { EditBottom } from './components/EditBottom'
  94. import { EditShapeBox } from './components/EditShapeBox'
  95. import { EditTools } from './components/EditTools'
  96. const chartEditStore = useChartEditStore()
  97. const { handleContextMenu } = useContextMenu()
  98. const { dataSyncFetch, intervalDataSyncUpdate } = useSync()
  99. // 布局处理
  100. useLayout()
  101. // 点击事件
  102. const { mouseenterHandle, mouseleaveHandle, mousedownHandle, mouseClickHandle } = useMouseHandle()
  103. // 右键事件
  104. const optionsHandle = (
  105. targetList: MenuOptionsItemType[],
  106. allList: MenuOptionsItemType[],
  107. targetInstance: CreateComponentType
  108. ) => {
  109. // 多选
  110. const moreMenuEnums = [MenuEnum.GROUP, MenuEnum.DELETE]
  111. // 单选
  112. const singleMenuEnums = targetList
  113. // 多选处理
  114. if (chartEditStore.getTargetChart.selectId.length > 1) {
  115. const list: MenuOptionsItemType[] = []
  116. allList.forEach(item => {
  117. // 成组
  118. if (moreMenuEnums.includes(item.key as MenuEnum)) {
  119. list.push(item)
  120. }
  121. })
  122. return list
  123. }
  124. return singleMenuEnums
  125. }
  126. // 主题色
  127. const themeSetting = computed(() => {
  128. const chartThemeSetting = chartEditStore.getEditCanvasConfig.chartThemeSetting
  129. return chartThemeSetting
  130. })
  131. // 配置项
  132. const themeColor = computed(() => {
  133. const chartThemeColor = chartEditStore.getEditCanvasConfig.chartThemeColor
  134. return chartColors[chartThemeColor]
  135. })
  136. // 是否展示渲染
  137. const filterShow = computed(() => {
  138. return chartEditStore.getEditCanvasConfig.filterShow
  139. })
  140. // 背景
  141. const rangeStyle = computed(() => {
  142. // 设置背景色和图片背景
  143. const background = chartEditStore.getEditCanvasConfig.background
  144. const backgroundImage = chartEditStore.getEditCanvasConfig.backgroundImage
  145. const selectColor = chartEditStore.getEditCanvasConfig.selectColor
  146. const backgroundColor = background ? background : undefined
  147. const computedBackground = selectColor
  148. ? { background: backgroundColor }
  149. : { background: `url(${backgroundImage}) no-repeat center center / cover !important` }
  150. // @ts-ignore
  151. return {
  152. ...computedBackground,
  153. width: 'inherit',
  154. height: 'inherit'
  155. }
  156. })
  157. onMounted(() => {
  158. // 键盘事件
  159. useAddKeyboard()
  160. // 获取数据
  161. dataSyncFetch()
  162. // 定时更新数据
  163. intervalDataSyncUpdate()
  164. })
  165. </script>
  166. <style lang="scss" scoped>
  167. @include goId('chart-edit-layout') {
  168. position: relative;
  169. width: 100%;
  170. overflow: hidden;
  171. @extend .go-point-bg;
  172. @include background-image('background-point');
  173. @include goId('chart-edit-content') {
  174. border-radius: 10px;
  175. margin: 25px;
  176. overflow: hidden;
  177. @extend .go-transition;
  178. @include fetch-theme('box-shadow');
  179. .edit-content-chart {
  180. position: absolute;
  181. overflow: hidden;
  182. }
  183. }
  184. }
  185. </style>