feat(web): 迁移前端源代码(任务 T4.1)
- 删除 novalon 前端 src/ 下所有文件 - 从 gym-manage 复制前端 src/ 完整目录树 - 替换 gym-manage-api → novalon-manage-api - 替换 gym_system → manage_system - 无 gym 残留引用
This commit is contained in:
@@ -21,20 +21,28 @@ const permissionMapping: PermissionMapping = {
|
||||
'POST /dict': 'system:dict:add',
|
||||
'PUT /dict': 'system:dict:edit',
|
||||
'DELETE /dict': 'system:dict:remove',
|
||||
'GET /config': 'system:config:list',
|
||||
'POST /config': 'system:config:list',
|
||||
'PUT /config': 'system:config:list',
|
||||
'DELETE /config': 'system:config:list',
|
||||
'GET /sys/config': 'system:config:list',
|
||||
'POST /sys/config': 'system:config:add',
|
||||
'PUT /sys/config': 'system:config:edit',
|
||||
'DELETE /sys/config': 'system:config:remove',
|
||||
'POST /sys/config': 'system:config:list',
|
||||
'PUT /sys/config': 'system:config:list',
|
||||
'DELETE /sys/config': 'system:config:list',
|
||||
'GET /files': 'system:file:list',
|
||||
'POST /files': 'system:file:upload',
|
||||
'DELETE /files': 'system:file:delete',
|
||||
}
|
||||
|
||||
export function checkApiPermission(method: string, url: string): boolean {
|
||||
const permissionStore = usePermissionStore()
|
||||
|
||||
const key = `${method.toUpperCase()} ${url.split('?')[0]}`
|
||||
const requiredPermission = permissionMapping[key]
|
||||
let requiredPermission = permissionMapping[key]
|
||||
|
||||
if (!requiredPermission) {
|
||||
const baseUrl = url.split('?')[0].replace(/\/\d+$/, '')
|
||||
const baseKey = `${method.toUpperCase()} ${baseUrl}`
|
||||
requiredPermission = permissionMapping[baseKey]
|
||||
}
|
||||
|
||||
if (!requiredPermission) {
|
||||
return true
|
||||
@@ -44,11 +52,24 @@ export function checkApiPermission(method: string, url: string): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
if (Array.isArray(requiredPermission)) {
|
||||
return requiredPermission.some(p => permissionStore.hasPermission(p))
|
||||
const stored = localStorage.getItem('permission')
|
||||
if (!stored) {
|
||||
return true
|
||||
}
|
||||
|
||||
return permissionStore.hasPermission(requiredPermission)
|
||||
try {
|
||||
const data = JSON.parse(stored)
|
||||
const permissions = data.permissions || []
|
||||
|
||||
if (Array.isArray(requiredPermission)) {
|
||||
return requiredPermission.some(p => permissions.includes(p))
|
||||
}
|
||||
|
||||
return permissions.includes(requiredPermission)
|
||||
} catch (error) {
|
||||
console.error('解析权限数据失败:', error)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export function getRequiredPermission(method: string, url: string): string | string[] | null {
|
||||
|
||||
Reference in New Issue
Block a user