|
|
@@ -1,13 +1,20 @@
|
|
|
<template>
|
|
|
<div class="header">
|
|
|
<div class="header_box">
|
|
|
+ <!-- 左边时间区域 -->
|
|
|
<div class="box_time">
|
|
|
<span class="date">日期:{{ currentDate }}</span>
|
|
|
<span>时间:{{ currentTime }}</span>
|
|
|
</div>
|
|
|
+ <!-- 中间标题区域 -->
|
|
|
<div class="box_title">万载三中领导驾驶舱</div>
|
|
|
+ <!-- 右边天气信息区域 -->
|
|
|
<div class="box_weather">
|
|
|
- <span>天气:晴 4℃~20℃</span>
|
|
|
+ <span
|
|
|
+ >天气:{{ weatherInfo.dayweather }} {{
|
|
|
+ weatherInfo.nighttemp
|
|
|
+ }}℃~{{ weatherInfo.daytemp }}℃</span
|
|
|
+ >
|
|
|
<span class="air">空气质量:优</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -17,6 +24,8 @@
|
|
|
<script setup lang="ts">
|
|
|
import { ref, onMounted, onUnmounted } from "vue";
|
|
|
import { getCurrentTime } from "@/utils/getTime";
|
|
|
+// @ts-ignore
|
|
|
+import { getWeatherInfo } from "@/api/weather/index";
|
|
|
|
|
|
// 当前日期
|
|
|
const currentDate = ref();
|
|
|
@@ -24,8 +33,20 @@ const currentDate = ref();
|
|
|
const currentTime = ref();
|
|
|
// 定时器标识
|
|
|
const timer = ref();
|
|
|
+// 天气信息
|
|
|
+const weatherInfo = ref({
|
|
|
+ // 天气情况
|
|
|
+ dayweather: "",
|
|
|
+ // 白天温度
|
|
|
+ daytemp: "",
|
|
|
+ // 夜间温度
|
|
|
+ nighttemp: "",
|
|
|
+});
|
|
|
|
|
|
onMounted(() => {
|
|
|
+ // 获取天气信息
|
|
|
+ getWeather();
|
|
|
+ // 获取当前时间
|
|
|
getTime();
|
|
|
timer.value = setInterval(() => {
|
|
|
getTime();
|
|
|
@@ -33,9 +54,15 @@ onMounted(() => {
|
|
|
});
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
+ // 页面卸载时清除定时器
|
|
|
clearInterval(timer.value);
|
|
|
});
|
|
|
|
|
|
+// 获取天气信息
|
|
|
+const getWeather = async () => {
|
|
|
+ weatherInfo.value = await getWeatherInfo();
|
|
|
+};
|
|
|
+
|
|
|
// 获取当前日期时间
|
|
|
const getTime = () => {
|
|
|
currentDate.value = getCurrentTime().currentDate;
|
|
|
@@ -87,7 +114,7 @@ const getTime = () => {
|
|
|
margin-top: 17px;
|
|
|
|
|
|
.air {
|
|
|
- margin: 0 75px 0 85px;
|
|
|
+ margin: 0 75px;
|
|
|
}
|
|
|
}
|
|
|
}
|