CircleProgress.vue 5.1 KB

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