index.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div class="go-chart-configurations-animations" v-if="targetData">
  3. <n-button
  4. class="clear-btn"
  5. :disabled="!targetData.styles.animations.length"
  6. @click="clearAnimation"
  7. >
  8. 清除动画
  9. </n-button>
  10. <CollapseItem
  11. v-for="(item, index) in animations"
  12. :key="index"
  13. :name="item.label"
  14. :expanded="true"
  15. >
  16. <n-grid :x-gap="6" :y-gap="10" :cols="3">
  17. <n-grid-item
  18. class="animation-item go-transition-quick"
  19. :class="[
  20. activeIndex(childrenItem.value) && 'active',
  21. hoverPreviewAnimate === childrenItem.value &&
  22. `animate__animated animate__${childrenItem.value}`
  23. ]"
  24. v-for="(childrenItem, index) in item.children"
  25. :key="index"
  26. @mouseover="hoverPreviewAnimate = childrenItem.value"
  27. @click="addAnimation(childrenItem)"
  28. >
  29. {{ childrenItem.label }}
  30. </n-grid-item>
  31. </n-grid>
  32. </CollapseItem>
  33. </div>
  34. </template>
  35. <script setup lang="ts">
  36. import { computed, ref, Ref } from 'vue'
  37. import { animations } from '@/settings/animations/index'
  38. import { CollapseItem } from '@/components/ChartItemSetting/index'
  39. import { CreateComponentType } from '@/packages/index.d'
  40. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  41. import { useDesignStore } from '@/store/modules/designStore/designStore'
  42. // 全局颜色
  43. const designStore = useDesignStore()
  44. const themeColor = ref(designStore.getAppTheme)
  45. const chartEditStore = useChartEditStore()
  46. const hoverPreviewAnimate = ref('')
  47. const targetData: Ref<CreateComponentType> = computed(() => {
  48. const list = chartEditStore.getComponentList
  49. const targetIndex = chartEditStore.fetchTargetIndex()
  50. return list[targetIndex]
  51. })
  52. // * 选中样式
  53. const activeIndex = (value: string) => {
  54. const selectValue = targetData.value.styles.animations
  55. if (!selectValue.length) return false
  56. return selectValue[0] === value
  57. }
  58. // * 清除动画
  59. const clearAnimation = () => {
  60. targetData.value.styles.animations = []
  61. }
  62. // * 新增动画,现只支持一种
  63. const addAnimation = (item: { label: string; value: string }) => {
  64. targetData.value.styles.animations = [item.value]
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. @include go('chart-configurations-animations') {
  69. padding: 20px 10px;
  70. .clear-btn {
  71. width: 100%;
  72. }
  73. .animation-item {
  74. height: 50px;
  75. line-height: 50px;
  76. text-align: center;
  77. cursor: pointer;
  78. border-radius: 5px;
  79. @include hover-border-color('hover-border-color');
  80. &:hover,
  81. &.active {
  82. color: v-bind('themeColor');
  83. border: 1px solid v-bind('themeColor');
  84. }
  85. }
  86. }
  87. </style>