diff --git a/1514080901134/pages/index/index.js b/1514080901134/pages/index/index.js index e6f21807..608a282e 100644 --- a/1514080901134/pages/index/index.js +++ b/1514080901134/pages/index/index.js @@ -1,12 +1,54 @@ +//index.js +//获取应用实例 +const app = getApp() + Page({ - open: function () { - wx.showActionSheet({ - itemList: ['A', 'B', 'C'], - success: function (res) { - if (!res.cancel) { - console.log(res.tapIndex) - } + data: { + motto: 'Hello World', + userInfo: {}, + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo') + }, + //事件处理函数 + bindViewTap: function() { + wx.navigateTo({ + url: '../logs/logs' + }) + }, + onLoad: function () { + if (app.globalData.userInfo) { + this.setData({ + userInfo: app.globalData.userInfo, + hasUserInfo: true + }) + } else if (this.data.canIUse){ + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + app.userInfoReadyCallback = res => { + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) } - }); + } else { + // 在没有 open-type=getUserInfo 版本的兼容处理 + wx.getUserInfo({ + success: res => { + app.globalData.userInfo = res.userInfo + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + } + }, + getUserInfo: function(e) { + console.log(e) + app.globalData.userInfo = e.detail.userInfo + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) } -}); \ No newline at end of file +}) diff --git a/1514080901134/pages/index/index.wxml b/1514080901134/pages/index/index.wxml index ba620e09..dafcae8c 100644 --- a/1514080901134/pages/index/index.wxml +++ b/1514080901134/pages/index/index.wxml @@ -1,34 +1,18 @@ HELLO - welcome to one sheep - - - - - - - - Button - 按钮,WeUI采用小程序原生的按钮为主体,加入一些间距的样式。 + 欢迎使用小程序 - - - - + - + - - - - + - - \ No newline at end of file + diff --git a/1514080901134/pages/index/index.wxss b/1514080901134/pages/index/index.wxss index 9c0b5e93..5adb1f89 100644 --- a/1514080901134/pages/index/index.wxss +++ b/1514080901134/pages/index/index.wxss @@ -1,6 +1,3 @@ -page{ - background-color: #FFFFFF; -} .button-sp-area{ margin: 0 auto; padding-top: 15px;