index.ts
4.46 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/login',
name: 'Login',
component: () => import('@/views/Login.vue'),
meta: { public: true },
},
{
path: '/',
component: () => import('@/layouts/MainLayout.vue'),
redirect: '/dashboard',
children: [
{
path: 'dashboard',
name: 'Dashboard',
component: () => import('@/views/dashboard/DashboardHome.vue'),
meta: { title: '工作台' },
},
{
path: 'city',
name: 'City',
component: () => import('@/views/city/CityList.vue'),
meta: { title: '租户管理' },
},
{
path: 'substation',
name: 'Substation',
component: () => import('@/views/substation/SubstationList.vue'),
meta: { title: '分站管理' },
},
{
path: 'merchant/enter',
name: 'MerchantEnter',
component: () => import('@/views/merchant/EnterList.vue'),
meta: { title: '入驻申请' },
},
{
path: 'merchant/store',
name: 'MerchantStore',
component: () => import('@/views/merchant/StoreList.vue'),
meta: { title: '店铺管理' },
},
{
path: 'rider',
name: 'Rider',
component: () => import('@/views/rider/RiderList.vue'),
meta: { title: '骑手管理' },
},
{
path: 'order',
name: 'Order',
component: () => import('@/views/order/OrderList.vue'),
meta: { title: '订单管理' },
},
{
path: 'refund',
name: 'Refund',
component: () => import('@/views/order/RefundList.vue'),
meta: { title: '退款管理' },
},
{
path: 'delivery/order',
name: 'DeliveryOrder',
component: () => import('@/views/delivery/DeliveryOrderList.vue'),
meta: { title: '配送订单' },
},
{
path: 'config/fee-plan',
name: 'FeePlan',
component: () => import('@/views/config/FeePlanList.vue'),
meta: { title: '配送费配置' },
},
{
path: 'dispatch/rule',
name: 'DispatchRule',
component: () => import('@/views/dispatch/DispatchRuleList.vue'),
meta: { title: '调度规则' },
},
{
path: 'rider/evaluate',
name: 'RiderEvaluate',
component: () => import('@/views/rider/RiderEvaluateList.vue'),
meta: { title: '骑手评价' },
},
{
path: 'open',
name: 'OpenApp',
component: () => import('@/views/open/OpenAppList.vue'),
meta: { title: '开放平台' },
},
{
path: 'open/mock-delivery',
name: 'OpenMockDelivery',
component: () => import('@/views/open/OpenMockDelivery.vue'),
meta: { title: '模拟推单' },
},
{
path: 'system/menu',
name: 'SystemMenu',
component: () => import('@/views/system/MenuManage.vue'),
meta: { title: '菜单管理' },
},
{
path: 'system/role',
name: 'SystemRole',
component: () => import('@/views/system/RoleList.vue'),
meta: { title: '角色管理' },
},
{
path: 'system/role-menu',
name: 'SystemRoleMenu',
component: () => import('@/views/system/RoleMenuAssign.vue'),
meta: { title: '角色菜单' },
},
{
path: 'admin-user',
name: 'AdminUser',
component: () => import('@/views/admin/AdminUserList.vue'),
meta: { title: '平台账号' },
},
],
},
{ path: '/:pathMatch(.*)*', redirect: '/' },
],
})
router.beforeEach((to) => {
const auth = useAuthStore()
if (!to.meta.public && !auth.token) {
return { path: '/login' }
}
if (!to.meta.public && auth.token) {
if (!auth.menus.length) {
auth.logout()
return { path: '/login' }
}
if (to.path !== '/' && !auth.hasPath(to.path)) {
return { path: auth.fallbackHomePath }
}
}
document.body.classList.add('loading')
})
router.afterEach(() => {
setTimeout(() => {
document.body.classList.remove('loading')
}, 300)
})
export default router