欢迎光临,了解微信小程序开发,就上易用通!

当前位置 : 易用通 > 小程序模板
小天气;定位地点,更新实时天气小天气;定位地点,更新实时天气
立即下载

小天气;定位地点,更新实时天气

模板分类 : 小程序模板 模板编号 : Y1021 源码文件 : 完全开源 下载权限 : VIP会员
模板大小 :  模板指数 :  更新时间 : 2018-03-21 09:42 模板等级 : ☆☆☆☆☆

模板截图:

小天气;定位地点,更新实时天气(图1)  代码示例:
[AppleScript] 纯文本查看 复制代码
?
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    location: {
      id: "WS10730EM8EV",
      name: "下拉刷新",
      country: "CN",
      path: "深圳,深圳,广东,中国",
      timezone: "Asia/Shanghai",
      timezone_offset: "+08:00"
    },
    now: {
      nowPic: "http://omh7cqphx.bkt.clouddn.com/",
      text: "...",
      code: "0",
      temperature: "26"
    },
    last_update: "",
    
    currentQueryObj: {
      key: "bixmpxjottltdf7l",
      location: "shenzhen",
      language: "zh-Hans",
      unit: "c"
    },
    api: {
      nowUrl: "https://api.thinkpage.cn/v3/weather/now.json",
      dailyUrl: "https://api.thinkpage.cn/v3/weather/daily.json",
      suggestion: "https://api.thinkpage.cn/v3/life/suggestion.json"
    }
    
  },
 
  //发送请求数据
  sendRequest: function(url, queryObj, callback) {
    wx.request({
      url: url,
      data: queryObj,
      method: 'GET',
      success: function(res) {
        callback(res);
      },
      fail: function(e) {
        console.log("******error******: ", e);
      },
      complete: function(e) {
        console.log("******请求完成****** ", e);
      }
    })
  },
  //发送请求数据
 
  //下拉刷新
  refreashNow: function(e) {
    var that = this;
    console.log(that.data.location);
    //更新实况天气
    this.sendRequest(this.data.api.nowUrl, this.data.currentQueryObj, function(res) {
      var result = res.data.results[0];
      that.refreashData(result); //下拉更新动作后的数据刷新
    });
    //更新实况天气   
  },
  //下拉刷新
 
  //更新数据
  refreashData: function(result) {
    // 更新实况天气数据
    var result = result;
    result.last_update = result.last_update.slice(-14, -9);
    result.now.nowPic = "http://omh7cqphx.bkt.clouddn.com/";
    // 更新实况天气数据
 
    //刷新数据
    this.setData({
      location: result.location,
      now: result.now,
      last_update: result.last_update
    });
    //刷新数据
  },
  //更新数据
 
  //改变地点
  changeLoc: function(e) {
    var that = this;
    wx.chooseLocation({
      success: function(res){
        console.log(JSON.stringify(res)); //{"name":"天安门广场","address":"北京市东城区广场东侧路","latitude":39.90323,"longitude":116.39772,"errMsg":"chooseLocation:ok"}
        var currentQueryObj = {
          key: "bixmpxjottltdf7l",
          location: res.latitude + ":" + res.longitude,
          language: "zh-Hans",
          unit: "c"
        };
        that.setData({
          currentQueryObj: currentQueryObj
        });
        that.refreashNow();
      }
    })
  },
  //改变地点
 
  //定位地点
  autoLoc: function(e) {
    var that = this;
    wx.getLocation({
      type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
      success: function(res){
        var currentQueryObj = {
          key: "bixmpxjottltdf7l",
          location: res.latitude + ":" + res.longitude,
          language: "zh-Hans",
          unit: "c"
        };
        that.setData({
          currentQueryObj: currentQueryObj
        });
        that.refreashNow();
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  //定位地点
 
  onShow: function(e) {
    
  },
 
  logmsg: function(res) {
    console.log(res);
  },
 
  onPullDownRefresh: function(){
    this.refreashNow();
    wx.stopPullDownRefresh();
  }
  
})

加入收藏
立即下载
分享到微信朋友圈
X

免责声明:

1. 本站所有素材(未指定商用),仅限学习交流,请勿用于商业用途。
2. 本站所有小程序模板Demo和图片均来自用户分享上传和网络收集,模板和图片版权归原作者及原出处所有。
3. 未经合法授权,会员不得以任何形式发布、传播、复制、转售该素材。