vue3圆环进度条组件

一、功能描述

主要用于展示数值,和根据百分比展示圆环

二、代码(圆环进度条组件)

html 复制代码
<template>
  <div class="progress" :style="{ width, height }">
    <svg
      viewBox="0 0 96 96"
      class="svg-circle-progress"
      style="width: 100%; height: 100%"
    >
      <circle
        r="40"
        cx="48"
        cy="48"
        fill="none"
        stroke-miterlimit="20"
        stroke-width="10"
        class="svg-progress"
        :style="`stroke-dasharray: 275, 279.602; stroke: ${bgCol}`"
      ></circle>
      <circle
        r="40"
        cx="48"
        cy="48"
        fill="none"
        stroke-miterlimit="20"
        stroke-width="10"
        class="svg-progress"
        :style="`stroke-dasharray: ${progressValue}, 279.602;stroke:${color};`"
      ></circle>
    </svg>
    <div class="mask">
      <!-- showProgress -->
      <span class="bigData"> {{ showtext }} </span>
    </div>
  </div>
</template>
<script setup>
const props = defineProps({
  // 百分比
  targetValue: {
    type: Number,
    require: true,
    default: -1,
  },
  // 默认轨道背景颜色
  bgCol: {
    type: String,
    default: "#eee",
  },
  // 数值轨道颜色
  color: {
    type: String,
    default: "#4c7cee",
  },
  // 展示数值
  showtext: {
    type: Number,
    default: 0,
    require: true,
  },
  // 宽度
  width: {
    type: String,
    default: "210px",
  },
  // 高度
  height: {
    type: String,
    default: "100px",
  },
});
const { height, width, color, targetValue, bgCol, showtext } = toRefs(props);

const showProgress = ref(0);
const addData = () => {
  if (targetValue.value === 0) return;
  let timer = setInterval(() => {
    if (targetValue.value === showProgress.value) {
      clearInterval(timer), timer == null;
      return;
    }
    ++showProgress.value;
  }, 15);
};
onMounted(() => {
  addData();
});

const progressValue = ref((showProgress.value / 100) * 250);

watch(showProgress, (newValue) => {
  progressValue.value = (newValue / 100) * 250;
});
</script>
<style scoped>
@font-face {
  font-family: 'LCD';
  src: url('/src/assets/static/font/LiquidCrystal-Normal.otf');
}
.progress {
  display: inline-block;
  position: relative;
  height: 100px;
  text-align: center;
}
.svg-circle-progress {
  position: relative;
  transform: rotate(-90deg);
}
.svg-progress {
  stroke: #2196f3;
  stroke-linecap: round;
  transition: all 0.3s linear;
}
.mask {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.bigData {
  font-family: 'LCD';
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
}
</style>

三、使用

html 复制代码
<Cirque
  :target-value="item.progress"
  :bgCol="item.bgCol"
  :color="item.Col"
  :showtext="item.value"
  width="50px"
  height="50px"
  />

四、本项目使用效果

相关推荐
weifont3 分钟前
聊一聊Electron中Chromium多进程架构
javascript·架构·electron
大得3697 分钟前
electron结合vue,直接访问静态文件如何跳转访问路径
javascript·vue.js·electron
水银嘻嘻2 小时前
12 web 自动化之基于关键字+数据驱动-反射自动化框架搭建
运维·前端·自动化
it_remember2 小时前
新建一个reactnative 0.72.0的项目
javascript·react native·react.js
小嘟嚷ovo2 小时前
h5,原生html,echarts关系网实现
前端·html·echarts
十一吖i3 小时前
Vue3项目使用ElDrawer后select方法不生效
前端
只可远观3 小时前
Flutter目录结构介绍、入口、Widget、Center组件、Text组件、MaterialApp组件、Scaffold组件
前端·flutter
周胡杰3 小时前
组件导航 (HMRouter)+flutter项目搭建-混合开发+分栏效果
前端·flutter·华为·harmonyos·鸿蒙·鸿蒙系统
敲代码的小吉米3 小时前
前端上传el-upload、原生input本地文件pdf格式(纯前端预览本地文件不走后端接口)
前端·javascript·pdf·状态模式
是千千千熠啊3 小时前
vue使用Fabric和pdfjs完成合同签章及批注
前端·vue.js