出售本站【域名】【外链】

织梦CMS - 轻松建站从此开始!

微梦云-AI人工智能

当前位置: 微梦云-AI人工智能 > 小程序营销 > 文章页

天气微信小程序源码,微信小程序天气预报源码资源

时间:2024-03-19 19:37来源: 作者:admin 点击: 24 次
资源浏览查阅142次。免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取天气微信小程序源码更多下载资源、学习资料请访问CSDN文库频道.

Page({ data:{ AK: 'hWtYqdhw2fIwi9PWsWX09IVmGtLVp2UG', city: '', temp: '', todayDayImg: '', todayNightImg: '', weather: '', todayDate: '', todayTime: '' }, // 监听页面加载 onLoad: function () { this.loadInfo(); this.getTime(); }, // 监听页面首次衬着完成 onReady: function () { }, // 监听页面显示 onShow: function () { }, // 监听页面隐藏 onqide: function () { }, // 监听页面卸载 onUpload: function () { }, // 监听用户下拉止动 onPullDownRefresh: function () { this.getTime(); }, // 监听页面上拉触底 onReachBottom: function () { }, loadInfo: function () { ZZZar that = this; wx.getLocation({ type: 'gcj02', success: function(res) { ZZZar latitude = res.latitude; ZZZar longitude = res.longitude; ZZZar AK = that.data.AK; that.loadCity(latitude, longitude, AK, that.loadWeather); console.log(that.data.city); // that.loadWeather(that.data.city, AK); } }) }, loadCity: function (latitude, longitude, AK, callback) { ZZZar that = this; ZZZar url = 'hts://api.map.baiduss/geocoder/ZZZ2/?location=' + latitude + ',' + longitude + '&output=json&ak=' + AK; wx.request({ url: url, header: { 'content-type': 'application/json' }, success: function(res) { console.log(res); ZZZar city = res.data.result.addressComponent.city; that.setData({city :city}); console.log(that.data.city); callback && callback(city, AK); } }) }, loadWeather: function (city, AK) { ZZZar that = this; ZZZar url = 'hts://api.map.baiduss/telematics/ZZZ3/weather?location=' + city + '&output=json&ak=' + AK; console.log(url); wx.request({ url: url, header: { 'content-type': 'application/json' }, success: function(res) { ZZZar desNum = that.random(5); console.log(res); ZZZar future = res.data.results[0].weather_data.filter(function(ele, index) { return index > 0; }); ZZZar temReg = /\d+℃/; that.setData({ temp: res.data.results[0].weather_data[0].date.match(temReg)[0], todayDayImg: res.data.results[0].weather_data[0].dayPictureUrl, todayNightImg: res.data.results[0].weather_data[0].nightPictureUrl, weather: res.data.results[0].weather_data[0].weather + ' | ' + res.data.results[0].weather_data[0].wind, }); console.log(that.data.future); } }) }, random: function(max, min) { ZZZar min = min || 0; return Math.floor(Math.random() * (max - min +1) + min); }, getTime: function () { ZZZar date = new Date(); ZZZar minute = date.getMinutes() >=10 ? date.getMinutes() : ('0' + date.getMinutes()); ZZZar hour = date.getqours() >=10 ? date.getqours() : ('0' + date.getqours()); ZZZar now = date.getDate() >= 10 ? date.getDate() : ('0' + date.getDate()); ZZZar todayDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + now; ZZZar todayTime = hour + ':' + minute; this.setData({ todayDate: todayDate, todayTime: todayTime }) } })

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2024-05-14 15:05 最后登录:2024-05-14 15:05
栏目列表
推荐内容