index.js
2.06 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginPage from '../views/LoginPage.vue'
import DashboardLayout from '../views/DashboardLayout.vue'
import OpportunityManagement from '../views/OpportunityManagement.vue'
import OpportunityDetail from '../views/OpportunityDetail.vue'
import GridQuery from '../views/GridQuery.vue'
import SystemManagement from '../views/SystemManagement.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/login',
name: 'Login',
component: LoginPage
},
{
path: '/',
component: DashboardLayout,
children: [
{
path: '',
redirect: '/opportunities'
},
{
path: '/opportunities',
name: 'OpportunityManagement',
component: OpportunityManagement
},
{
path: '/opportunities/:id',
name: 'OpportunityDetail',
component: OpportunityDetail
},
{
path: '/grid-query',
name: 'GridQuery',
component: GridQuery
},
{
path: '/system',
redirect: '/system/personnel'
},
{
path: '/system/personnel',
name: 'SystemPersonnel',
component: SystemManagement,
props: { activeTab: 'personnel' }
},
{
path: '/system/opportunity-config',
name: 'SystemOpportunityConfig',
component: SystemManagement,
props: { activeTab: 'tags' }
},
{
path: '/system/accounts',
name: 'SystemAccounts',
component: SystemManagement,
props: { activeTab: 'accounts' }
}
]
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
// 路由守卫
router.beforeEach((to, from, next) => {
// 检查是否已登录(演示模式下允许访问)
const isAuthenticated = localStorage.getItem('user') || sessionStorage.getItem('demoMode')
if (to.path !== '/login' && !isAuthenticated) {
next('/login')
} else {
next()
}
})
export default router