index.vue 6.4 KB

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