Skip to content

Commit

Permalink
增加定位,loading样式
Browse files Browse the repository at this point in the history
  • Loading branch information
hingsir committed Sep 26, 2016
1 parent a48ae18 commit d608123
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 29 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//app.js
var util = require('./utils/util.js')
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)

},
getUserInfo:function(cb){
var that = this;
Expand Down
27 changes: 26 additions & 1 deletion app.wxss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
display: table;
clear:both;
}
.hide{
display: none !important;
}
.container {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -54,4 +57,26 @@
}
.person{
margin-right: 5px;
}
}
.page-loading{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
font-size: 14px;
color: #666;
}
.page-loading .loading-text{
display: inline-block;
vertical-align: middle;
}
.weui-loading {
width: 20px;
height: 20px;
display: inline-block;
vertical-align: middle;
-webkit-animation: weuiLoading 1s steps(12, end) infinite;
animation: weuiLoading 1s steps(12, end) infinite;
background: transparent url(data:image/svg+xml;base64,PHN2ZyBjbGFzcz0iciIgd2lkdGg9JzEyMHB4JyBoZWlnaHQ9JzEyMHB4JyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICAgIDxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJub25lIiBjbGFzcz0iYmsiPjwvcmVjdD4KICAgIDxyZWN0IHg9JzQ2LjUnIHk9JzQwJyB3aWR0aD0nNycgaGVpZ2h0PScyMCcgcng9JzUnIHJ5PSc1JyBmaWxsPScjRTlFOUU5JwogICAgICAgICAgdHJhbnNmb3JtPSdyb3RhdGUoMCA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HRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNFMkUyRTInCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgzMzAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0Pgo8L3N2Zz4=) no-repeat;
background-size: 100%;
}
30 changes: 17 additions & 13 deletions pages/douban/coming_soon/coming_soon.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
var util = require('../../../utils/util.js')
var functions = require('../functions.js')
Page({
data: {
films: []
films: [],
showLoading: true
},
onLoad: function () {
var that = this
fetch('https://api.douban.com/v2/movie/coming_soon?city=%E4%B8%8A%E6%B5%B7').then(function(response){
if(response.status !== 200){
console.log("error:"+response.status);
return;
}
response.json().then(function(data){
that.setData({
films: data.subjects
})
});
})
functions.getCity(function(city){
fetch('https://api.douban.com/v2/movie/coming_soon?city=' + city).then(function(response){
if(response.status !== 200){
console.log("error:"+response.status);
return;
}
response.json().then(function(data){
that.setData({
films: data.subjects,
showLoading: false
})
});
})
}
)
},
viewDetail: functions.viewDetail
})
3 changes: 3 additions & 0 deletions pages/douban/coming_soon/coming_soon.wxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<view class="page-loading {{showLoading ? '' : 'hide'}}">
<text class="weui-loading"/><text class="loading-text">玩命加载中</text>
</view>
<view class="container film-list">
<block wx:for-items="{{films}}" wx:for-item="film">
<view class="film-item" bindtap="viewDetail" data-id="{{film.id}}" data-title="{{film.title}}">
Expand Down
3 changes: 3 additions & 0 deletions pages/douban/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
baiduAK: '7VENmCeC4aaAfx3CKbSjT1K3oRucOgDK'
}
29 changes: 27 additions & 2 deletions pages/douban/functions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
module.exports={
var store = require('./store.js')
var config = require('./config.js')
module.exports = {
viewDetail: function(e){
var ds = e.currentTarget.dataset;
wx.navigateTo({
url: '../detail/detail?id=' + ds.id + '&title=' + ds.title
url: '../detail/detail?id=' + ds.id + '&title=' + ds.title
})
},
getLocation: function(cb){
var location = store.location
if(location){
cb(location)
return;
}
wx.getLocation({
success: function (res) {
var locationParam = res.latitude + ',' + res.longitude
fetch('https://api.map.baidu.com/geocoder/v2/?ak=' + config.baiduAK + '&location=' + locationParam + '1&output=json&pois=1').then(function(response){
response.json().then(function(data){
store.location = data.result
cb(data.result)
})
})
}
})
},
getCity: function(cb){
this.getLocation(function(location){
cb(location.addressComponent.city.replace('市', ''))
})
}
}
28 changes: 16 additions & 12 deletions pages/douban/in_theathers/in_theathers.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
var util = require('../../../utils/util.js')
var functions = require('../functions.js')
Page({
data: {
films: []
films: [],
showLoading: true
},
onLoad: function () {
var that = this
fetch('https://api.douban.com/v2/movie/in_theaters?city=%E4%B8%8A%E6%B5%B7').then(function(response){
if(response.status !== 200){
console.log("error:"+response.status);
return;
}
response.json().then(function(data){
that.setData({
films: data.subjects
})
});
functions.getCity(function(city){
fetch('https://api.douban.com/v2/movie/in_theaters?city=' + city).then(function(response){
if(response.status !== 200){
console.log("error:"+ response.status);
return;
}
response.json().then(function(data){
that.setData({
films: data.subjects,
showLoading: false
})
});
})
})

},
viewDetail: functions.viewDetail
})
3 changes: 3 additions & 0 deletions pages/douban/in_theathers/in_theathers.wxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<view class="page-loading {{showLoading ? '' : 'hide'}}">
<text class="weui-loading"/><text class="loading-text">玩命加载中</text>
</view>
<view class="container film-list">
<block wx:for-items="{{films}}" wx:for-item="film">
<view class="film-item" bindtap="viewDetail" data-id="{{film.id}}" data-title="{{film.title}}">
Expand Down
3 changes: 3 additions & 0 deletions pages/douban/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
location: null
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 微信小程序 - 豆瓣电影

[应用号IDE + 破解](https://github.com/gavinkwoe/weapp-ide-crack)

![image/list.jpg](image/list.jpg)


Expand Down
13 changes: 12 additions & 1 deletion utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ function formatNumber(n) {
return n[1] ? n : '0' + n
}

function formatLocation(longitude, latitude) {
longitude = longitude.toFixed(2)
latitude = latitude.toFixed(2)

return {
longitude: longitude.toString().split('.'),
latitude: latitude.toString().split('.')
}
}

module.exports = {
formatTime: formatTime
formatTime: formatTime,
formatLocation: formatLocation
}

0 comments on commit d608123

Please sign in to comment.