123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- const types = ['default', 'primary', 'warn']
- //获取应用实例
- const app = getApp()
- const pageObject = {
- data: {
- userInfo: {},
- hasUserInfo: false,
- canIUse: wx.canIUse('button.open-type.getUserInfo'),
- defaultSize: 'default',
- primarySize: 'default',
- warnSize: 'default',
- disabled: false,
- plain: false,
- loading: false
- },
- onLoad: function () {
- // console.log("****************onLoad setting******************");
- 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
- })
- }
- })
- }
- console.log("user info:" + app.globalData.userInfo);
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- // console.log("onReady setting @@@@@@@@@@@@@@@@@");
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- // console.log("*************onShow setting****************");
- 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
- })
- }
- })
- }
- // console.log("user info:" + app.globalData.userInfo);
- },
- }
- Page(pageObject)
|