This commit is contained in:
yangsy
2025-08-14 12:51:20 +08:00
parent 542625c1d6
commit 941984447b
8 changed files with 381 additions and 55 deletions

View File

@@ -1,8 +1,65 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHistory } from 'vue-router';
import { useUserStore } from '@/stores/user';
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [],
})
routes: [
{
path: '/login',
component: () => import('@/pages/login-page.vue'),
},
{
path: '/',
component: () => import('@/layouts/app-layout.vue'),
redirect: '/dashboard',
children: [
{
path: 'dashboard',
component: () => import('@/pages/dashboard-page.vue'),
},
{
path: 'device',
component: () => import('@/pages/device-page.vue'),
},
{
path: 'alarm',
component: () => import('@/pages/alarm-page.vue'),
},
{
path: 'statistics',
component: () => import('@/pages/statistics-page.vue'),
},
{
path: 'log',
component: () => import('@/pages/log-page.vue'),
},
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: () => import('@/pages/not-found-page.vue'),
},
],
},
],
});
export default router
const whiteList = ['/login'];
router.beforeEach((to, from, next) => {
const userStore = useUserStore();
if (userStore.userLoginResult?.token) {
if (to.path === '/login') {
next({ path: '/' });
} else {
next();
}
} else {
if (whiteList.includes(to.path)) {
next();
} else {
next('/login');
}
}
});
export default router;