AriStockAI/services/frontend/src/router/index.js
fanfpy deaba87362 feat: 重构前端架构并添加核心功能
- 新增Pinia状态管理用于用户认证和全局状态
- 实现JWT认证工具类和API服务封装
- 添加路由权限控制和全局错误处理
- 重构项目结构,新增layouts目录和组件
- 完善工具函数库和常量定义
- 新增404页面和API接口模块
- 优化移动端导航和响应式布局
- 更新依赖并添加开发工具支持
2025-07-18 16:13:23 +08:00

138 lines
3.1 KiB
JavaScript

import { createRouter, createWebHistory } from 'vue-router';
import MainLayout from '@/layouts/MainLayout.vue';
import Index from '@/views/public/Index.vue';
import Login from '@/views/public/Login.vue';
import SignUp from '@/views/public/SignUp.vue';
import Dashboard from '@/views/private/Dashboard.vue';
import AiInvestment from '@/views/private/AiInvestment.vue';
import StockMarket from '@/views/private/StockMarket.vue';
import EarningsPrediction from '@/views/private/EarningsPrediction.vue';
import TradingNews from '@/views/private/TradingNews.vue';
import History from '@/views/private/History.vue';
import NotFoundView from '@/views/NotFoundView.vue';
const routes = [
{
path: '/',
name: 'Index',
component: Index,
meta: {
title: 'AriStockAI - 智能股票投资平台',
requiresAuth: false
}
},
{
path: '/app',
name: 'App',
component: MainLayout,
meta: {
requiresAuth: true
},
children: [
{
path: 'dashboard',
name: 'Dashboard',
component: Dashboard,
meta: {
title: '仪表盘'
}
},
{
path: 'ai-investment',
name: 'AiInvestment',
component: AiInvestment,
meta: {
title: 'AI投资'
}
},
{
path: 'stock-market',
name: 'StockMarket',
component: StockMarket,
meta: {
title: '股票市场'
}
},
{
path: 'earnings-prediction',
name: 'EarningsPrediction',
component: EarningsPrediction,
meta: {
title: '收益预测'
}
},
{
path: 'trading-news',
name: 'TradingNews',
component: TradingNews,
meta: {
title: '交易新闻'
}
},
{
path: 'history',
name: 'History',
component: History,
meta: {
title: '历史记录'
}
}
]
},
{
path: '/login',
name: 'Login',
component: Login,
meta: {
title: '登录',
requiresAuth: false
},
beforeEnter: (to, from, next) => {
if (localStorage.getItem('isLoggedIn') === 'true') {
next('/app/dashboard');
} else {
next();
}
}
},
{
path: '/sign-up',
name: 'SignUp',
component: SignUp,
meta: {
title: '注册',
requiresAuth: false
}
},
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: NotFoundView,
meta: {
title: '页面未找到',
requiresAuth: false
}
}
];
const router = createRouter({
history: createWebHistory(),
routes
})
// 全局前置守卫
router.beforeEach((to, from, next) => {
// 设置页面标题
document.title = to.meta.title ? `${to.meta.title} - AriStockAI` : 'AriStockAI';
// 权限检查 - 暂时注释未定义的permission调用
// permission.routeGuard(to, from, next);
next(); // 直接放行
});
// 全局后置钩子
router.afterEach((to, from) => {
console.log(`Route changed from ${from.name || 'null'} to ${to.name}`);
})
export default router;