ScreenElement.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div
  3. class="screen-element"
  4. :style="{
  5. zIndex: elementIndex,
  6. color: theme.fontColor,
  7. fontFamily: theme.fontName,
  8. visibility: needWaitAnimation ? 'hidden' : 'visible',
  9. }"
  10. >
  11. <component
  12. :is="currentElementComponent"
  13. :elementInfo="elementInfo"
  14. ></component>
  15. </div>
  16. </template>
  17. <script lang="ts">
  18. import { computed, defineComponent, PropType } from 'vue'
  19. import { useStore } from '@/store'
  20. import { ElementTypes, PPTElement, Slide } from '@/types/slides'
  21. import BaseImageElement from '@/views/components/element/ImageElement/BaseImageElement.vue'
  22. import BaseTextElement from '@/views/components/element/TextElement/BaseTextElement.vue'
  23. import BaseShapeElement from '@/views/components/element/ShapeElement/BaseShapeElement.vue'
  24. import BaseLineElement from '@/views/components/element/LineElement/BaseLineElement.vue'
  25. import ScreenChartElement from '@/views/components/element/ChartElement/ScreenChartElement.vue'
  26. import BaseTableElement from '@/views/components/element/TableElement/BaseTableElement.vue'
  27. export default defineComponent({
  28. name: 'screen-element',
  29. props: {
  30. elementInfo: {
  31. type: Object as PropType<PPTElement>,
  32. required: true,
  33. },
  34. elementIndex: {
  35. type: Number,
  36. required: true,
  37. },
  38. animationIndex: {
  39. type: Number,
  40. default: -1,
  41. },
  42. },
  43. setup(props) {
  44. const currentElementComponent = computed(() => {
  45. const elementTypeMap = {
  46. [ElementTypes.IMAGE]: BaseImageElement,
  47. [ElementTypes.TEXT]: BaseTextElement,
  48. [ElementTypes.SHAPE]: BaseShapeElement,
  49. [ElementTypes.LINE]: BaseLineElement,
  50. [ElementTypes.CHART]: ScreenChartElement,
  51. [ElementTypes.TABLE]: BaseTableElement,
  52. }
  53. return elementTypeMap[props.elementInfo.type] || null
  54. })
  55. const store = useStore()
  56. const theme = computed(() => store.state.theme)
  57. const currentSlide = computed<Slide>(() => store.getters.currentSlide)
  58. const needWaitAnimation = computed(() => {
  59. const animations = currentSlide.value.animations || []
  60. const elementIndexInAnimation = animations.findIndex(animation => animation.elId === props.elementInfo.id)
  61. if(elementIndexInAnimation !== -1 && elementIndexInAnimation >= props.animationIndex) return true
  62. return false
  63. })
  64. return {
  65. currentElementComponent,
  66. needWaitAnimation,
  67. theme,
  68. }
  69. },
  70. })
  71. </script>