heritage-admin/src/router/index.js

78 lines
2.8 KiB
JavaScript

import { createRouter, createWebHistory } from 'vue-router'
import Index from '../pages/Index.vue'
import Archives from '../pages/Archives.vue'
import Inspections from '../pages/Inspections.vue'
import Projects from '../pages/Projects.vue'
import Analytics from '../pages/Analytics.vue'
import QrLogin from '../pages/QrLogin.vue'
import AdminLayout from '../pages/admin/AdminLayout.vue'
import AdminHome from '../pages/admin/Home.vue'
import { getToken } from '../lib/auth'
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/',
name: 'index',
component: Index,
},
{
path: '/archives',
name: 'archives',
component: Archives,
},
{
path: '/inspections',
name: 'inspections',
component: Inspections,
},
{
path: '/projects',
name: 'projects',
component: Projects,
},
{
path: '/analytics',
name: 'analytics',
component: Analytics,
},
{
path: '/login',
name: 'login',
component: QrLogin,
},
{
path: '/admin',
component: AdminLayout,
children: [
{ path: '', redirect: '/admin/home' },
{ path: 'home', component: AdminHome },
{ path: 'archives', name: 'admin-archives', component: Archives },
{ path: 'inspections', name: 'admin-inspections', component: Inspections },
{ path: 'system/user', name: 'admin-system-usr', component: () => import('../pages/system/user.vue') },
{ path: 'system/role', name: 'admin-system-role', component: () => import('../pages/system/role.vue') },
{ path: 'system/option', name: 'admin-system-option', component: () => import('../pages/system/option.vue') },
{ path: 'org/list', name: 'admin-org-list', component: () => import('../pages/org/list.vue') },
{ path: 'org/person', name: 'admin-org-person', component: () => import('../pages/org/person.vue') },
{ path: 'device/summary', name: 'admin-device-summary', component: () => import('../pages/device/summary.vue') },
{ path: 'device/list', name: 'admin-device-list', component: () => import('../pages/device/list.vue') },
{ path: 'project/list', name: 'admin-project-list', component: () => import('../pages/project/list.vue') },
{ path: 'project/detail', name: 'admin-project-detail', component: () => import('../pages/project/detail.vue') },
{path:'task/list',name:'admin-task-list',component:()=> import('../pages/task/list.vue')},
{path:'data/list',name:'admin-record-list',component:()=> import('../pages/record/list.vue')},
{path:'point/list',name:'admin-point-list',component:()=> import('../pages/point/list.vue')}
],
},
],
})
router.beforeEach((to) => {
if (to.path.startsWith('/admin') && !getToken()) {
return { path: '/login' }
}
return true
})
export default router