roundProgress.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="overall">
  3. <div class="annulus-box" :style="{width: width + 'px', height: width + 'px'}">
  4. <div class="plan" :style="{width: width-ringWidth + 'px', height: width-ringWidth + 'px', left: `calc(50% - ${(width-ringWidth)/2}px)`, top: `calc(50% - ${(width-ringWidth)/2}px)`}">
  5. <span >{{plan}}%</span>
  6. </div>
  7. <div class="annulus-bck">
  8. <div class="annulus-left">
  9. <!-- :style="`transform: rotate(${plan>50?(plan-50)*3.6:0}deg);`" -->
  10. <div ref="semicircle-l" class="semicircle" :style="{width: width + 'px'}"></div>
  11. </div>
  12. <div class="annulus-right">
  13. <!-- :style="`transform: rotate(${plan<50?plan*3.6:180}deg);`" -->
  14. <div ref="semicircle-r" class="semicircle" :style="{width: width + 'px'}"></div>
  15. </div>
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'roundProgress',
  23. props: {
  24. plan: {
  25. default: 0,
  26. type: Number | String
  27. },
  28. width: { // px
  29. default: 70,
  30. type: Number
  31. },
  32. ringWidth: { // px
  33. default: 20,
  34. type: Number
  35. },
  36. },
  37. data() {
  38. return {}
  39. },
  40. mounted() {
  41. this.planChange()
  42. },
  43. methods: {
  44. planChange() {
  45. setTimeout(() => {
  46. if (this.plan > 50 && this.plan <= 100) {
  47. this.$refs['semicircle-l'].style.transform = `rotate(${(this.plan -
  48. 50) *
  49. 3.6}deg)`
  50. }
  51. if (this.plan > 100) {
  52. this.$refs['semicircle-l'].style.transform = `rotate(180deg)`
  53. }
  54. if (this.plan < 50) {
  55. this.$refs['semicircle-r'].style.transform = `rotate(${this.plan *
  56. 3.6}deg)`
  57. }else if (this.plan ==='暂无') {
  58. this.$refs['semicircle-r'].style.transform = `rotate(${0 *
  59. 3.6}deg)`
  60. }else {
  61. this.$refs['semicircle-r'].style.transform = `rotate(180deg)`
  62. }
  63. }, 500)
  64. }
  65. },
  66. created() {
  67. }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. .annulus-box {
  72. // box-shadow: 0 0 5px #ccc;
  73. position: relative;
  74. margin: auto;
  75. .plan {
  76. border-radius: 50%;
  77. background: white;
  78. position: absolute;
  79. z-index: 5;
  80. box-shadow: 0 0 5px #ccc inset;
  81. display: flex;
  82. justify-content: center;
  83. align-items: center;
  84. font-weight: bold;
  85. font-size: 14px;
  86. color: #424242;
  87. }
  88. // -webkit-mask: radial-gradient(transparent 50px, white 0px);
  89. .annulus-bck {
  90. width: 100%;
  91. height: 100%;
  92. border-radius: 50%;
  93. background: radial-gradient(rgb(0, 255, 213) 50%, rgb(0, 110, 255) 100%);
  94. position: absolute;
  95. left: 0;
  96. top: 0;
  97. box-shadow: 0 0 10px #ccc;
  98. display: flex;
  99. justify-content: space-between;
  100. overflow: hidden;
  101. }
  102. .annulus-left,
  103. .annulus-right {
  104. transform: scale(1.01);
  105. transform-origin: 50% 50%;
  106. width: 50%;
  107. height: 100%;
  108. overflow: hidden;
  109. position: relative;
  110. .semicircle {
  111. transition: linear 0.5s;
  112. /*width: $annulusBox;*/
  113. height: 100%;
  114. border-radius: 50%;
  115. }
  116. }
  117. .annulus-left {
  118. .semicircle {
  119. transition-delay: 0.5s;
  120. left: 0;
  121. clip-path: polygon(0% 0%, 50% 0%, 50% 100%, 0% 100%);
  122. background: white;
  123. }
  124. }
  125. .annulus-right {
  126. .semicircle {
  127. position: relative;
  128. left: -100%;
  129. clip-path: polygon(50% 0%, 100% 0%, 100% 100%, 50% 100%);
  130. background: white;
  131. }
  132. }
  133. }
  134. </style>