2023-12-30 17:40:20 +08:00
|
|
|
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
|
2025-08-10 14:32:24 +08:00
|
|
|
// import LoginInex from '../components/Login.vue'
|
2023-12-30 17:40:20 +08:00
|
|
|
import { CONSTANT } from '../constant'
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
2025-08-10 14:32:24 +08:00
|
|
|
// 使用 HTML5 History 模式,确保 URL 变化反映在浏览器地址栏中
|
2025-08-10 14:39:45 +08:00
|
|
|
history: createWebHashHistory(),
|
2023-12-30 17:40:20 +08:00
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
name: 'login',
|
2025-08-10 14:32:24 +08:00
|
|
|
component:() => import('../components/Login.vue')
|
2023-12-30 17:40:20 +08:00
|
|
|
},
|
2024-01-24 21:33:51 +08:00
|
|
|
{
|
2025-08-10 14:32:24 +08:00
|
|
|
path: '/',
|
|
|
|
|
name: 'index',
|
|
|
|
|
component: () => import('../components/Index.vue'),
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
// 默认子路由,显示 Dashboard
|
|
|
|
|
path: '',
|
|
|
|
|
name: 'dashboard',
|
|
|
|
|
component: () => import('../components/pages/dashboard/Dashboard.vue')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'sendlogs',
|
|
|
|
|
name: 'sendlogs',
|
|
|
|
|
component: () => import('../components/pages/sendLogs/SendLogs.vue')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'hostedmessage',
|
|
|
|
|
name: 'hostedmessage',
|
|
|
|
|
component: () => import('../components/pages/hostedMessage/HostedMessage.vue')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'settings',
|
|
|
|
|
name: 'settings',
|
|
|
|
|
component: () => import('../components/pages/settings/Settings.vue')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'sendways',
|
|
|
|
|
name: 'sendways',
|
|
|
|
|
component: () => import('../components/pages/sendWays/SendWays.vue')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'sendtasks',
|
|
|
|
|
name: 'sendtasks',
|
|
|
|
|
component: () => import('../components/pages/sendTasks/SendTasks.vue')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'cronmessages',
|
|
|
|
|
name: 'cronmessages',
|
|
|
|
|
component: () => import('../components/pages/cronMessages/CronMessages.vue')
|
|
|
|
|
}
|
|
|
|
|
]
|
2024-01-03 20:18:25 +08:00
|
|
|
},
|
2025-08-10 14:32:24 +08:00
|
|
|
// {
|
|
|
|
|
// path: '/settings',
|
|
|
|
|
// name: 'settings',
|
|
|
|
|
// component: () => import('../views/tabsTools/settings/settings.vue')
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// path: '/hostedMessage',
|
|
|
|
|
// name: 'hostedmessage',
|
|
|
|
|
// component: () => import('../views/tabsTools/hostedMessage/hostedMessage.vue')
|
|
|
|
|
// },
|
2025-09-20 14:18:02 +08:00
|
|
|
{
|
|
|
|
|
path: '/:catchAll(.*)',
|
|
|
|
|
name: '404',
|
|
|
|
|
component: () => import('../components/404.vue')
|
|
|
|
|
},
|
2023-12-30 17:40:20 +08:00
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 登录失效重定向到登录页面
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
2025-08-10 14:32:24 +08:00
|
|
|
const token = localStorage.getItem(CONSTANT.STORE_TOKEN_NAME);
|
|
|
|
|
const isAuthenticated = Boolean(token && token.trim() !== '');
|
|
|
|
|
|
2025-09-20 14:18:02 +08:00
|
|
|
// 404页面不需要登录验证
|
|
|
|
|
if (to.name === '404') {
|
|
|
|
|
next();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-10 14:32:24 +08:00
|
|
|
|
2023-12-30 17:40:20 +08:00
|
|
|
if (!isAuthenticated && to.path !== '/login') {
|
2025-08-10 14:32:24 +08:00
|
|
|
|
2023-12-30 17:40:20 +08:00
|
|
|
next('/login');
|
2025-08-10 14:32:24 +08:00
|
|
|
} else if (isAuthenticated && to.path === '/login') {
|
|
|
|
|
|
|
|
|
|
next('/');
|
2023-12-30 17:40:20 +08:00
|
|
|
} else {
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default router
|