<template> <div class="container"> <div class="title">气象指标</div> <div class="content"> <div class="block" v-for="(value,key,index) in data" :key="index"> <item :data="value"/> </div> </div> </div> </template> <script> import Item from "./components/item"; import { getTyphoonOcean, getTyphoonList,getShelterPosition} from "@/api/typhoon" import { dateToString } from '@/utils/formatDate' export default { name: 'Weather', components: {Item}, data() { return { data:[ {name:'风速风向',value:'***°',color:'#00f5ff'}, {name:'海温',value:'',color:'#50C55C'}, {name:'气压',value:'',color:'#50C55C'}, {name:'海拔',value:'',color:'#50C55C'}, {name:'风浪方向/高度',value:'',color:'#00f5ff'}, {name:'涌浪方向/高度',value:'',color:'#00f5ff'}, {name:'台风预报',value:'********************************************',color:'#50C55C'}, ] } }, mounted() { getShelterPosition().then(res => { if (res.code === 200) { let params = { lng: res.data.lng, lat: res.data.lat, date: dateToString(new Date(), 'y-m-d'), days: 0, hour: new Date().getHours() } getTyphoonOcean(params).then(res => { if (res.code === 200) { this.data[0].value = res.data.windSpeed + 'm/s '+res.data.windDir + '°' this.data[1].value = res.data.temperature + '℃ ' this.data[2].value = res.data.pressure + 'hPa ' this.data[3].value = res.data.altitude + '米 ' this.data[4].value = res.data.waveDir + '° '+ res.data.waveHeight + '米 ' this.data[5].value = res.data.swellDir + '° '+ res.data.swellHeight + '米 ' } }) } }) getTyphoonList().then(res => { if (res.code === 200) { if(res.data.length===0) {this.data[6].value = '暂无台风'} else { this.data[6].value = '' for(let i=0;i<res.data.length;i++){ this.data[6].value += (res.data[i].name+'台风('+res.data[i].lng+','+res.data[i].lat+'),'+ res.data[i].power +'级风 \n') } } } }) }, methods: { } } </script> <style rel="stylesheet/scss" lang="scss" scoped> .container{ background: url("../../assets/images/bg.png") no-repeat; -webkit-background-size: 100% 100%; background-size: 100% 100%; .title{ font-size: 17px; color: #00f5ff; margin: 10px 0px 10px 20px; } .content{ padding: 0px 20px; display: flex; flex-direction: column; flex: 1; .block{ width: 100%; height: 30px; } } } </style>