forked from drone/command-center-dashboard

chenyao
2025-04-09 cc1aacf766bc902001f460fdfce20a9ec2ea097d
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
<template>
  <div class="time-weather">
    <div class="time">{{ time }}</div>
    <div class="line"></div>
    <div class="weather">
      <img src="@/assets/images/home/homeLeft/tq.png" alt="" />
      <span class="tq">{{ weather }}</span>
      <span class="qk">{{ isFly }}</span>
    </div>
  </div>
</template>
 
<script setup>
import dayjs from 'dayjs';
import { getDroneSuggest } from '@/api/home/common';
 
 
const time = ref('');
const updateTime = () => {
    time.value = dayjs().format('YYYY.MM.DD HH:mm:ss');
};
 
// 天气
const weather = ref('');
// 是否适合飞行
const isFly = ref('');
// 获取天气建议
const getWeatherSuggest = () => {
  getDroneSuggest().then(res => {
    if (res.data.code !== 0) return;
    weather.value = res.data.data.weather;
    isFly.value = res.data.data.flightAdvice;
  });
};
onMounted(() => {
    getWeatherSuggest();
    updateTime(); // 立即执行一次
    time.value = setInterval(updateTime, 1000);
});
onUnmounted(() => {
    if (time.value) {
        clearInterval(time.value);
        time.value = null;
    }
});
</script>
 
<style scoped lang="scss">
.time-weather {
  margin-left: 45px;
  width: 310px;
  font-size: 14px;
  height: 36px;
  line-height: 36px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .line {
    border: 1px solid #ffffff;
    height: 10px;
    opacity: 0.5;
  }
  .weather {
    img {
      width: 20px;
      height: 20px;
    }
    .tq {
      margin: 0 5px;
      color: #e7f5ff;
    }
    .qk {
      margin-left: 5px;
      color: #04f043;
    }
  }
}
</style>