Skip to content

Commit

Permalink
小程序第一天
Browse files Browse the repository at this point in the history
  • Loading branch information
韦华文 committed Oct 13, 2018
1 parent a86c4bb commit 58a3c1b
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 2,807 deletions.
39 changes: 6 additions & 33 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)

// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo

// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
userInfo: null
// options 路径对象
onShow: function (options) {
console.log(options)
},
onHide: function (options) {
console.log(options)
}
})
6 changes: 0 additions & 6 deletions jsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion pages/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Page({
* 页面的初始数据
*/
data: {

msg: 'home'
},

/**
Expand Down
4 changes: 3 additions & 1 deletion pages/home/home.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"navigationBarTitleText": "home"
}
6 changes: 5 additions & 1 deletion pages/home/home.wxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<!--pages/home/home.wxml-->
<text>pages/home/home.wxml</text>
<!-- <text>pages/home/home.wxml</text> -->

<text>
{{msg}}
</text>
75 changes: 19 additions & 56 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,29 @@
// pages/index/index.js
Page({

/**
* 页面的初始数据
*/
data: {

},

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {

onLoad: function(options) {
//Do some initialize when page load.

},

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {

onReady: function() {
//Do some when page ready.

},

/**
* 生命周期函数--监听页面显示
*/
onShow: function () {

onShow: function() {
//Do some when page show.

},

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

onHide: function() {
//Do some when page hide.

},

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {

onUnload: function() {
//Do some when page unload.

},

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {

},

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {

},

/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {

onPullDownRefresh: function() {
//Do some when page pull down.

}
})
Loading

0 comments on commit 58a3c1b

Please sign in to comment.