CircleProgress.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div>
  3. <div class="number" v-if="textPosition == 'top'">
  4. <ul class="flex">
  5. <!-- <ScrollNum v-for="(num, idx) of numArr" :key="idx" as="li" :i="num" :delay="idx + 1" /> -->
  6. <count-to :useEasing="false" style="font-size: 0.08rem;" :startVal='1' :endVal='targetValue' :duration='2000'></count-to>
  7. <span>个</span>
  8. </ul>
  9. </div>
  10. </div>
  11. <div class="progress" :style="{ width, height }">
  12. <svg viewBox="0 0 96 96" class="svg-circle-progress">
  13. <circle r="38" cx="48" cy="48" fill="none" stroke-miterlimit="20" stroke-width="4" class="svg-progress"
  14. style="stroke-dasharray: 275, 279.602; stroke: rgba(255, 255, 255, 0.19)"></circle>
  15. <circle r="38" transform="rotate(180 48 48)" cx="48" cy="48" fill="none" stroke-miterlimit="20" stroke-width="4"
  16. class="svg-progress" :style="`stroke-dasharray: 240, 279.602;stroke:${color};`"></circle>
  17. </svg>
  18. <div class="mask">
  19. <slot></slot>
  20. </div>
  21. </div>
  22. <div class="bottomNumber" v-if="textPosition == 'bottom'">
  23. <ul class="flex" style="width: 65px;display: flex;align-items: center;justify-content: center;">
  24. <!-- <ScrollNum v-for="(num, idx) of numArr" :key="idx" as="li" :i="num" :delay="idx + 1" /> -->
  25. <div style="color: #fff;font-weight: 600; ">
  26. <count-to :useEasing="false" style="font-size: 0.08rem;" :startVal='1' :endVal='targetValue' :duration='2000'></count-to>
  27. </div>
  28. <span style="color: antiquewhite;" v-if="text.includes('课程')">(节)</span>
  29. <span style="color: antiquewhite;" v-else>(个)</span>
  30. </ul>
  31. </div>
  32. </template>
  33. <script setup lang="ts">
  34. import { ref, computed, toRefs, watch, onMounted,reactive } from 'vue';
  35. import ScrollNum from './roll.vue';
  36. import { CountTo } from 'vue3-count-to';
  37. const props = defineProps({
  38. targetValue: {
  39. type: Number,
  40. require: false,
  41. default: -1,
  42. },
  43. color: {
  44. type: String,
  45. default: '#4c7cee',
  46. },
  47. text: {
  48. type: String,
  49. default: -1,
  50. },
  51. width: {
  52. type: String,
  53. default: '54.6px',
  54. },
  55. height: {
  56. type: String,
  57. default: '54.6px',
  58. },
  59. textPosition: {
  60. type: String,
  61. require: false,
  62. default: 'top',
  63. }
  64. });
  65. const { height, width, color, targetValue, textPosition,text } = toRefs(props);
  66. // let showProgress = ref<number>(0);
  67. const numArr = computed(() => {
  68. const str = String(targetValue.value)
  69. let arr = <any>[]
  70. for (let i = 0; i < str.length; i++) {
  71. arr.push(parseInt(str[i]))
  72. }
  73. return arr
  74. })
  75. const progressValue = ref<number>(0);
  76. let timer = ref<any>(null)
  77. const circleValue = () => {
  78. if (textPosition.value == "top") {
  79. if (progressValue.value = 360) {
  80. timer.value = null
  81. return
  82. }
  83. (timer as any) = setInterval(() => {
  84. progressValue.value += 5
  85. }, 3000)
  86. } else {
  87. if (progressValue.value = 120) {
  88. timer.value = null
  89. return
  90. }
  91. (timer as any) = setInterval(() => {
  92. progressValue.value += 5
  93. }, 3000)
  94. }
  95. }
  96. onMounted(() => {
  97. circleValue()
  98. })
  99. // const progressValue = ref(0)
  100. watch(textPosition, (newValue) => {
  101. console.log("监听一下现在的位置", newValue)
  102. // progressValue.value = 360;
  103. });
  104. </script>
  105. <style lang="scss" scoped>
  106. .progress {
  107. display: flex;
  108. flex-direction: column;
  109. align-items: center;
  110. justify-content: center;
  111. text-align: center;
  112. }
  113. .svg-circle-progress {
  114. position: relative;
  115. transform: rotate(-90deg);
  116. }
  117. .svg-progress {
  118. stroke: #2196f3;
  119. stroke-linecap: round;
  120. transition: all 0.3s linear;
  121. }
  122. .mask {
  123. position: absolute;
  124. margin-top: 5px;
  125. }
  126. .number {
  127. font-size: 14px;
  128. font-weight: bold;
  129. span {
  130. font-size: 12px;
  131. }
  132. }
  133. ul {
  134. padding: 0;
  135. margin: 0
  136. }
  137. .flex {
  138. display: flex;
  139. // border: 1px solid darkblue;
  140. box-sizing: border-box;
  141. // width: 100px;
  142. align-items: center;
  143. text-align: center;
  144. span {
  145. font-size: 12px;
  146. margin-left: 4px;
  147. }
  148. }
  149. </style>