init
This commit is contained in:
parent
662620e3ea
commit
558f54e721
8
app.js
8
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({
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user