Page({
data:{
AK: 'hWtYHdhw2fIwi9PWsWX09IVmGtLVp2UG',
city: '',
temp: '',
todayDayImg: '',
todayNightImg: '',
weather: '',
todayDate: '',
todayTime: ''
},
// 监听页面加载
onLoad: function () {
this.loadInfo();
this.getTime();
},
// 监听页面初次渲染完成
onReady: function () {
},
// 监听页面显示
onShow: function () {
},
// 监听页面隐藏
onHide: function () {
},
// 监听页面卸载
onUpload: function () {
},
// 监听用户下拉动作
onPullDownRefresh: function () {
this.getTime();
},
// 监听页面上拉触底
onReachBottom: function () {
},
loadInfo: function () {
var that = this;
wx.getLocation({
type: 'gcj02',
success: function(res) {
var latitude = res.latitude;
var longitude = res.longitude;
var 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) {
var that = this;
var url = 'https://api.map.baidu.com/geocoder/v2/?location=' + latitude + ',' + longitude + '&output=json&ak=' + AK;
wx.request({
url: url,
header: {
'content-type': 'application/json'
},
success: function(res) {
console.log(res);
var city = res.data.result.addressComponent.city;
that.setData({city :city});
console.log(that.data.city);
callback && callback(city, AK);
}
})
},
loadWeather: function (city, AK) {
var that = this;
var url = 'https://api.map.baidu.com/telematics/v3/weather?location=' + city + '&output=json&ak=' + AK;
console.log(url);
wx.request({
url: url,
header: {
'content-type': 'application/json'
},
success: function(res) {
var desNum = that.random(5);
console.log(res);
var future = res.data.results[0].weather_data.filter(function(ele, index) {
return index > 0;
});
var 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) {
var min = min || 0;
return Math.floor(Math.random() * (max - min +1) + min);
},
getTime: function () {
var date = new Date();
var minute = date.getMinutes() >=10 ? date.getMinutes() : ('0' + date.getMinutes());
var hour = date.getHours() >=10 ? date.getHours() : ('0' + date.getHours());
var now = date.getDate() >= 10 ? date.getDate() : ('0' + date.getDate());
var todayDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + now;
var todayTime = hour + ':' + minute;
this.setData({
todayDate: todayDate,
todayTime: todayTime
})
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
微信小程序——天气预报(截图+源码).zip
共47个文件
png:15个
wxml:8个
js:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 86 浏览量
2022-04-18
22:34:53
上传
评论
收藏 939KB ZIP 举报
温馨提示
微信小程序——天气预报(截图+源码).zip 微信小程序——天气预报(截图+源码).zip 微信小程序——天气预报(截图+源码).zip 微信小程序——天气预报(截图+源码).zip 微信小程序——天气预报(截图+源码).zip 微信小程序——天气预报(截图+源码).zip 微信小程序——天气预报(截图+源码).zip 微信小程序——天气预报(截图+源码).zip 微信小程序——天气预报(截图+源码).zip
资源推荐
资源详情
资源评论
收起资源包目录
微信小程序——天气预报(截图+源码).zip (47个子文件)
源码
Weather
weather2
jsconfig.json 55B
app.json 986B
pages
life
life.js 2KB
life.wxss 840B
life.wxml 335B
assets
img
future-s.png 1KB
medicine.png 3KB
cloth.png 3KB
car.png 8KB
home.png 678B
uv.png 4KB
future.png 945B
bg.jpg 12KB
life.png 2KB
life-s.png 2KB
home-s.png 720B
travel.png 5KB
bg2.jpg 45KB
bg1.jpg 80KB
sport.png 7KB
main
main.js 4KB
main.wxml 693B
main.wxss 2KB
future
future.wxss 845B
future.js 2KB
future.wxml 332B
template
futuretpl.wxml 505B
lifetpl.wxml 326B
itemtpl.wxml 421B
typings
weapp.d.ts 42KB
app.wxss 194B
app.js 719B
utils
util.js 460B
wether1
jsconfig.json 55B
app.json 216B
pages
assets
img
bg.jpg 12KB
main
main.js 3KB
main.wxml 574B
main.wxss 1KB
template
itemtpl.wxml 421B
typings
weapp.d.ts 42KB
app.wxss 194B
app.js 719B
utils
util.js 460B
截图
1.png 233KB
2.png 266KB
3.png 222KB
共 47 条
- 1
资源评论
- 2301_773425432023-04-16资源使用价值高,内容详实,给了我很多新想法,感谢大佬分享~
易小侠
- 粉丝: 6449
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功