index.vue 2.65 KB
<template>
  <div class="go-animat">
    <div class="go-svg" :style="{ marginLeft: animat.x + 'px', marginTop: animat.y + 'px' }">
      <svg :width="w" :height="h">
        <polyline
          fill="transparent"
          stroke-width="3"
          :points="`0,${h / 5} ${w / 5.555555555555556},${h / 5}  ${w / 5},${h / 2.5}  ${w / 4},${h / 2.5} ${
            w / 3.703703703703704
          },${h / 1.666666666666667}  ${w / 1.388888888888889},${h / 1.666666666666667} ${w / 1.333333333333333},${
            h / 2.5
          }   ${w / 1.25},${h / 2.5}   ${w / 1.219512195121951},${h / 5}  ${w},${h / 5}`"
          :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="`${w / 3.333333333333333},${h / 1.25} ${w / 1.428571428571429},${h / 1.25}`"
          :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>
    <div class="go-text" :style="{ top: animat.textPos.y + '%', left: animat.textPos.x + '%' }">
      <n-gradient-text :size="animat.size" :gradient="animat.gradient">
        {{ dataset }}
      </n-gradient-text>
    </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=180

const { w, h } = toRefs(props.chartConfig.attr)

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

<style lang="scss" scoped>
.go-animat {
  width: v-bind('w+"px"');
  height: v-bind('h+"px"');
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  .go-svg {
  }
  .go-text {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}
</style>