Xxxu
2020-07-03 1ac6ef52a03f25f9def9f6a2594d2a8196aa77f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template>
  <div style="padding: 20px">
    <el-row>
      <el-col :span="18">
        <div class="weather-bound">
          <p class="weather-show">{{ dataForm.city }}</p>
          <p class="weather-show">温度:{{ dataForm.temperature }}℃</p>
          <p class="weather-show">湿度:{{ dataForm.humidity }}%RH</p>
          <p class="weather-show"> 亮度:{{ dataForm.brightness }}lux</p>
          <p class="weather-show">风速:{{ dataForm.windSpeed }}m/s</p>
          <p class="weather-show">CO2:{{ dataForm.eco2 }}ppm</p>
          <p class="weather-show">甲醛:{{ dataForm.ech2o }}mg/m³</p>
          <p class="weather-show">TVOC:{{ dataForm.tvoc }}mg/m³</p>
          <p class="weather-show">PM25:{{ dataForm.pm25 }}mg/m³</p>
          <p class="weather-show">PM10:{{ dataForm.pm10 }}mg/m³</p>
        </div>
      </el-col>
      <el-col :span="6">
        <div>
          <button class="btn" @click="pushLED"></button>
        </div>
      </el-col>
    </el-row>
  </div>  
</template>
 
<script>
export default {
  data () {
    return {
      dataForm: {
        city: '',
        temperature: 0,
        humidity: 0,
        pm25: 0,
        brightness: 0,
        pm10: 0,
        ech2o: 0,
        eco2: 0,
        tvoc: 0,
        windSpeed: 0
      }
    }
  },
  computed: {
    lightemitStateId () {
      return this.$store.state.led.lightemitId
    }
  },
  watch: {
    lightemitStateId (curVal, oldVal) {
      this.getSensorInfo(curVal)
    }
  },
  methods: {
    getSensorInfo (lightemitId) {
      this.$http({
        url: this.$http.adornUrl(`/pole/polesensor/getInfoByLightemitId/${lightemitId}`),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataForm.city = data.city.replace('市', '')
          this.dataForm.temperature = data.sensor.temperature
          this.dataForm.humidity = data.sensor.humidity
          this.dataForm.pm25 = data.sensor.pm25
          this.dataForm.brightness = data.sensor.brightness
          this.dataForm.pm10 = data.sensor.pm10
          this.dataForm.ech2o = data.sensor.ech2o
          this.dataForm.eco2 = data.sensor.eco2
          this.dataForm.tvoc = data.sensor.tvoc
          this.dataForm.windSpeed = data.sensor.windSpeed
        } else {
          this.dataForm.city = ''
          this.dataForm.temperature = 0
          this.dataForm.humidity = 0
          this.dataForm.pm25 = 0
          this.dataForm.brightness = 0
          this.dataForm.pm10 = 0
          this.dataForm.ech2o = 0
          this.dataForm.eco2 = 0
          this.dataForm.tvoc = 0
          this.dataForm.windSpeed = 0
          this.$message.error(data.msg)
        }
      })
    },
    // 推送天气数据
    pushLED () {
      var ids = [this.lightemitStateId]
      this.$http({
        url: this.$http.adornUrl(`/pole/polelightemit/pushLED`),
        method: 'post',
        data: this.$http.adornData({
          lightemitIds: ids
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        } else {
          this.$message.error(data.msg)
        }
      })
    }
  }
}
</script>
 
<style lang="scss" scoped>
.weather-bound {
  height: 100%;
  width: 60%;
}
.weather-show {
  font-size: 1.2em;
  line-height: 85%;
  color: #fff;
}
.btn {
  border-style: none;
  width: 100px;
  height: 35px;
  background: url(~@/assets/img/btn-config.png);
  background-repeat:no-repeat;
  border-style: none;
  background-size: 100%;
  color: #fff;
  font-size: 1.4em;
  font-weight: 550;
};
</style>