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
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
||||||
api("/auth/miniLogin?code=" + res.code).then(res => {
|
api("/auth/miniLogin?code=" + res.code).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
wx.setStorageSync('openid', res.data.openid)
|
wx.setStorageSync('openId', res.data.user.openId)
|
||||||
wx.setStorageSync('sessionKey', res.data.sessionKey)
|
wx.setStorageSync('sessionKey', res.data.user.sessionKey)
|
||||||
if (res.data.id){
|
if (res.data.user.id){
|
||||||
wx.setStorageSync('user', res.data)
|
wx.setStorageSync('user', res.data.user)
|
||||||
wx.setStorageSync('token', res.data.token)
|
wx.setStorageSync('token', res.data.token)
|
||||||
} else {
|
} else {
|
||||||
wx.showModal({
|
wx.showModal({
|
||||||
|
|||||||
@ -8,14 +8,22 @@ Page({
|
|||||||
* 页面的初始数据
|
* 页面的初始数据
|
||||||
*/
|
*/
|
||||||
data: {
|
data: {
|
||||||
checked:false
|
checked:false,
|
||||||
|
openData:null
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生命周期函数--监听页面加载
|
* 生命周期函数--监听页面加载
|
||||||
*/
|
*/
|
||||||
onLoad(options) {
|
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(){
|
read(){
|
||||||
@ -31,13 +39,13 @@ Page({
|
|||||||
if (e.detail.errMsg != 'getPhoneNumber:ok') {
|
if (e.detail.errMsg != 'getPhoneNumber:ok') {
|
||||||
return
|
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 => {
|
api("/auth/getPhone", 'GET', data).then(res => {
|
||||||
wx.hideLoading()
|
wx.hideLoading()
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
wx.setStorageSync('user', res.data)
|
wx.setStorageSync('user', res.data.user)
|
||||||
wx.setStorageSync('token', res.data.token)
|
wx.setStorageSync('token', res.data.token)
|
||||||
wx.navigateBack()
|
wx.navigateBack()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user