-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhook.js
More file actions
59 lines (55 loc) · 1.91 KB
/
Copy pathhook.js
File metadata and controls
59 lines (55 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {
getToken,
getAccountList
} from '../../business/auth'
import store from '@/store'
import * as types from '@/store/mutation-types'
// import { ToPage } from '../../business/types'
import {
isNotEmpty
} from '../../utils'
import clone from 'clone'
// import { isNotEmpty } from '../../utils'
const extension = require('extensionizer')
const whiteListPage = ['/login', '/register', '/newwallet', '/newwalletresult', '/importwalletwithseed']
// const whiteListPage = ['/login', '/register', '/transfer', '/newwallet', '/newwalletresult', '/importwalletwithseed', '/homepage', '/delegateorunbond', '/txresult', '/accountlist', '/newaccount', '/importaccount']
// 获取backgroud.js中store中的state
const bg = extension.extension.getBackgroundPage()
const bgState = bg.getBgState()
store.commit(types.SET_MSG_QUEQUE, clone(bgState.msgQueue))
// store.commit(types.INPUT_TOPAGE_PARAMS, new ToPage(bgState.toPage))
console.log('bgState.msgQueue in popup hook', bgState.msgQueue)
export async function beforeEach (to, from, next) {
// const first = await bg.getFirstMsg()
const first = store.getters.firstMsg
console.log('store.getters.firstMsg', store.getters.firstMsg)
if (isNotEmpty(first)) {
const data = first.params
if (isNotEmpty(data.pageName) && !first.hasDirect) {
// 更新当前first data 为已跳转页面状态
store.commit(types.HAS_DIRECT_PAGE)
next({
name: data.pageName
})
return
}
}
// const toPage = await store.dispatch('getToPage')
// if (isNotEmpty(toPage.pageName)) {
// next({ name: toPage.pageName })
// return
// }
if (!getToken() && whiteListPage.indexOf(to.path) === -1) {
console.log('real to page name', to.name)
// 判断是否有token
const accList = getAccountList()
if (!accList || accList.length === 0) {
// next('/register')
next('/login')
return
}
next('/login')
return
}
next()
}