34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
|
|
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);
|
|||
|
|
}
|