Uniapp实现气象监测页面

页面效果图展示:

实现代码:
 

<template>
  <view class="content">
    <view class="content-top">
      <text class="name">{{city}}</text>
    </view>
    <view class="background">
      <view class="content-middle">
        <text class="temp-left">{{dataArr.temperature}}°</text>
        <view class="temp-middle">
          <text class="temp-weather">{{dataArr.weather}}</text>
          <text class="temp-maxmin">{{dataArr.temperature-3}}/{{dataArr.temperature-(-3)}}℃</text>
        </view>
        <image :src="selecturl" mode="aspectFit" class="temp-icon"> </image>
      </view>
      <view class="content-bottom">
        <view class="info">
          <image class="info-icon" src="../../static/images/ic_qxjc_weater.png" mode="aspectFit"></image>
          <text class="info-data">{{dataArr.weather}}</text>
          <text class="info-explain">天气</text>
        </view>
        <view class="info">
          <image class="info-icon" src="../../static/images/ic_qxjc_leaf.png" mode="aspectFit"></image>
          <text class="info-data">{{dataArr.humidity}}</text>
          <text class="info-explain">空气湿度</text>
        </view>
        <view class="info">
          <image class="info-icon" src="../../static/images/ic_qxjc_temp.png" mode="aspectFit"></image>
          <text class="info-data">{{dataArr.temperature}}</text>
          <text class="info-explain">温度</text>
        </view>
        <view class="info">
          <image class="info-icon" src="../../static/images/ic_qxjc_windy.png" mode="aspectFit"></image>
          <text class="info-data">暂无数据</text>
          <text class="info-explain">风速</text>
        </view>
        <view class="info">
          <image class="info-icon" src="../../static/images/ic_qxjc_celsius.png" mode="aspectFit"></image>
          <text class="info-data">{{dataArr.temperature-(-3)}}</text>
          <text class="info-explain">当天最高温度</text>
        </view>
        <view class="info">
          <image class="info-icon" src="../../static/images/ic_qxjc_celsius.png" mode="aspectFit"></image>
          <text class="info-data">{{dataArr.temperature-3}}</text>
          <text class="info-explain">当天最低温度</text>
        </view>
        <view class="info">
          <image class="info-icon" src="../../static/images/ic_qxjc_wind.png" mode="aspectFit"></image>
          <text class="info-data">{{dataArr.winddirection}}</text>
          <text class="info-explain">风向</text>
        </view>
        <view class="info">
          <image class="info-icon" src="../../static/images/ic_qxjc_tornado.png" mode="aspectFit"></image>
          <text class="info-data">{{dataArr.windpower}}</text>
          <text class="info-explain">风力</text>
        </view>
      </view>
    </view>
  </view>

</template>

<script>
  export default {
    data() {
      return {
        city: "衡阳蒸湘区",
        //高德地图api的key
        gdkey: "dcc44b404271d76d8d8bf53febb5f94f",
        adcode: 0,
        dataArr: [],
        //根据天气情况选择图片,默认或无对应状态图片时显示logo
        selecturl: "../../static/logo.png",
        //预先储存相关天气的图片和名字
        imgarry: [{
            name: '阴',
            imgurl: '../../static/images/weather_ic_cloudy.png'
          },
          {
            name: '晴',
            imgurl: '../../static/images/weather_ic_sunny_day.png'
          },
          {
            name: '霾',
            imgurl: '../../static/images/weather_ic_fog.png'
          },
          {
            name: '雨',
            imgurl: '../../static/images/weather_ic_hail.png'
          }, {
            name: '雪',
            imgurl: '../../static/images/weather_ic_cloudy.png'
          }, {
            name: '扬沙',
            imgurl: '../../static/images/weather_ic_dust.png'
          }
        ]


      }
    },
    onLoad() {
      this.getadcode();
      console.log("loading.....")
    },
    methods: {
      //获取城市编码,高德地图查询使用的是编码
      async getadcode() {
        uni.request({
          url: "https://restapi.amap.com/v3/geocode/geo?parameters",
          data: {
            key: this.gdkey,
            address: this.city
          },
          success: res => {
            console.log(res.data.geocodes[0].adcode)
            this.adcode = res.data.geocodes[0].adcode
            this.getdata()

          },
          fail: err => {
            console.log(err)
          }
        })
      },
      //根据城市编码获取天气状态
      getdata() {
        uni.request({
          url: "https://restapi.amap.com/v3/weather/weatherInfo?parameters",
          data: {
            key: this.gdkey,
            city: this.adcode,
            extensions: 'base'
          },
          success: res => {
            console.log(res.data.lives[0])
            this.dataArr = res.data.lives[0]
            this.select()
          },
          fail: err => {
            console.log(err)
          }
        })
      },
      //依据天气状况对比选择对应图片url
      select() {
        this.imgarry.forEach((item, index) => {
          console.log("foreach" + this.dataArr.weather)
          if (item.name == this.dataArr.weather) this.selecturl = item.imgurl
        })
      }
    },


  }
</script>

<style lang="scss">
  .content {
    display: flex;
    flex-direction: column;

    .content-top {
      width: 100%;
      height: 70rpx;
      background-color: #68CF96;
      padding-left: 20rpx;
      padding-top: 15rpx;

      .name {
        font-size: 40rpx;
        color: #ffffff;
      }


    }

    .content-middle {
      display: flex;
      //background-color: #EEFFEE;
      width: 100%;
      height: 130rpx;
      padding-top: 20rpx;

      .temp-left {
        font-size: 60rpx;
        font-weight: bold;
        padding-left: 40rpx;
      }

      .temp-middle {
        display: flex;
        flex-direction: column;
        padding-left: 20rpx;
        font-size: 30rpx;
      }

      .temp-icon {
        padding-left: 300rpx;
        width: 130rpx;
        height: 130rpx;
      }
    }

    .content-bottom {
      display: flex;
      flex-wrap: wrap;
      width: 100%;
      height: 750rpx;
      justify-content: center;
      // background-color: #EEFFEE;



      .info {
        display: flex;
        flex-direction: column;
        width: 300rpx;
        height: 150rpx;
        background-color: #ffffff;
        box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 3px 0.3px;
        border-radius: 15rpx;
        padding-left: 20rpx;
        padding-top: 20rpx;
        margin-right: 15rpx;
        margin-bottom: 15rpx;

        .info-icon {
          width: 50rpx;
          height: 50rpx;
        }

        .info-data {
          font-size: 30rpx;
        }

        .info-explain {
          font-size: 30rpx;
          color: #d8d5d7;
        }
      }
    }

    .background::after {
      content: '';
      background: linear-gradient(to bottom, #86b972, #a0c68f, #accc9e, #b9d2ad, #c6d8bb);
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      opacity: 0.3;
      z-index: -1;

    }
  }
</style>

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
LabVIEW气象监测系统是一种基于LabVIEW编程平台开发的用于实时监测和分析气象数据的系统。该系统通过采集气象仪器提供的各种环境参数数据,如温度、湿度、气压、风速、风向等,实时显示和记录这些数据。 LabVIEW气象监测系统具有以下优点: 1. 可视化界面:通过LabVIEW的图形化界面,用户可以直观地看到实时的气象数据,并能够根据需要自定义显示方式和数据格式。 2. 数据采集和处理:系统能够实时采集多个气象仪器的数据,并将其进行处理和分析。用户可以根据需要编写各种数据处理算法,比如求平均值、标准差等,并实现数据的可视化展示和导出。 3. 实时监测和预警:系统能够实时监测气象数据,并设定临界值,一旦数据超出设定范围,系统将自动发出警报或进行预警。这对于天气预报和气象灾害监测具有重要意义。 4. 数据存储和管理:系统能够将采集到的气象数据存储在数据库中,并具备数据管理功能,包括数据查询、导出、分析等,方便用户进行各种数据处理和统计。 5. 可扩展性:LabVIEW平台具有很强的可扩展性,用户可以根据需要添加新的功能和模块,如加入新的仪器接口、数据处理算法等,以满足不同领域的气象监测需求。 总之,LabVIEW气象监测系统是一种功能强大、易用性高的气象数据监测与分析工具,能够帮助用户实时获取气象信息,并进行数据处理和分析。通过该系统,用户可以更好地了解和预测天气情况,为气象研究和气象灾害监测提供有力的支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宇宙的最后一粒尘埃

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值