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. status:'',
  43. sjTemperature:0,
  44. tLength:0,
  45. tGrap:0,
  46. tIdx:-1
  47. }
  48. },
  49. methods:{
  50. init(){
  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.maxT&&this.sjTemperature>=this.$props.minT){
  54. if(this.sjTemperature==this.$props.minT) this.tIdx = 0;
  55. else if(this.sjTemperature==this.$props.maxT) this.tIdx = this.tLength-1;
  56. else this.tIdx = (this.sjTemperature-this.$props.minT)/0.5
  57. }
  58. },
  59. changeTemperature(type){
  60. if(this.status==0) return;
  61. if(type==1){
  62. if(this.sjTemperature==this.$props.minT) return
  63. this.sjTemperature-=1
  64. } else if(type==2){
  65. if(this.sjTemperature==this.$props.maxT) return
  66. this.sjTemperature+=1
  67. }
  68. this.init();
  69. this.$emit('changeTemperature',this.sjTemperature)
  70. }
  71. }
  72. }
  73. </script>
  74. <style scoped lang="less">
  75. .box{
  76. width: 100%;
  77. height: 100%;
  78. position: relative;
  79. .pre{
  80. width: 100%;
  81. height: 12rpx;
  82. background: transparent;
  83. position: absolute;
  84. left: 0;
  85. top: 50%;
  86. margin-top: -5rpx;
  87. .tou{
  88. width: 50rpx;
  89. height: 100%;
  90. background: #D8D8D8;
  91. box-shadow: 0rpx 4rpx 16rpx 4rpx #EFEFEF;
  92. border-radius: 7.5rpx;
  93. .jd{
  94. height: 100%;
  95. border-radius: 7.5rpx;
  96. background: linear-gradient( 270deg, #3A8DFF 0%, #0BC6FF 100%);
  97. }
  98. }
  99. }
  100. .center{
  101. width: calc(100% - 120rpx);
  102. height: calc(100% - 120rpx);
  103. border-radius: 50%;
  104. background: #FFFFFF;
  105. box-shadow: 0rpx 0rpx 20rpx 8rpx #EDF4FF;
  106. position: absolute;
  107. left: 60rpx;
  108. top: 60rpx;
  109. z-index: 2;
  110. padding: 15rpx;
  111. box-sizing: border-box;
  112. .nei{
  113. width: calc(100% - 60rpx);
  114. height: calc(100% - 60rpx);
  115. border-radius: 50%;
  116. background: #FFFFFF;
  117. border: 20rpx solid #EDF4FF;
  118. position: absolute;
  119. left: 10rpx;
  120. top: 10rpx;
  121. z-index: 3;
  122. }
  123. }
  124. .control{
  125. width: 100%;
  126. height: 100%;
  127. display: flex;
  128. align-items: center;
  129. justify-content: center;
  130. position: absolute;
  131. left: 0;
  132. top: 0;
  133. z-index: 4;
  134. image{
  135. width: 36rpx;
  136. height: 36rpx;
  137. }
  138. p{
  139. margin: 0 35rpx;
  140. font-family: PingFang-SC, PingFang-SC;
  141. font-weight: bold;
  142. font-size: 80rpx;
  143. color: #1D2129;
  144. line-height: 112rpx;
  145. span{
  146. font-weight: 400;
  147. font-size: 48rpx;
  148. }
  149. }
  150. }
  151. }
  152. </style>