Files
income_payments_applet/app.js
T

53 lines
1.5 KiB
JavaScript

// 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.removeStorage({
key: 'avatarUrl',
})
// 长时间不操作导致token失效之后执行自动微信登录操作
wx.getStorage({
key: 'rsaPublicKey',
success(result){
wxBind((res)=>{
let params = {
openId: res.result.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.removeStorage({
key: 'userInfoTemp',
})
wx.removeStorage({
key: 'userInfo',
})
wx.removeStorage({
key: 'X-Access-Token',
})
}
})
})
}
})
},
globalData: {
userInfo: null
}
})