✅ auth.ts: 认证相关状态管理
✅ user.ts: 用户信息管理
src/
├── pages/
│ ├── login/
│ │ └── login.vue # 登录页面
│ └── index/
│ └── index.vue # 主页面(已集成登录状态)
├── store/
│ ├── index.ts # Store 入口
│ └── modules/
│ ├── auth.ts # 认证状态管理
│ └── user.ts # 用户信息管理
├── utils/
│ ├── routeGuard.ts # 路由守卫
│ └── loginHelper.ts # 登录工具函数
├── config/
│ └── loginConfig.ts # 登录配置
├── App.vue # 应用入口(已集成自动登录)
└── pages.json # 页面路由配置
{
enableCaptcha: false, // 是否启用验证码
enableRememberMe: true, // 是否启用记住我
autoLoginTimeout: 5000, // 自动登录超时
tokenRefreshInterval: 1800000, // Token刷新间隔
maxLoginRetries: 3 // 最大重试次数
}
{
loginPath: '/pages/login/login',
homePath: '/pages/index/index',
publicPages: [...], // 无需登录页面
adminPages: [...] // 管理员页面
}
import { useAuthStore } from '@/store/modules/auth';
const authStore = useAuthStore();
const success = await authStore.login({
username: 'admin',
password: '123456'
});
import { useUserStore } from '@/store/modules/user';
const userStore = useUserStore();
const hasPermission = userStore.hasPermission('user:create');
const hasRole = userStore.hasRole('admin');
import { navigateWithAuth } from '@/utils/routeGuard';
// 需要登录的页面跳转
navigateWithAuth('/pages/profile/profile');
import { quickLogin, getUserDisplayName } from '@/utils/loginHelper';
// 快速登录
await quickLogin('username', 'password');
// 获取用户显示名称
const displayName = getUserDisplayName();
所有功能都已完全 TypeScript 化:
项目现在具备了完整的登录认证系统,支持现代化的用户体验和企业级的安全特性!