index.vue 2.62 KB
<template>
  <div class="go-animat">
    <div class="go-animat-item" :style="{ marginLeft: animat.x + 'px', marginTop: animat.y + 'px' }">
      <svg :width="animat.w + 'px'" :height="animat.h + 'px'">
        <polyline
          fill="transparent"
          stroke-width="3"
          :points="`0,20 ${animat.w / 5.555555555555556},20   ${animat.w / 5},40  ${animat.w / 4},40  ${
            animat.w / 3.703703703703704
          },60  ${animat.w / 1.388888888888889},60  ${animat.w / 1.333333333333333},40  ${animat.w / 1.25},40  ${
            animat.w / 1.219512195121951
          },20  ${animat.w},20`"
          :stroke="animat.colors[0]"
        >
          <animate
            attributeName="stroke-dasharray"
            attributeType="XML"
            :from="`0, 969.031002232793, 0, 969.031002232793`"
            :to="`0, 0, 1938.062004465586, 0`"
            dur="3s"
            begin="0s"
            calcMode="spline"
            keyTimes="0;1"
            keySplines="0.4,1,0.49,0.98"
            repeatCount="indefinite"
          ></animate>
        </polyline>
        <polyline
          fill="transparent"
          stroke-width="2"
          :points="`${animat.w / 3.333333333333333},80 ${animat.w / 1.428571428571429},80`"
          :stroke="animat.colors[1]"
        >
          <animate
            attributeName="stroke-dasharray"
            attributeType="XML"
            from="0, 384, 0, 384"
            to="0, 0, 768, 0"
            dur="3s"
            begin="0s"
            calcMode="spline"
            keyTimes="0;1"
            keySplines=".4,1,.49,.98"
            repeatCount="indefinite"
          ></animate>
        </polyline>
      </svg>
      <div class="go-text" :style="{ top: animat.textPos.y + '%', left: animat.textPos.x + '%' }">
        <n-gradient-text :size="animat.size" :gradient="animat.gradient">
          {{ animat.text }}
        </n-gradient-text>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { PropType, toRefs } from 'vue'
import { CreateComponentType } from '@/packages/index.d'

const props = defineProps({
  chartConfig: {
    type: Object as PropType<CreateComponentType>,
    required: true
  }
})

//默认设置宽高距离位置
props.chartConfig.attr.w = 1920
props.chartConfig.attr.h = 300
props.chartConfig.attr.x = 0
props.chartConfig.attr.y = 0

const { animat } = toRefs(props.chartConfig.option)
</script>

<style lang="scss" scoped>
.go-animat {
  width: 1920px;
  height: 1080px;
  display: flex;
  margin: 0 auto;
  justify-content: center;
  align-items: center;
  .go-animat-item {
    position: relative;
  }
  .go-text {
    position: absolute;
  }
}
</style>