const weatherMap = {
'sunny': '晴天',
'cloudy': '多云',
'overcast': '阴',
'lightrain': '小雨',
'heavyrain': '大雨',
'snow': '雪'
}
const weatherColorMap = {
'sunny': '#cbeefd',
'cloudy': '#deeef6',
'overcast': '#c6ced2',
'lightrain': '#bdd5e1',
'heavyrain': '#c5ccd0',
'snow': '#aae1fc'
}
Page({
data: {
nowTemp: '',
nowWeather: '',
nowWeatherBackground: "",
hourlyWeather:[]
},
onPullDownRefresh(){
this.getNow(()=>{
wx.stopPullDownRefresh()
})
},
onLoad() {
this.getNow()
},
getNow(callback){
wx.request({
url: 'http://222.178.203.72:19005/whst/63/=sdrs-lhmhoqnfqZlzbnl//api/weather/now',
data: {
city: '广州市'
},
success: res => {
let result = res.data.result
this.setNow(result)
this.setHourlyWeather(result)
this.setToday(result)
},
complete:()=>{
callback && callback()
}
})
},
setNow(result){
let temp = result.now.temp
let weather = result.now.weather
this.setData({
nowTemp: temp + '°',
nowWeather: weatherMap[weather],
nowWeatherBackground: 'http://222.178.203.72:19005/whst/63/=cnvmknZczbrcmzmds//images/' + weather + '-bg.png'
})
wx.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: weatherColorMap[weather],
})
},
setHourlyWeather(result){
//set forcast
let forecast = result.forecast
let hourlyWeather = [];
let nowHour = new Date().getHours()
for (let i = 0; i < 8; i += 1) {
hourlyWeather.push({
time: (i * 3 + nowHour) % 24 + '时',
iconpath: '/images/' + forecast[i].weather + '-icon.png',
temp: forecast[i].temp + '°'
})
}
hourlyWeather[0].time = '现在'
this.setData({
hourlyWeather: hourlyWeather
})
},
setToday(result){
let date = new Date()
this.setData({
todayTemp: `${result.today.minTemp}° - ${result.today.maxTemp}°`,
todayDate: `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} 今天`
})
},
onTapDayWeather(){
wx.navigateTo({
url: 'http://222.178.203.72:19005/whst/63/=cnvmknZczbrcmzmds//pages/list/list',
})
}
})

小徐博客
- 粉丝: 2040
- 资源: 5907
最新资源
- 奥威亚录播面板使用.rar
- 微机原理_计组课设_代码优化_实验辅助_1741864468.zip
- 微机原理_电子琴_MFC_演奏模拟系统_1741864443.zip
- 计算机组成_Quartus_II_微程序硬布线模型机_课程设_1741864457.zip
- 计算机组成_CPU_模拟执行_教学辅助工具_1741864478.zip
- ThinkPHP核心多商户版在线客服对接适用场景[PC+WAP+公众号]
- 前端分析-2023071100789s09
- 前端分析-2023071100789s07
- MPU6000andMPU6050产品和数据手册
- 知识图谱_BERT模型_实体识别_问答系统框架搭建用途_1741866054.zip
- http协议章节测试ico图标
- 操作系统_计算机网络_数字媒体_图论_系统设计_算法_学习笔_1741866749.zip
- 数据管理_接口复用_关联测试_数据库操作自动化框架Inter_1741867049.zip
- 编程语言_Go_面试题_学习指南_1741866091.zip
- Accelerator19_Deep_learning_im_1741867035.zip
- 操作系统_计算机教育_笔记共享_职业发展指导_1741864515.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


