roundProgress.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. console.log(this.plan)
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .annulus-box {
  73. // box-shadow: 0 0 5px #ccc;
  74. position: relative;
  75. margin: auto;
  76. .plan {
  77. border-radius: 50%;
  78. background: white;
  79. position: absolute;
  80. z-index: 5;
  81. box-shadow: 0 0 5px #ccc inset;
  82. display: flex;
  83. justify-content: center;
  84. align-items: center;
  85. font-weight: bold;
  86. font-size: 14px;
  87. color: #424242;
  88. }
  89. // -webkit-mask: radial-gradient(transparent 50px, white 0px);
  90. .annulus-bck {
  91. width: 100%;
  92. height: 100%;
  93. border-radius: 50%;
  94. background: radial-gradient(rgb(0, 255, 213) 50%, rgb(0, 110, 255) 100%);
  95. position: absolute;
  96. left: 0;
  97. top: 0;
  98. box-shadow: 0 0 10px #ccc;
  99. display: flex;
  100. justify-content: space-between;
  101. overflow: hidden;
  102. }
  103. .annulus-left,
  104. .annulus-right {
  105. transform: scale(1.01);
  106. transform-origin: 50% 50%;
  107. width: 50%;
  108. height: 100%;
  109. overflow: hidden;
  110. position: relative;
  111. .semicircle {
  112. transition: linear 0.5s;
  113. /*width: $annulusBox;*/
  114. height: 100%;
  115. border-radius: 50%;
  116. }
  117. }
  118. .annulus-left {
  119. .semicircle {
  120. transition-delay: 0.5s;
  121. left: 0;
  122. clip-path: polygon(0% 0%, 50% 0%, 50% 100%, 0% 100%);
  123. background: white;
  124. }
  125. }
  126. .annulus-right {
  127. .semicircle {
  128. position: relative;
  129. left: -100%;
  130. clip-path: polygon(50% 0%, 100% 0%, 100% 100%, 50% 100%);
  131. background: white;
  132. }
  133. }
  134. }
  135. </style>