Skip to content

Commit bdc76eb

Browse files
功能完成
0 parents  commit bdc76eb

File tree

15 files changed

+790
-0
lines changed

15 files changed

+790
-0
lines changed

app.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//app.js
2+
App({
3+
onLaunch: function () {
4+
// 展示本地存储能力
5+
var logs = wx.getStorageSync('logs') || []
6+
logs.unshift(Date.now())
7+
wx.setStorageSync('logs', logs)
8+
9+
// 登录
10+
wx.login({
11+
success: res => {
12+
// 发送 res.code 到后台换取 openId, sessionKey, unionId
13+
}
14+
})
15+
// 获取用户信息
16+
wx.getSetting({
17+
success: res => {
18+
if (res.authSetting['scope.userInfo']) {
19+
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
20+
wx.getUserInfo({
21+
success: res => {
22+
// 可以将 res 发送给后台解码出 unionId
23+
this.globalData.userInfo = res.userInfo
24+
25+
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
26+
// 所以此处加入 callback 以防止这种情况
27+
if (this.userInfoReadyCallback) {
28+
this.userInfoReadyCallback(res)
29+
}
30+
}
31+
})
32+
}
33+
}
34+
})
35+
},
36+
globalData: {
37+
userInfo: null
38+
}
39+
})

app.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"pages":[
3+
"pages/index/index",
4+
"pages/logs/logs"
5+
],
6+
"window":{
7+
"backgroundTextStyle":"light",
8+
"navigationBarBackgroundColor": "#fff",
9+
"navigationBarTitleText": "WeChat",
10+
"navigationBarTextStyle":"black"
11+
}
12+
}

app.wxss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**app.wxss**/
2+
.container {
3+
height: 100%;
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
justify-content: space-between;
8+
padding: 200rpx 0;
9+
box-sizing: border-box;
10+
}

images/location.png

1.1 KB
Loading

pages/index/index.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
const QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
2+
const network = require('../../utils/util.js');
3+
4+
Page({
5+
data: {
6+
latitude: '',
7+
longitude: '',
8+
controls: [{
9+
id: 1,
10+
iconPath: "../../images/location.png",
11+
position: {
12+
left: wx.getSystemInfoSync().windowWidth / 2 - 25,
13+
top: wx.getSystemInfoSync().windowHeight / 2 - 45,
14+
width: 50,
15+
height: 50
16+
},
17+
clickable: true
18+
}]
19+
},
20+
regionchange(e) {
21+
if (e.type === "end") {
22+
this.mapCtx.getCenterLocation({
23+
success: (res) => {
24+
this.setData({
25+
latitude: res.latitude,
26+
longitude: res.longitude
27+
})
28+
this.myLocation()
29+
}
30+
})
31+
}
32+
},
33+
moveToLocation() {
34+
this.mapCtx.moveToLocation();
35+
},
36+
myLocation() {
37+
var mapDemo = new QQMapWX({
38+
key: 'II5BZ-YLEK3-2ID3I-YZ7MB-6UWR2-BEBOX' // 必填
39+
});
40+
let location = this.data.longitude + ',' + this.data.latitude
41+
let data = {
42+
key: 'b2b69d499ffb2670e23f79f9c5c12a6d',
43+
location: location
44+
}
45+
network.ajax('https://restapi.amap.com/v3/geocode/regeo', data).then(res => {
46+
console.log(res.regeocode.formatted_address)
47+
wx.showModal({
48+
content: res.regeocode.formatted_address,
49+
})
50+
}).catch(function (err) {
51+
console.error(err)
52+
})
53+
// mapDemo.reverseGeocoder({
54+
// location: {
55+
// latitude: this.data.latitude,
56+
// longitude: this.data.longitude
57+
// },
58+
// success: function (res) {
59+
// console.log(res.result.address);
60+
// wx.showModal({
61+
// title: '提示',
62+
// content: res.result.address,
63+
// success: function (res) {
64+
// if (res.confirm) {
65+
// console.log('用户点击确定')
66+
// }
67+
// }
68+
// })
69+
// },
70+
// fail: function (res) {
71+
// console.log(res);
72+
// },
73+
// complete: function (res) {
74+
// console.log(res);
75+
// }
76+
// });
77+
78+
},
79+
onLoad: function () {
80+
this.mapCtx = wx.createMapContext('map')
81+
},
82+
onReady: function () {
83+
wx.getLocation({
84+
type: 'wgs84',
85+
success: (res) => {
86+
console.log(res)
87+
this.setData({
88+
latitude: res.latitude,
89+
longitude: res.longitude
90+
})
91+
this.myLocation()
92+
setTimeout(()=>{
93+
this.moveToLocation();
94+
})
95+
}
96+
})
97+
}
98+
})

pages/index/index.wxml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!--logs.wxml-->
2+
<view class="container log-list">
3+
<map id="map" longitude="{{longitude}}" latitude="{{latitude}}" markers="{{markers}}" scale="16" bindregionchange="regionchange" controls="{{controls}}" show-location>
4+
<cover-view class='location' bindtap="moveToLocation">2134</cover-view>
5+
</map>
6+
</view>

pages/index/index.wxss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.log-list {
2+
display: flex;
3+
flex-direction: column;
4+
height: 100%;
5+
padding:0;
6+
}
7+
8+
#map {
9+
position: relative;
10+
width: 100%;
11+
height: 100%;
12+
}
13+
14+
page {
15+
height: 100%;
16+
}
17+
18+
.location{
19+
position:fixed;
20+
bottom:50px;
21+
left:50px;
22+
z-index: 100;
23+
}

pages/logs/logs.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Page({
2+
3+
/**
4+
* 页面的初始数据
5+
*/
6+
data: {
7+
8+
},
9+
10+
/**
11+
* 生命周期函数--监听页面加载
12+
*/
13+
onLoad: function (options) {
14+
15+
},
16+
17+
/**
18+
* 生命周期函数--监听页面初次渲染完成
19+
*/
20+
onReady: function () {
21+
22+
},
23+
24+
/**
25+
* 生命周期函数--监听页面显示
26+
*/
27+
onShow: function () {
28+
29+
},
30+
31+
/**
32+
* 生命周期函数--监听页面隐藏
33+
*/
34+
onHide: function () {
35+
36+
},
37+
38+
/**
39+
* 生命周期函数--监听页面卸载
40+
*/
41+
onUnload: function () {
42+
43+
},
44+
45+
/**
46+
* 页面相关事件处理函数--监听用户下拉动作
47+
*/
48+
onPullDownRefresh: function () {
49+
50+
},
51+
52+
/**
53+
* 页面上拉触底事件的处理函数
54+
*/
55+
onReachBottom: function () {
56+
57+
},
58+
59+
/**
60+
* 用户点击右上角分享
61+
*/
62+
onShareAppMessage: function () {
63+
64+
}
65+
})

pages/logs/logs.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"navigationBarTitleText": "查看启动日志"
3+
}

pages/logs/logs.wxml

Whitespace-only changes.

pages/logs/logs.wxss

Whitespace-only changes.

project.config.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"description": "项目配置文件。",
3+
"setting": {
4+
"urlCheck": true,
5+
"es6": true,
6+
"postcss": true,
7+
"minified": true,
8+
"newFeature": true
9+
},
10+
"compileType": "miniprogram",
11+
"libVersion": "1.9.94",
12+
"appid": "wxe1b184e986d8f644",
13+
"projectname": "%E5%9C%B0%E5%9B%BE",
14+
"isGameTourist": false,
15+
"condition": {
16+
"search": {
17+
"current": -1,
18+
"list": []
19+
},
20+
"conversation": {
21+
"current": -1,
22+
"list": []
23+
},
24+
"game": {
25+
"currentL": -1,
26+
"list": []
27+
},
28+
"miniprogram": {
29+
"current": -1,
30+
"list": []
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)