Skip to content

Commit

Permalink
first commi
Browse files Browse the repository at this point in the history
  • Loading branch information
laohoubin committed Sep 23, 2016
1 parent cc98842 commit 1bfdc71
Show file tree
Hide file tree
Showing 34 changed files with 294 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# wechat-weapp-mapdemo

微信小程序开发demo-地图定位


### Screenshot

![](./image/screenshot1.png)

![](./image/screenshot1.png)

30 changes: 30 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
getUserInfo:function(cb){
var that = this;
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo;
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
});
}
},
globalData:{
userInfo:null
}
})
36 changes: 36 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"pages":[
"pages/index/index",
"pages/location/location",
"pages/logs/logs"
],
"tabBar": {
"color": "#dddddd",
"selectedColor": "#3cc51f",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [{
"pagePath": "pages/index/index",
"iconPath": "image/wechat.png",
"selectedIconPath": "image/wechatHL.png",
"text": "首页"
}, {
"pagePath": "pages/location/location",
"iconPath": "image/locate.png",
"selectedIconPath": "image/locateHL.png",
"text": "定位"
},{
"pagePath": "pages/logs/logs",
"iconPath": "image/wechat.png",
"selectedIconPath": "image/wechat.png",
"text": "日志"
}]
},
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Map",
"navigationBarTextStyle":"black"
},
"debug": true
}
10 changes: 10 additions & 0 deletions app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
Binary file added image/arrowright.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/icon64_appwx_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/locate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/locateHL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/record.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/wechat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/wechatHL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
motto: '微信小程序尝鲜,地图定位',
userInfo: {},
appInfo:{
logoUrl:'../../image/wechat.png',
title:'使用微信内置地图查看API定位'
}
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../location/location'
})
},
onLoad: function () {
console.log('onLoad')
var that = this
console.log(this.data)
that.setData({
appInfo:this.data.appInfo
})
//调用应用实例的方法获取全局数据
// app.getUserInfo(function(userInfo){
// //更新数据
// that.setData({
// userInfo:userInfo
// })
// that.update()
// })
}
})
10 changes: 10 additions & 0 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--index.wxml-->
<view class="container">
<view bindtap="bindViewTap" class="userinfo">
<image class="userinfo-avatar" src="{{appInfo.logoUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{appInfo.title}}</text>
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>
21 changes: 21 additions & 0 deletions pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}

.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}

.userinfo-nickname {
color: #aaa;
}

.usermotto {
margin-top: 200px;
}
21 changes: 21 additions & 0 deletions pages/location/location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//location.js
//获取应用实例
var app = getApp()
Page({
onLoad: function () {
console.log('地图定位!')
var that = this
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
success: function (res) {
var latitude = res.latitude;
var longitude = res.longitude;
wx.openLocation({
latitude:latitude,
longitude:longitude,
scale:1
})
}
});
}
})
3 changes: 3 additions & 0 deletions pages/location/location.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "当前地图位置"
}
2 changes: 2 additions & 0 deletions pages/location/location.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<view class="container" id="map">
</view>
3 changes: 3 additions & 0 deletions pages/location/location.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#map {
padding: 40rpx;
}
13 changes: 13 additions & 0 deletions pages/logs/logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(function (log) {
return util.formatTime(new Date(log))
})
})
}
})
3 changes: 3 additions & 0 deletions pages/logs/logs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "查看启动日志"
}
6 changes: 6 additions & 0 deletions pages/logs/logs.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for-items="{{logs}}" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>
8 changes: 8 additions & 0 deletions pages/logs/logs.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
30 changes: 30 additions & 0 deletions pages/main/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var app = getApp()
Page({
data: {
motto: 'Hello WeApp',
userInfo: {}
},
onButtonTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
console.log('onLoad')
var that = this
//登录
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.setData({userInfo: res.userInfo})
that.update()
}
})
},
fail: function (res) {
console.log(res)
}
});
}
})
10 changes: 10 additions & 0 deletions pages/main/main.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--index.wxml-->
<view class="container">
<view bindtap="onButtonTap" class="userinfo">
<image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</view>
<view>
<text class="user-motto">{{motto}}</text>
</view>
</view>
24 changes: 24 additions & 0 deletions pages/main/main.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**index.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
}
21 changes: 21 additions & 0 deletions utils/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function formatTime(date) {
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()

var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds();


return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}

module.exports = {
formatTime: formatTime
}

0 comments on commit 1bfdc71

Please sign in to comment.