//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();
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
定位天气.zip小程序例子源码打包下载适合研究学习技术
共12个文件
js:4个
wxss:3个
json:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 97 浏览量
2022-03-13
12:49:36
上传
评论
收藏 7KB ZIP 举报
温馨提示
定位天气.zip小程序例子源码打包下载适合研究学习技术定位天气.zip小程序例子源码打包下载适合研究学习技术 1.适合学习做毕业设计参考模板。 2.适合程序员学习开发小程序研究用 3.适合小公司换皮做新项目参考使用用
资源推荐
资源详情
资源评论
收起资源包目录
定位天气.zip (12个子文件)
定位天气
xiaotianqi-master
app.json 279B
pages
index
index.js 3KB
index.json 2B
index.wxss 458B
index.wxml 1KB
logs
logs.js 266B
logs.json 54B
logs.wxml 194B
logs.wxss 106B
app.wxss 194B
app.js 719B
utils
util.js 460B
共 12 条
- 1
资源评论
yxkfw
- 粉丝: 76
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功