vue 环形进度条封装

<template>
  <div>
    <svg :viewBox="`0 0 ${2 * radius + srtokeWidth} ${radius + srtokeWidth}`">
      <defs>
        <linearGradient id="linear" x1="0%" y1="0%" x2="100%" y2="0%">
          <stop offset="0%" :stop-color="defaultNegativeColor" />
          <stop offset="100%" :stop-color="defaultPositiveColor" />
        </linearGradient>
      </defs>
      <path
        :d="
          `M ${srtokeWidth / 2} ${radius +
            srtokeWidth / 2} a ${radius} ${radius} 0 1 1 ${radius * 2} 0`
        "
        :stroke-width="srtokeWidth"
        :stroke="emptyColor"
        fill="none"
        stroke-linecap="round"
      ></path>
      <path
        :d="
          `M ${srtokeWidth / 2} ${radius +
            srtokeWidth / 2} a ${radius} ${radius} 0 1 1 ${radius * 2} 0`
        "
        :stroke-width="srtokeWidth"
        stroke="url(#linear)"
        fill="none"
        stroke-linecap="round"
        :stroke-dasharray="strokeDasharray"
        :stroke-dashoffset="strokeDashoffset"
      >
        <animate
          attributeName="stroke-dashoffset"
          :dur="`${durTime}ms`"
          fill="freeze"
          :from="strokeDasharray"
          :to="strokeDashoffset"
        ></animate>
      </path>
    </svg>
  </div>
</template>
<script>
export default {
  data() {
    return {
      defaultDurTime: 800, // 进度条完结时间
      defaultEmptyColor: '#ECF2FF', // 默认底色
      defaultNegativeColor: '#d4fc78', // 80EDFF FF4456
      defaultPositiveColor: '#00ba5e', // 进行时底色
      defaultSrtokeWidth: 10, // 进度线宽度
      defaultRadius: 100
    }
  },
  props: ['options', 'value'],
  computed: {
    durTime() {
      return this.options
        ? this.options.durTime || this.defaultDurTime
        : this.defaultDurTime
    },
    radius() {
      return this.options
        ? this.options.radius || this.defaultRadius
        : this.defaultRadius
    },
    emptyColor() {
      return this.options
        ? this.options.emptyColor || this.defaultEmptyColor
        : this.defaultEmptyColor
    },
    srtokeWidth() {
      return this.options
        ? this.options.srtokeWidth || this.defaultSrtokeWidth
        : this.defaultSrtokeWidth
    },
    valueColor() {
      if (this.value < 0) {
        return this.options
          ? this.options.negativeColor || this.defaultNegativeColor
          : this.defaultNegativeColor
      } else {
        return this.options
          ? this.options.positiveColor || this.defaultPositiveColor
          : this.defaultPositiveColor
      }
    },
    strokeDasharray() {
      return 3.1415926 * this.radius
    },
    strokeDashoffset() {
      return this.strokeDasharray - this.strokeDasharray * this.value
      //   return 10
    }
  }
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值