dma_handbook/docs/.vuepress/utils/auth.js
2025-09-29 16:51:36 +08:00

34 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PERMISSIONS } from '../roles';
import axios from 'axios'
export function getCurrentUserRole() {
console.log('32-')
// 从store或localStorage获取用户角色
return localStorage.getItem('userRole') || 'coach';
}
export function checkPermission(currentRole, requiredPath) {
console.log(currentRole,PERMISSIONS)
// const rolePermissions = PERMISSIONS[currentRole] || [];
// console.log(rolePermissions,'rolePermissions=')
// return rolePermissions.includes('*') || rolePermissions.includes(requiredPath);
const allowedPaths = PERMISSIONS[currentRole] || [];
return allowedPaths.some(path =>
requiredPath.startsWith(path) || path === '*'
);
}
export function isLoggedIn() {
return !!localStorage.getItem('authToken');
}
export function showLoginModal() {
// 实现弹窗逻辑建议使用ElementUI等UI库
}
// 添加登录API调用方法
export async function login(credentials) {
const response = await axios.post('/api/login', credentials);
localStorage.setItem('authToken', response.data.token);
localStorage.setItem('userRole', response.data.role);
}