首页| 论坛| 消息
主题:小程序
回帖:// pages/user/user.js
const app = getApp()

Page({
/**
* 页面的初始数据
*/
data: {
userInfo: {},
hasUserInfo: false,
canIUseGetUserProfile: false,
//canIUse: wx.canIUse('button.open-type.getUserInfo'),
skey: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
//获取缓存中skey的值
try {
var skey = wx.getStorageSync('skey')
var hasKey = false
if (skey) {
hasKey = true
} else {
hasKey = false
}
//console.log(skey)
if (skey) {
this.setData({
skey: skey
})
}

} catch (e) {
}
if (app.globalData.userInfo) {
//console.log(hasKey);
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true,
hasKey: hasKey
})
} else if (this.data.canIUseGetUserProfile) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true,
hasKey: hasKey
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserProfile({
desc: '用于完善会员资料',
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true,
hasKey: hasKey
})
}
})
}

},
isLogin() {
app.isLogin();
},
goto:function(e){
var url = e.currentTarget.dataset.url;
if (wx.getStorageSync("skey")) {
wx.reLaunch({
url: "../" + url + "/" + url,
});
} else {
app.issLogin(url);
}
//
},
suggest: function (e) {
var url = e.currentTarget.dataset.url;
wx.navigateTo({
url: "../" + url + "/" + url,
});
},
read: function (e) {
var id = e.currentTarget.dataset.id;
wx.navigateTo({
url: "../read/read?id=" + id ,
});
},
readweb: function (e) {
var id = e.currentTarget.dataset.id;
wx.navigateTo({
url: "../user/xie1?id=" + id ,
});
},
bindViewTap1: function() {
wx.redirectTo({
url: "../scanble/scanble"
});
},
getUserProfile(e) {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
getUserInfo: function (e) {
var that = this
wx.showModal({
title: '隐私提示',
content: '首次授权用户请阅读血压云隐私协议。是否授权血压云获取您微信的昵称信息?',
cancelText:'阅读协议',
confirmText:'同意授权',
success (res) {
if (res.confirm) {
//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);
//console.log('用户点击确定1')
that.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true,
hasKey: true
})
//console.log('用户点击确定2')
} else if (res.cancel) {
wx.navigateTo({
url: '../user/xie1',
})
//console.log('用户点击取消')
}
}
})
},
outLogin() {
this.setData({
hasUserInfo: false,
hasKey:false
})
wx.removeStorage({
key: "userInfo"
}),
app.globalData.userInfo = null,
wx.removeStorage({ key: 'skey' })
},
delLogin() {
var that = this
wx.showModal({
title: '帐号注销',
content: '此功能将清除您在血压云所有的血压记录数据及注册信息,请谨慎使用。',
cance
下一页 (1/3)
下一楼›:点此授权登陆1
点此授权登陆2

{{userInfo.nickName}}
退出

我的血压 ..
‹上一楼://index.js
//获取应用实例
const app = getApp()
Page({
data: {
motto: & ..

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