forked from drone/command-center-dashboard

罗广辉
2025-04-21 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7
src/components/CommonWeather.vue
@@ -6,8 +6,8 @@
         <img src="@/assets/images/home/homeLeft/tq.png" alt="" />
         <span class="tq">{{ weather }}</span>
         <span class="tq">风速:{{ windVelocity }} </span>
         <span v-if="flylevel >= 5" :class="[isFly === '建议飞行' ? 'qk' : isFly === '禁止飞行' ? 'redqk' : 'yellowqk']">{{
            isFly
         <span v-if="flightAdvice" :class="[flightAdvice === '适合飞行' ? 'qk' : flightAdvice === '禁止飞行' ? 'redqk' : 'yellowqk']">{{
               flightAdvice
         }}</span>
      </div>
   </div>
@@ -16,6 +16,13 @@
<script setup>
import dayjs from 'dayjs'
import { getDroneSuggest } from '@/api/home/common'
import { useStore } from 'vuex'
import { ElMessage } from 'element-plus'
const store = useStore()
const flySuggest = computed(() => store.state.home.flySuggest)
const selectedAreaCode = computed(() => store.state.user.selectedAreaCode)
const useAreaCode = computed(() => store.state.user.userInfo.detail.areaCode)
const time = ref('')
const updateTime = () => {
@@ -24,33 +31,31 @@
// 天气
const weather = ref('')
// 是否适合飞行
const isFly = ref('')
// 风速
const windVelocity = ref('')
// 区县级
const flylevel = ref('')
const flightAdvice = computed(() => flySuggest.value?.flightAdvice)
// 获取天气建议
const getWeatherSuggest = () => {
   getDroneSuggest().then(res => {
   getDroneSuggest({ areaCode: selectedAreaCode.value || useAreaCode.value }).then(res => {
      if (res.data.code !== 0) return
      weather.value = res.data.data.weather
      isFly.value = res.data.data.flightAdvice
      windVelocity.value = res.data.data.windPower
      flylevel.value = res.data.data.adcode.replace(/0+$/, "")
   })
}
let intervalTime
onMounted(() => {
   getWeatherSuggest()
   updateTime() // 立即执行一次
   time.value = setInterval(updateTime, 1000)
   intervalTime = setInterval(updateTime, 1000)
})
onUnmounted(() => {
   if (time.value) {
      clearInterval(time.value)
      time.value = null
   if (intervalTime) {
      clearInterval(intervalTime)
      intervalTime = null
   }
})
</script>
@@ -63,15 +68,17 @@
   height: 36px;
   line-height: 36px;
   display: flex;
   justify-content: space-between;
   align-items: center;
   color: #e7f5ff;
   .line {
      border: 1px solid #ffffff;
      height: 10px;
      opacity: 0.5;
      margin: 0 18px;
   }
   .weather {
      display: flex;
      align-items: center;
      img {
         width: 20px;
         height: 20px;
@@ -93,4 +100,4 @@
      }
   }
}
</style>
</style>