首页| 论坛| 消息
主题:小程序
回帖://index.js
//获取应用实例
const app = getApp()
Page({
data: {
motto: '添加血压',
userInfo: {},
hasUserInfo: false,
hasKey:false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
bindViewTap: function() {
//wx.navigateTo({
//url: '../logs/logs'
//})
wx.navigateTo({
url: '../user/user'
})
},
bindAddTap: function () {
wx.switchTab({
url: '../add/add'
})
},
bindAddLanYaTap: function () {
wx.redirectTo({
url: '../scanble/scanble'
})
},
onLoad: function () {
var skey = wx.getStorageSync('skey')
var hasKey = false
if (skey){
hasKey = true
}else{
hasKey = false
}
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true,
hasKey:hasKey
})
} else if (this.data.canIUse){
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true,
hasKey: hasKey
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true,
hasKey: hasKey
})
}
})
}
},
getUserInfo: function(e) {
console.log(e)
console.log(e.detail.errMsg)
console.log(e.detail.iv)
console.log(e.detail.encryptedData)
app.globalData.userInfo = e.detail.userInfo
app.getLogin(e.detail);
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true,
hasKey: true
})
},
getPhoneNumber(e) {
console.log(e.detail.errMsg)
console.log(e.detail.iv)
console.log(e.detail.encryptedData)
},
getLogin(){
app.getLogin();
},
isLogin(){
app.isLogin();
},
outLogin(){
this.setData({
hasUserInfo: false
})
wx.removeStorage({
key: "userInfo"
}),
app.globalData.userInfo=null,
wx.removeStorage({key: 'skey'})
}
})
下一页 (1/2)
下一楼›:开心生活每一天
开始使用

{{userInfo.nickName}}

{{motto}}。支持西恩、斐 ..
‹上一楼:开心生活每一天
开始使用

{{userInfo.nickName}}

{{motto}}。支持西恩、斐 ..

查看全部回帖(9)
«返回主帖