index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <ContentBox
  3. id="go-chart-edit-layout"
  4. ref="editDomRef"
  5. :flex="true"
  6. :showTop="false"
  7. :showBottom="true"
  8. :depth="1"
  9. :xScroll="true"
  10. @drop="handleDrop"
  11. @dragover="handleDragOver"
  12. >
  13. <div id="go-chart-edit-content">
  14. <!-- 展示 -->
  15. <EditRange ref="editRangeRef">
  16. <!-- 图表 -->
  17. <ShapeBox
  18. v-for="(item, index) in chartEditStore.getComponentList"
  19. :key="item.id"
  20. :data-id="item.id"
  21. :index="index"
  22. :style="useComponentStyle(item.attr, index)"
  23. :item="item"
  24. @mousedown="mousedownHandle($event, item)"
  25. @mouseenter="mouseenterHandle($event, item)"
  26. @mouseleave="mouseleaveHandle($event, item)"
  27. @contextmenu="handleContextMenu($event, item)"
  28. >
  29. <component
  30. class="edit-content-chart"
  31. :is="item.key"
  32. :chartData="item"
  33. :themeData="themeData"
  34. :style="useSizeStyle(item.attr)"
  35. />
  36. </ShapeBox>
  37. </EditRange>
  38. </div>
  39. <!-- 底部控制 -->
  40. <template #bottom>
  41. <EditBottom />
  42. </template>
  43. </ContentBox>
  44. </template>
  45. <script lang="ts" setup>
  46. import { ref, onMounted, computed } from 'vue'
  47. import { ContentBox } from '../ContentBox/index'
  48. import { EditRange } from './components/EditRange'
  49. import { EditBottom } from './components/EditBottom'
  50. import { ShapeBox } from './components/ShapeBox/index'
  51. import { useLayout } from './hooks/useLayout.hook'
  52. import { useAddKeyboard } from '../hooks/useKeyboard.hook'
  53. import { handleDrop, handleDragOver, useMouseHandle } from './hooks/useDrop.hook'
  54. import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
  55. import { getChartEditStore } from './hooks/useStore.hook'
  56. import { useComponentStyle, useSizeStyle } from './hooks/useStyle.hook'
  57. import { CreateComponentType } from '@/packages/index.d'
  58. import { chartColors } from '@/settings/chartThemes/index'
  59. const chartEditStore = getChartEditStore()
  60. const { handleContextMenu } = useContextMenu()
  61. // 布局处理
  62. useLayout()
  63. // 点击事件
  64. const editRangeRef = ref<HTMLElement | null>(null)
  65. const { mouseenterHandle, mouseleaveHandle, mousedownHandle } = useMouseHandle()
  66. // 主题色注入
  67. const themeData = computed(() => {
  68. const theme = chartEditStore.getEditCanvasConfig.chartTheme
  69. if(theme === 'dark') return 'dark'
  70. // @ts-ignore
  71. return chartColors[theme]
  72. })
  73. // 键盘事件
  74. onMounted(() => {
  75. useAddKeyboard()
  76. })
  77. </script>
  78. <style lang="scss" scoped>
  79. @include goId(chart-edit-layout) {
  80. position: relative;
  81. width: 100%;
  82. overflow: hidden;
  83. @include background-image('background-point');
  84. @extend .go-point-bg;
  85. @include goId(chart-edit-content) {
  86. margin: 20px;
  87. overflow: hidden;
  88. transform-origin: left top;
  89. border: 1px solid rgba(0, 0, 0, 0);
  90. @extend .go-transition;
  91. &.content-resize {
  92. border-radius: 15px;
  93. @include hover-border-color('hover-border-color');
  94. }
  95. .edit-content-chart {
  96. position: absolute;
  97. }
  98. }
  99. }
  100. </style>