circle.vue 2.25 KB
<template>
	<view style="text-align: center;">
		<div style="display: inline-block;position: relative;">
		  <svg style="transform: rotate(-90deg)" :width="width" :height="width" xmlns="http://www.w3.org/2000/svg">
		    <circle :r="(width-radius)/2"
		      :cy="width/2"
		      :cx="width/2"
		      :stroke-width="radius"
		      :stroke="backgroundColor"
		      fill="none"
		    />
		    <circle ref="$bar"
		      :r="(width-radius)/2"
		      :cy="width/2"
		      :cx="width/2"
		      :stroke="barColor"
		      :stroke-width="radius"
		      :stroke-linecap="isRound ? 'round' : 'square'"
		      :stroke-dasharray="(width-radius)*3.14"
		      :stroke-dashoffset="isAnimation ? (width-radius) * 3.14 : (width - radius) * 3.14 * (100 - progress) / 100"
		      fill="none"
		    />
		  </svg>
		  <div class='contentBox'>
			  <div>
				  <img :src="picSrc" alt="">
			  </div>
			  <div :style="{color:textColor}">{{num}}</div>
		  </div>
		  
		</div>
	</view>
</template>

<script>
export default {
	data () {
			return {
			}
	},
	computed: {
		width() {
			return uni.upx2px(200) 
		},
	},
  props: {
	  num:[Number,String],
	  picSrc:[String],
	  textColor:[String],
	  align:[String],
    radius: [Number, String], // 进度条厚度
    progress: [Number, String], // 进度条百分比
    barColor: String, // 进度条颜色
    backgroundColor: String, // 背景颜色
    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 {
      idStr: `circle_progress_keyframes_${this.id}`
    }
  },
  beforeDestroy() {},
  mounted() {},
}
</script>
<style scoped>
	.contentBox{
		position: absolute;
		top: 61.59upx;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
	}
	.contentBox img{
		width: 32.6upx;
	}
</style>