首页 > 其他分享 >直播电商平台开发,环形进度条组件

直播电商平台开发,环形进度条组件

时间:2023-05-04 14:24:56浏览次数:38  
标签:进度条 default width radius 组件 progress 电商 type id

直播电商平台开发,环形进度条组件

 

<template>
  <div class="content" ref="box">
    <svg
      :id="idStr"
      style="transform: rotate(-90deg)"
      :width="width"
      :height="width"
      xmlns="http://www.w3.org/2000/svg"
    >
      <linearGradient :id="`gradient-${id}`" gradientUnits="userSpaceOnUse">
        <stop
          v-for="(item, index) in gradientsColor"
          :key="index"
          :offset="item.offset"
          :stop-color="item.color"
        />
      </linearGradient>
      <circle
        :r="(width-radius)/2"
        :cy="width/2"
        :cx="width/2"
        :stroke-width="radius"
        :stroke="backgroundColor"
        fill="none"
      />
      <circle
        v-if="gradientsColorShow"
        ref="$bar"
        :r="(width-radius)/2"
        :cy="width/2"
        :cx="width/2"
        :stroke="gradientsColor ? `url(#gradient-${id})` : barColor"
        :stroke-width="radius"
        :stroke-linecap="isRound ? 'round' : 'square'"
        :stroke-dasharray="(width-radius)*3.14"
        :stroke-dashoffset="dashoffsetValue"
        fill="none"
      />
    </svg>
    <div class="center_text">
      <p v-if="!$slots.default" class="title">{{progress}}%</p>
      <slot></slot>
    </div>
  </div>
</template>
<script>
// import _ from "lodash";
export default {
  props: {
    widthPresent: {
      type: Number,
      default: 1
    },
    gradientsColor: {
      type: [Boolean, Array],
      default: false
    },
    radius: {
      type: [Number, String],
      default: 20
    }, // 进度条厚度
    progress: {
      type: [Number, String],
      default: 20
    }, // 进度条百分比
    barColor: {
      type: String,
      default: "#1890ff"
    }, // 进度条颜色
    backgroundColor: {
      type: String,
      default: "rgba(0,0,0,0.3)"
    }, // 背景颜色
    isAnimation: {
      // 是否是动画效果
      type: Boolean,
      default: true
    },
    isRound: {
      // 是否是圆形画笔
      type: Boolean,
      default: true
    },
    id: {
      // 组件的id,多组件共存时使用
      type: [String, Number],
      default: 1
    },
    duration: {
      // 整个动画时长
      type: [String, Number],
      default: 1000
    },
    delay: {
      // 延迟多久执行
      type: [String, Number],
      default: 200
    },
    timeFunction: {
      // 动画缓动函数
      type: String,
      default: "cubic-bezier(0.99, 0.01, 0.22, 0.94)"
    }
  },
  data() {
    return {
      width: 200,
      idStr: "",
      oldValue: 0
    };
  },
  computed: {
    gradientsColorShow: function() {
      return true;
    },
    dashoffsetValue: function() {
      const { isAnimation, width, radius, progress, oldValue } = this;
      return isAnimation
        ? ((width - radius) * 3.14 * (100 - oldValue)) / 100
        : ((width - radius) * 3.14 * (100 - progress)) / 100;
    }
  },
  watch: {
    id: function() {
      this.idStr = `circle_progress_keyframes_${this.id || 1}`;
    },
    progress: function(newData, oldData) {
      if (newData !== oldData) {
        this.oldValue = oldData;
        this.setAnimation();
      }
    }
  },
  mounted() {
    this.idStr = `circle_progress_keyframes_${this.id || 1}`;
    let self = this;
    this.setCircleWidth();
    this.setAnimation();
    // 此处不能使用window.onresize
    window.addEventListener("resize", function() {
      self.setCircleWidth();
      self.setAnimation(self);
    });
  },
  methods: {
    setCircleWidth() {
      const { widthPresent } = this;
      this.$nextTick(() => {
        let box = this.$refs.box;
        let width = box.clientWidth * widthPresent;
        let height = box.clientHeight * widthPresent;
        let cW = width > height ? height : width;
        this.width = cW;
      })
    },
    setAnimation() {
      let self = this;
      if (self.isAnimation) {
        // 重复定义判断
        if (document.getElementById(self.idStr)) {
          self.$refs.$bar.classList.remove(`circle_progress_bar${self.id}`);
        }
        this.$nextTick(() => {
          this.startAnimation();
        });
      }
    },
    startAnimation() {
      // 生成动画样式文件
      let style = document.createElement("style");
      style.id = this.idStr;
      style.type = "text/css";
      style.innerHTML = `
      @keyframes circle_progress_keyframes_name_${this.id} {
      from {stroke-dashoffset: ${((this.width - this.radius) *
        3.14 *
        (100 - this.oldValue)) /
        100}px;}
      to {stroke-dashoffset: ${((this.width - this.radius) *
        3.14 *
        (100 - this.progress)) /
        100}px;}}
      .circle_progress_bar${
        this.id
      } {animation: circle_progress_keyframes_name_${this.id} ${
        this.duration
      }ms ${this.delay}ms ${this.timeFunction} forwards;}`;
      // 添加新样式文件
      document.getElementsByTagName("head")[0].appendChild(style);
      // 往svg元素中添加动画class
      this.$refs.$bar.classList.add(`circle_progress_bar${this.id}`);
    }
  }
};
</script>
<style  scoped>
.content {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.center_text {
  position: absolute;
  font-size: 16px;
  font-weight: bold;
}
</style>

以上就是直播电商平台开发,环形进度条组件, 更多内容欢迎关注之后的文章

 

标签:进度条,default,width,radius,组件,progress,电商,type,id
From: https://www.cnblogs.com/yunbaomengnan/p/17371076.html

相关文章

  • 第十二章——电商产品评论数据情感分析
    1、评论去重的代码importpandasaspdimportreimportjieba.possegaspsgimportnumpyasnp#去重,去除完全重复的数据reviews=pd.read_csv("./reviews.csv")reviews=reviews[['content','content_type']].drop_duplicates()content=revie......
  • 关于OKD(OpenShift)中组件资源介绍和命令行操作的一些笔记
    写在前面参加考试,会陆续分享一些OpenShift的笔记博文内容为openshift常见API资源对象介绍,包括所特有的Route,IS,DC,BC等。学习环境为openshiftv3的版本,有些旧这里如果专门学习openshift,建议学习v4版本理解不足小伙伴帮忙指正傍晚时分,你坐在屋檐下,看着天慢慢地黑下去,心......
  • 跨境电商出海东南亚,茄子科技助力企业实现品牌出海
    作为亚洲最具潜力的电商市场之一,东南亚地区拥有6亿多人口,电商市场高达218亿美元。人口红利、数字化经济高额投资、移动设备全面普及等,正在为东南亚的跨境电商搭建起庞大的市场基础框架,推动电商多种形态在东南亚崛起,天然的电商发展沃土让东南亚正成为企业品牌出海寻求增量的优质选择......
  • 【HarmonyOS】自定义组件之ArkUI实现通用标题栏组件
     【关键字】标题栏、常用内置组件整合、ArkUI、自定义组件 1、写在前面在上一篇文章中我们通过Java语言实现了一个通用的标题栏组件,有需要的可以看下,文章地址:https://developer.huawei.com/consumer/cn/forum/topic/0202117373459738584?fid=0101587866109860105现在很多......
  • 电商产品评论数据情感分析
    #代码12-1评论去重的代码importpandasaspdimportreimportjieba.possegaspsgimportnumpyasnp#去重,去除完全重复的数据reviews=pd.read_csv("D:/school/three/below/12/data/reviews.csv")reviews=reviews[['content','content_type']].......
  • 电商产品评论数据情感分析
    #代码12-1评论去重的代码importpandasaspdimportreimportjieba.possegaspsgimportnumpyasnp#去重,去除完全重复的数据reviews=pd.read_csv("D:/JupyterLab-Portable-3.1.0-3.9/新建文件夹/第十二章/reviews.csv")reviews=reviews[['content','content......
  • BootstrapBlazor组件保姆级教程
    BootstrapBlazor组件库保姆级使用教程BootstrapBlazor组件库官网https://www.blazor.zone/componentsBootstrapBlazor组件库github仓库地址https://github.com/dotnetcore/BootstrapBlazorBootstrapBlazor组件库gitee仓库地址https://gitee.com/LongbowEnterprise/Bootstra......
  • vue2实现数据聚合【scatter-clustering】组件封装
    实现如下效果:效果展示:https://code.juejin.cn/pen/7228568245148581943如果不会请移步到官网的栗子,请点击查看直接给大家上代码:整体代码片段1<template>2<divref="echarts"style="width:100%;height:300px;"></div>3</template>4<scrip......
  • 用vue2封装轮播图组件
    日常练习用vue2封装轮播图组件,传入图片信息数组。实现思想:图片组添加translate动画,通过轮播到第几张图片作为参数,让图片组整体移动。Carousel.vue<template><divclass="carousel"><divclass="carouselList"><!--图片列表--><ulclass="img&quo......
  • 电商产品评论数据情感分析
    #代码12-1评论去重的代码importpandasaspdimportreimportjieba.possegaspsgimportnumpyasnp#去重,去除完全重复的数据reviews=pd.read_csv(r"G:\data\data\reviews.csv")reviews=reviews[['content','content_type']].drop_dupli......