index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div class="editable-element-chart"
  3. :class="{ 'lock': elementInfo.lock }"
  4. :style="{
  5. top: elementInfo.top + 'px',
  6. left: elementInfo.left + 'px',
  7. width: elementInfo.width + 'px',
  8. height: elementInfo.height + 'px',
  9. }"
  10. @mousedown="$event => handleSelectElement($event)"
  11. >
  12. <div
  13. class="element-content"
  14. :style="{
  15. backgroundColor: elementInfo.fill,
  16. }"
  17. v-contextmenu="contextmenus"
  18. >
  19. <ElementOutline
  20. :width="elementInfo.width"
  21. :height="elementInfo.height"
  22. :outline="elementInfo.outline"
  23. />
  24. <Chart
  25. :width="elementInfo.width"
  26. :height="elementInfo.height"
  27. :type="elementInfo.chartType"
  28. :data="elementInfo.data"
  29. :options="elementInfo.options"
  30. :themeColors="elementInfo.themeColors"
  31. :gridColor="elementInfo.gridColor"
  32. />
  33. </div>
  34. </div>
  35. </template>
  36. <script lang="ts">
  37. import { defineComponent, PropType } from 'vue'
  38. import { PPTChartElement } from '@/types/slides'
  39. import { ContextmenuItem } from '@/components/Contextmenu/types'
  40. import ElementOutline from '@/views/components/element/ElementOutline.vue'
  41. import Chart from './Chart.vue'
  42. export default defineComponent({
  43. name: 'editable-element-chart',
  44. components: {
  45. ElementOutline,
  46. Chart,
  47. },
  48. props: {
  49. elementInfo: {
  50. type: Object as PropType<PPTChartElement>,
  51. required: true,
  52. },
  53. selectElement: {
  54. type: Function as PropType<(e: MouseEvent, element: PPTChartElement, canMove?: boolean) => void>,
  55. required: true,
  56. },
  57. contextmenus: {
  58. type: Function as PropType<() => ContextmenuItem[]>,
  59. },
  60. },
  61. setup(props) {
  62. const handleSelectElement = (e: MouseEvent) => {
  63. if(props.elementInfo.lock) return
  64. e.stopPropagation()
  65. props.selectElement(e, props.elementInfo)
  66. }
  67. return {
  68. handleSelectElement,
  69. }
  70. },
  71. })
  72. </script>
  73. <style lang="scss" scoped>
  74. .editable-element-chart {
  75. position: absolute;
  76. cursor: move;
  77. &.lock .element-content {
  78. cursor: default;
  79. }
  80. }
  81. .element-content {
  82. width: 100%;
  83. height: 100%;
  84. }
  85. </style>