Files
quinn-accounts/pages/myself/index.js
2023-01-31 14:58:42 +08:00

41 lines
1.1 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 () {
wx.login({
success (res) {
if (res.code) {
app.$api.getOpenId(res.code).then(res => {
wx.setStorageSync("openid",res.data.openid)
this.setData({
noLogin : false
})
}, err => {
console.log(err);
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
app.$api.loginAccount(wx.getStorageSync('openid')).then(res => {
wx.setStorageSync('userId',res.data)
});
}
});