forked from drone/command-center-dashboard

张含笑
2025-04-10 3124dced3b901426803137204ddbd58016b60760
feat: 添加风速,修改建议飞行颜色
1 files modified
60 ■■■■■ changed files
src/components/CommonWeather.vue 60 ●●●●● patch | view | raw | blame | history
src/components/CommonWeather.vue
@@ -5,50 +5,58 @@
    <div class="weather">
      <img src="@/assets/images/home/homeLeft/tq.png" alt="" />
      <span class="tq">{{ weather }}</span>
      <span class="qk">{{ isFly }}</span>
            <span class="tq">风速:{{ windVelocity }} </span>
            <span v-if="flylevel >6" :class="[isFly ==='建议飞行' ? 'qk' :isFly ==='禁止飞行' ? 'redqk' :'yellowqk']">{{ isFly }}</span>
    </div>
  </div>
</template>
<script setup>
import dayjs from 'dayjs';
import { getDroneSuggest } from '@/api/home/common';
import dayjs from 'dayjs'
import { getDroneSuggest } from '@/api/home/common'
const time = ref('');
const time = ref('')
const updateTime = () => {
    time.value = dayjs().format('YYYY.MM.DD HH:mm:ss');
};
    time.value = dayjs().format('YYYY.MM.DD HH:mm:ss')
}
// 天气
const weather = ref('');
const weather = ref('')
// 是否适合飞行
const isFly = ref('');
const isFly = ref('')
// 风速
const windVelocity = ref('')
// 区县级
const flylevel = ref('')
// 获取天气建议
const getWeatherSuggest = () => {
  getDroneSuggest().then(res => {
    if (res.data.code !== 0) return;
    weather.value = res.data.data.weather;
    isFly.value = res.data.data.flightAdvice;
  });
};
        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.length
        console.log('天气res', res.data.data, flylevel.value)
    })
}
onMounted(() => {
    getWeatherSuggest();
    updateTime(); // 立即执行一次
    time.value = setInterval(updateTime, 1000);
});
    getWeatherSuggest()
    updateTime() // 立即执行一次
    time.value = setInterval(updateTime, 1000)
})
onUnmounted(() => {
    if (time.value) {
        clearInterval(time.value);
        time.value = null;
        clearInterval(time.value)
        time.value = null
    }
});
})
</script>
<style scoped lang="scss">
.time-weather {
  margin-left: 45px;
  width: 310px;
    width: 350px;
  font-size: 14px;
  height: 36px;
  line-height: 36px;
@@ -73,6 +81,14 @@
      margin-left: 5px;
      color: #04f043;
    }
        .yellowqk {
            margin-left: 5px;
            color: yellow;
        }
        .redqk {
            margin-left: 5px;
            color: red;
        }
  }
}
</style>