微信API

This commit is contained in:
2023-01-31 14:58:42 +08:00
parent 13cf902ce2
commit c8a16e91b6
6 changed files with 128 additions and 35 deletions

View File

@@ -1,11 +1,40 @@
const app = getApp()
Page({
data: {},
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)
});
}
});