index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="box" v-if="tLength">
  3. <div class="pre" :style="{'transform':'rotate('+(-30+tGrap*i)+'deg)'}" v-for="(a,i) in tLength" :key="i">
  4. <div class="tou">
  5. <div class="jd" :style="{'width':i<=tIdx?'100%':'0rpx'}"></div>
  6. </div>
  7. </div>
  8. <div class="center">
  9. <div class="nei"></div>
  10. </div>
  11. <div class="control">
  12. <image :src="imgBase+'home/kongtiao_jian.png'" @tap="changeTemperature(1)"></image>
  13. <p>{{sjTemperature}}<span>℃</span></p>
  14. <image :src="imgBase+'home/kongtiao_jia.png'" @tap="changeTemperature(2)"></image>
  15. </div>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. props:{
  21. temperature:{
  22. typeof:Number,
  23. default:0
  24. },
  25. minT:{
  26. typeof:Number,
  27. default:16
  28. },
  29. maxT:{
  30. typeof:Number,
  31. default:30
  32. }
  33. },
  34. mounted() {
  35. this.sjTemperature = this.$props.temperature;
  36. this.$nextTick(()=>{
  37. this.init();
  38. })
  39. },
  40. data(){
  41. return {
  42. sjTemperature:0,
  43. tLength:0,
  44. tGrap:0,
  45. tIdx:-1
  46. }
  47. },
  48. methods:{
  49. init(){
  50. if(this.sjTemperature<=this.$props.maxT&&this.sjTemperature>=this.$props.minT){
  51. this.tLength = (this.$props.maxT-this.$props.minT)*2+1;
  52. this.tGrap = (240/(this.tLength-1)).toFixed(2);
  53. if(this.sjTemperature==this.$props.minT) this.tIdx = 0;
  54. else if(this.sjTemperature==this.$props.maxT) this.tIdx = this.tLength-1;
  55. else this.tIdx = (this.sjTemperature-this.$props.minT)/0.5
  56. }
  57. },
  58. changeTemperature(type){
  59. if(type==1){
  60. if(this.sjTemperature==this.$props.minT) return
  61. this.sjTemperature-=0.5
  62. } else if(type==2){
  63. if(this.sjTemperature==this.$props.maxT) return
  64. this.sjTemperature+=0.5
  65. }
  66. this.init();
  67. this.$emit('changeTemperature',this.sjTemperature)
  68. }
  69. }
  70. }
  71. </script>
  72. <style scoped lang="less">
  73. .box{
  74. width: 100%;
  75. height: 100%;
  76. position: relative;
  77. .pre{
  78. width: 100%;
  79. height: 12rpx;
  80. background: transparent;
  81. position: absolute;
  82. left: 0;
  83. top: 50%;
  84. margin-top: -5rpx;
  85. .tou{
  86. width: 50rpx;
  87. height: 100%;
  88. background: #D8D8D8;
  89. box-shadow: 0rpx 4rpx 16rpx 4rpx #EFEFEF;
  90. border-radius: 7.5rpx;
  91. .jd{
  92. height: 100%;
  93. border-radius: 7.5rpx;
  94. background: linear-gradient( 270deg, #3A8DFF 0%, #0BC6FF 100%);
  95. }
  96. }
  97. }
  98. .center{
  99. width: calc(100% - 120rpx);
  100. height: calc(100% - 120rpx);
  101. border-radius: 50%;
  102. background: #FFFFFF;
  103. box-shadow: 0rpx 0rpx 20rpx 8rpx #EDF4FF;
  104. position: absolute;
  105. left: 60rpx;
  106. top: 60rpx;
  107. z-index: 2;
  108. padding: 15rpx;
  109. box-sizing: border-box;
  110. .nei{
  111. width: calc(100% - 60rpx);
  112. height: calc(100% - 60rpx);
  113. border-radius: 50%;
  114. background: #FFFFFF;
  115. border: 20rpx solid #EDF4FF;
  116. position: absolute;
  117. left: 10rpx;
  118. top: 10rpx;
  119. z-index: 3;
  120. }
  121. }
  122. .control{
  123. width: 100%;
  124. height: 100%;
  125. display: flex;
  126. align-items: center;
  127. justify-content: center;
  128. position: absolute;
  129. left: 0;
  130. top: 0;
  131. z-index: 4;
  132. image{
  133. width: 36rpx;
  134. height: 36rpx;
  135. }
  136. p{
  137. margin: 0 35rpx;
  138. font-family: PingFang-SC, PingFang-SC;
  139. font-weight: bold;
  140. font-size: 80rpx;
  141. color: #1D2129;
  142. line-height: 112rpx;
  143. span{
  144. font-weight: 400;
  145. font-size: 48rpx;
  146. }
  147. }
  148. }
  149. }
  150. </style>