index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. <collapse-item
  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. </collapse-item>
  33. </div>
  34. </template>
  35. <script setup lang="ts">
  36. import { ref } from 'vue'
  37. import { animations } from '@/settings/animations/index'
  38. import { CollapseItem } from '@/components/Pages/ChartItemSetting'
  39. import { useDesignStore } from '@/store/modules/designStore/designStore'
  40. import { useTargetData } from '../hooks/useTargetData.hook'
  41. // 全局颜色
  42. const designStore = useDesignStore()
  43. const themeColor = ref(designStore.getAppTheme)
  44. const hoverPreviewAnimate = ref('')
  45. const { targetData } = useTargetData()
  46. // * 选中的动画样式
  47. const activeIndex = (value: string) => {
  48. const selectValue = targetData.value.styles.animations
  49. if (!selectValue.length) return false
  50. return selectValue[0] === value
  51. }
  52. // * 清除动画
  53. const clearAnimation = () => {
  54. targetData.value.styles.animations = []
  55. }
  56. // * 新增动画,现只支持一种
  57. const addAnimation = (item: { label: string; value: string }) => {
  58. targetData.value.styles.animations = [item.value]
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. @include go('chart-configurations-animations') {
  63. padding: 20px 10px;
  64. .clear-btn {
  65. width: 100%;
  66. }
  67. .animation-item {
  68. height: 40px;
  69. line-height: 40px;
  70. text-align: center;
  71. cursor: pointer;
  72. border-radius: 5px;
  73. @include hover-border-color('hover-border-color');
  74. &:hover,
  75. &.active {
  76. color: v-bind('themeColor');
  77. border: 1px solid v-bind('themeColor');
  78. }
  79. }
  80. }
  81. </style>