progressBar.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div class="progress-bar color-font" :style="'--percent:'+percent+';'">
  3. <svg class="progress-circle">
  4. <circle stroke="var(--inactive-color)"
  5. style="stroke-dasharray: calc(3.1415 * var(--r) * (360 - 120) / 180),calc(3.1415 * var(--r) * 120 / 180)" />
  6. <circle stroke="var(--color)"
  7. style="stroke-dasharray: calc(3.1415 * var(--r) * var(--percent) * var(--active-degree) / 180 / 100), 1000" />
  8. </svg>
  9. <div class="progress-label">
  10. <span class="alibaba number">{{percent}}</span><span class="unit">%</span>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. props: ['percent', 'title'],
  17. data() {
  18. return {};
  19. },
  20. created() {},
  21. methods: {}
  22. };
  23. </script>
  24. <style lang="scss">
  25. .progress-bar {
  26. width: 70px;
  27. position: relative;
  28. .progress-label {
  29. display: flex;
  30. align-items: center;
  31. position: absolute;
  32. left: 0;
  33. width: 100%;
  34. bottom: 30px;
  35. justify-content: center;
  36. .number {
  37. font-size: 14px;
  38. }
  39. .unit {
  40. opacity: 0.6;
  41. font-size: 7px;
  42. font-weight: 500;
  43. line-height: 10px;
  44. }
  45. }
  46. /* 百分数 */
  47. --percent: 100;
  48. /* 尺寸大小 */
  49. --size: 70px;
  50. /* 环形宽度(粗细) */
  51. --border-width: 6px;
  52. /* 主色 */
  53. --color: #6FF2F0;
  54. /* 辅助色 */
  55. --inactive-color: #283040;
  56. --r: calc((var(--size) - var(--border-width)) / 2);
  57. --gap-degree: 120;
  58. --active-degree: calc(360 - var(--gap-degree));
  59. .progress-circle {
  60. width: var(--size);
  61. height: var(--size);
  62. transform: rotate(-90deg);
  63. border-radius: 50%;
  64. }
  65. circle {
  66. cx: calc(var(--size) / 2);
  67. cy: calc(var(--size) / 2);
  68. r: calc((var(--size) - var(--border-width)) / 2);
  69. fill: none;
  70. stroke-width: var(--border-width);
  71. stroke-linecap: round;
  72. transition: stroke-dasharray 0.4s linear, stroke .3s;
  73. transform: rotate(calc((var(--gap-degree) + (360 - var(--gap-degree)) / 2) * 1deg));
  74. transform-origin: center;
  75. }
  76. }
  77. </style>