Skip to content

Commit

Permalink
Simplify logout
Browse files Browse the repository at this point in the history
  • Loading branch information
maundytime authored Oct 17, 2017
1 parent a1789ec commit 9e902bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/pages/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ const network = require('../../mixins/network')

Page(extend({}, tap, {
onLoad () {
if (!getApp().globalData.account) {
wx.redirectTo({url: '/pages/login/login'})
return
}
fm.load(this)
network.listen(this)
},
Expand Down
23 changes: 10 additions & 13 deletions src/pages/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,19 @@ Page({
itemList: ['退出登录'],
success (res) {
if (!res.cancel) {
const {id} = e.currentTarget.dataset
let index = -1
for (let i = 0; i < accounts.length; i++) {
if (accounts[i].id === id) {
index = i
for (const [i, account] of accounts.entries()) {
if (account.id === e.currentTarget.dataset.id) {
accounts.splice(i, 1)
wx.setStorageSync('accounts', accounts)
getApp().globalData.account = accounts[0]
if (accounts.length === 0) {
wx.reLaunch({url: '/pages/login/login'})
} else if (i === 0) {
wx.reLaunch({url: '/pages/home/home'})
}
break
}
}
if (index >= 0) {
accounts.splice(index, 1)
wx.setStorageSync('accounts', accounts)
getApp().globalData.account = accounts[0]
if (index === 0) {
wx.reLaunch({url: '/pages/home/home'})
}
}
page.setData({accounts})
}
}
Expand Down

0 comments on commit 9e902bc

Please sign in to comment.