|
@@ -27,10 +27,10 @@
|
|
|
<!-- Right: Weather -->
|
|
<!-- Right: Weather -->
|
|
|
<div class="nav-right">
|
|
<div class="nav-right">
|
|
|
<div class="nav-weather">
|
|
<div class="nav-weather">
|
|
|
- <span class="icon">⛅</span>
|
|
|
|
|
|
|
+ <!--<span class="icon">⛅</span>-->
|
|
|
<div>
|
|
<div>
|
|
|
- <div class="weather-location">北京 · 晴转多云</div>
|
|
|
|
|
- <div class="weather-detail">12°C / AQI 68</div>
|
|
|
|
|
|
|
+ <div class="weather-location">{{weather}}</div>
|
|
|
|
|
+ <div class="weather-detail">{{weatherA}}{{weatherB}}</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -38,18 +38,23 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
+ import { getWeather } from '@/api/screen'
|
|
|
export default {
|
|
export default {
|
|
|
name: 'ScreenHeader',
|
|
name: 'ScreenHeader',
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
currentTime: '',
|
|
currentTime: '',
|
|
|
currentDate: '',
|
|
currentDate: '',
|
|
|
- timer: null
|
|
|
|
|
|
|
+ timer: null,
|
|
|
|
|
+ weather:'',
|
|
|
|
|
+ weatherA:'',
|
|
|
|
|
+ weatherB:'',
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
mounted() {
|
|
mounted() {
|
|
|
this.updateTime()
|
|
this.updateTime()
|
|
|
this.timer = setInterval(this.updateTime, 1000)
|
|
this.timer = setInterval(this.updateTime, 1000)
|
|
|
|
|
+ this.fetchWeather()
|
|
|
},
|
|
},
|
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
|
if (this.timer) {
|
|
if (this.timer) {
|
|
@@ -70,6 +75,17 @@ export default {
|
|
|
const d = now.getDate()
|
|
const d = now.getDate()
|
|
|
const weekDays = ['日', '一', '二', '三', '四', '五', '六']
|
|
const weekDays = ['日', '一', '二', '三', '四', '五', '六']
|
|
|
this.currentDate = `${y}年${mon}月${d}日 星期${weekDays[now.getDay()]}`
|
|
this.currentDate = `${y}年${mon}月${d}日 星期${weekDays[now.getDay()]}`
|
|
|
|
|
+ },
|
|
|
|
|
+ async fetchWeather() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await getWeather()
|
|
|
|
|
+ const d = res.data
|
|
|
|
|
+ this.weather = ` 北京 · ${d.weekDay} `;
|
|
|
|
|
+ this.weatherA = ` ${d.weatherDesc} `;
|
|
|
|
|
+ this.weatherB = ` ${d.temperature}°C`;
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ this.weather = ''
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|