50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
const app = getApp()
|
|
Page({
|
|
data: {
|
|
noLogin: true,
|
|
},
|
|
onLoad: function (options) {
|
|
let openId = wx.getStorageSync("userId");
|
|
if (openId) {
|
|
this.setData({
|
|
noLogin : false
|
|
})
|
|
}
|
|
},
|
|
onShow: function () {
|
|
if (wx.canIUse('hideHomeButton')) {
|
|
wx.hideHomeButton()
|
|
}
|
|
},
|
|
loginAcc () {
|
|
let that = this;
|
|
wx.login({
|
|
success (res) {
|
|
if (res.code) {
|
|
let param = {
|
|
appid:'wxb1f499f0a173865b',
|
|
secret:'833eefaf9206337d6c2d643f94baef7b',
|
|
js_code: res.code,
|
|
grant_type: 'authorization_code'
|
|
};
|
|
//发起网络请求
|
|
wx.request({
|
|
url: 'https://api.weixin.qq.com/sns/jscode2session',
|
|
data: param,
|
|
success: function(x) {
|
|
app.$api.loginAccount({"openId":x.data.openid}).then(t=>{
|
|
wx.setStorageSync("userId",t.data)
|
|
that.setData({
|
|
noLogin : false
|
|
})
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
console.log('登录失败!' + res.errMsg)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
});
|