Initial commit
This commit is contained in:
@@ -13,8 +13,11 @@ Page({
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.fetchHonors()
|
||||
this.fetchProjects()
|
||||
const app = getApp()
|
||||
if (app.globalData.token) {
|
||||
this.fetchHonors()
|
||||
this.fetchProjects()
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
@@ -23,6 +26,12 @@ Page({
|
||||
|
||||
getUserInfo() {
|
||||
const app = getApp()
|
||||
if (!app.globalData.token) {
|
||||
// Not logged in, clear data
|
||||
this.setData({ user: {}, honors: [], projects: [] })
|
||||
return
|
||||
}
|
||||
|
||||
// Try to get from globalData first to speed up rendering
|
||||
if (app.globalData.userInfo) {
|
||||
this.setData({ user: app.globalData.userInfo })
|
||||
@@ -36,10 +45,21 @@ Page({
|
||||
// this.fetchProjects();
|
||||
}).catch(err => {
|
||||
console.error('Failed to fetch user info', err)
|
||||
if (err && (err.code === 401 || err.code === 403)) {
|
||||
// Token invalid, clear it
|
||||
app.globalData.token = null;
|
||||
app.globalData.userInfo = null;
|
||||
this.setData({ user: {}, honors: [], projects: [] });
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
const app = getApp()
|
||||
if (!app.globalData.token) {
|
||||
wx.stopPullDownRefresh()
|
||||
return
|
||||
}
|
||||
Promise.all([this.fetchHonors(), this.fetchProjects()]).then(() => {
|
||||
wx.stopPullDownRefresh()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user