bug修改
This commit is contained in:
@@ -1,27 +1,43 @@
|
||||
// app.js
|
||||
import UserApi from 'assets/js/http/userApi'
|
||||
import { wxBind } from 'assets/js/common'
|
||||
App({
|
||||
onLaunch() {
|
||||
// 展示本地存储能力
|
||||
const logs = wx.getStorageSync('logs') || []
|
||||
logs.unshift(Date.now())
|
||||
wx.setStorageSync('logs', logs)
|
||||
// wx.getStorage({
|
||||
// key: 'X-Access-Token',
|
||||
// success: (res) =>{// 缓存中登录过,直接进小程序
|
||||
// wx.switchTab({
|
||||
// url: 'pages/home/home',
|
||||
// })
|
||||
// },
|
||||
// fail: function(){
|
||||
// // 缓存中没有登录过默认app.json的登录页
|
||||
// }
|
||||
// })
|
||||
// 登录
|
||||
wx.login({
|
||||
success: res => {
|
||||
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
||||
// 长时间不操作导致token失效之后执行自动微信登录操作
|
||||
wx.getStorage({
|
||||
key: 'rsaPublicKey',
|
||||
success(result){
|
||||
wxBind((res)=>{
|
||||
let params = {
|
||||
openId: res.data.openid,
|
||||
rsaPublicKey: result.rsaPublicKey
|
||||
}
|
||||
UserApi.wxLogin(params).then(res=>{
|
||||
if(res.success) { // 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp)
|
||||
wx.setStorageSync('userInfo', res.result.userInfo)
|
||||
wx.setStorage({
|
||||
key: 'X-Access-Token',
|
||||
data: res.result.token
|
||||
})
|
||||
wx.switchTab({
|
||||
url: '../home/home',
|
||||
})
|
||||
}else{ // 首次登录不能直接用微信快捷登录
|
||||
wx.showToast({
|
||||
title: '暂无授权手机号, 请重新登录',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
globalData: {
|
||||
userInfo: null
|
||||
|
||||
Reference in New Issue
Block a user