diff --git a/app.js b/app.js index 93e56f4..b1c27d8 100644 --- a/app.js +++ b/app.js @@ -12,10 +12,10 @@ App({ // 发送 res.code 到后台换取 openId, sessionKey, unionId api("/auth/miniLogin?code=" + res.code).then(res => { if (res.code === 200) { - wx.setStorageSync('openid', res.data.openid) - wx.setStorageSync('sessionKey', res.data.sessionKey) - if (res.data.id){ - wx.setStorageSync('user', res.data) + wx.setStorageSync('openId', res.data.user.openId) + wx.setStorageSync('sessionKey', res.data.user.sessionKey) + if (res.data.user.id){ + wx.setStorageSync('user', res.data.user) wx.setStorageSync('token', res.data.token) } else { wx.showModal({ diff --git a/pages/login/index.js b/pages/login/index.js index 68f128d..100fe64 100644 --- a/pages/login/index.js +++ b/pages/login/index.js @@ -8,14 +8,22 @@ Page({ * 页面的初始数据 */ data: { - checked:false + checked:false, + openData:null }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { + this.init() + }, + init(){ + const openId = wx.getStorageSync("openId") + const sessionKey = wx.getStorageSync('seesionKey') + const tmp = {openId: openId,sessionKey: sessionKey} + this.setData({openData:tmp}) }, read(){ @@ -31,13 +39,13 @@ Page({ if (e.detail.errMsg != 'getPhoneNumber:ok') { return } - console.log(e); - const data = {code:e.detail.code} + + const data = {code:e.detail.code, ...this.data.openData} api("/auth/getPhone", 'GET', data).then(res => { wx.hideLoading() if (res.code === 200) { - wx.setStorageSync('user', res.data) + wx.setStorageSync('user', res.data.user) wx.setStorageSync('token', res.data.token) wx.navigateBack() } else {