極簡天氣之小夭天氣

1、利用週末兩天的時間,參考小天氣的風格,擼了一個天氣小程序,【小夭天氣】。
2、功能十分簡單,查看當前地區的天氣和搜索其他地區的天氣,增加了可以生成圖片分享出去。
3、上線後發現一個問題,就是極速提供的天氣接口對區級市沒有區分,例如 上海有寶山區,東北那也有一個。就沒有區分。這是一個bug
4、其他有什麼問題歡迎大家提意見和建議。

歡迎大家掃碼體驗

小夭天氣

詳情如下

首頁

首頁

首頁

空氣質量詳情

生活指數詳情

多日天氣詳情

部分代碼如下:

    <!-- 生成圖片 -->
    <view class="saveimage" wx:if="{{canvasPic}}">
      <view class="loading" wx:if="{{loading}}"><image src="../images/loading.gif" class="loading"></image></view>
      <canvasdrawer painting="{{painting}}" bind:getImage="eventGetImage"/>
      <view class="picbox">
          <view class="saveimageCont"><image src="{{shareImage}}" mode="widthFix"></image></view>
          <button class="keep" catchtap='eventSave'>{{shareText}}</button> 
          <text class="keep keep2" bindtap="closesaveimage">返回</text>
      </view>
    </view>
        <!--選擇地區-->
        <view class="selectArea {{getLotion === '' ? 'nomargin' :'' }}" wx:if="{{selectArea}}">
            <!-- 返回 -->
            <view class="selectAreaBox" :dss="getLotion">
                <view class="back" wx:if="{{getLotion === 'null' || getLotion !== ''}}">
                    <view class="backIcon" bindtap="back">
                        <image src="../images/back.png" class="img"></image>
                    </view>
                </view>
                <view class="input">
                    <input type="text" class="Jinput" placeholder="請輸入地區"  bindinput='writeArea' value="{{inpuText}}" ></input>
                    <image src="../images/serchicon.png" class="imgicon"></image>
                    <view class="clear" bindtap="clearInpuText"><image src="../images/clear.png" class="clearicon"></image></view>
                    <view class="sureBtn" bindtap="inputGoWeather"><image src="../images/surebtn.png" class="sureicon"></image></view>
                </view>
                <view class="tips">歷史記錄</view>
                <view class="hisCity">
                    <view class="hisCityBtn" data-city="{{list}}" wx:for="{{historyArea}}" wx:for-item="list" wx:key wx:if="historyArea.length > 0"  bindtap="goWeather">{{list}}</view>
                </view>
                <view class="tips">熱門城市</view>
                <view class="recCity">
                     <view class="recCityBtn getLocation" bindtap="selectLocation"><image class="getLocationimg" src="../images/hoticon.png"></image>定位</view>
                    <view class="recCityBtn" data-city="{{list}}" wx:for="{{hotArea}}" wx:for-item="list" wx:key bindtap="goWeather">{{list}}</view>
                </view>
            </view>
        </view> 
 getWeatherData:function(city){
    var _this = this,
          thisdata = this.data,
          historyArea = thisdata.historyArea;
    wx.request({
      url: _this.data.api,
      data: {
        "city": city
      },
      method: 'get',
      header: {
        'Content-Type': 'application/json'
      },
      dataType: 'jsonp',
      jsonp: 'callback',
      success: function (res) {
        var res = res.data
        res = JSON.parse(res)
        if (res.status === "0") {
          var data = res['result']
          data.img = '../images/condicon/'+data.img+'b.png'
          _this.setData({
            getSuccess: 'true',
            getLotion: city,
            realdata: data,
            clock: data.updatetime,
            aqi: data['aqi'],
            aqiMsg: data.aqi.aqiinfo['affect'] + ',' + data.aqi.aqiinfo['measure'],
            life: data['index'],
            daily: data['daily'],
            hourly: data['hourly'],
            airPredict: '兩小時之後天氣' + data.hourly[2].weather + ' ,溫度 ' + data.hourly[2].temp + '°',
            quality: data['aqi'].quality
          })
          // 搜索返回成功後 清除 輸入框,將搜索結果放入歷史記錄
          // _this.$refs.clearText.value = ''
          if (thisdata.inpuText !== '') {
            if (thisdata.historyArea.indexOf(thisdata.inpuText) === -1) {
              historyArea.push(thisdata.inpuText)
              _this.setData({
                historyArea: historyArea
              })
            }
          }
          _this.back()
        } else {
          wx.showModal({
            title: '提示',
            content: res.msg,
            success: function (res) {
              if (res.confirm) {
                _this.setData({
                  msgText: '位置獲取失敗!!!請手動選擇',
                  loadingBtn: true
                })
              } else if (res.cancel) {
                console.log('用戶點擊取消')
              }
            }
          })
        }
      },
// 定位獲取
  selectLocation: function () {
    let _this = this
    _this.getlocation();
  },
  getlocation: function () {
    var _this = this
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        console.log(res)
        var latitude = res.latitude
        var longitude = res.longitude
        var speed = res.speed
        var accuracy = res.accuracy
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: latitude,
            longitude: longitude
          },
          success: function (res) { 
            console.log(res)
            _this.setData({
              getLotion: res.result.address_component.district ? res.result.address_component.district : res.result.address_component.city
            })
            wx.setNavigationBarTitle({
              title: res.result.address_component.district
            })
            _this.getWeatherData(res.result.address_component.district)
          }
        })
      },
      fail:function(res){
        _this.setData({
          msgText: '位置獲取失敗!!!請手動選擇',
          loadingBtn:true
        })
      }
    })
  },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章