refactor(frontend): P3 — K8s 组件拆分、AlertCenter Query、permission utils
- 拆分 DeploymentView / DeploymentDetail 至子目录(<700 行红线) - AlertCenter 接入 useAlerts / useAgentAlertRules / useAlertMutations - 新增 utils/permission.ts,usePermission 复用纯函数 - useAlerts 增强分页统计与 Agent 规则 hooks
This commit is contained in:
1 parent
37c657987b
commit
521bfd356f
24 files changed
+1454
-1221
No files matched your search
@@ -43,4 +43,12 @@ export {
|
||||
isValidHostname,
|
||||
isValidUrl,
|
||||
parsePortList,
|
||||
} from './validate';
|
||||
} from './validate';
|
||||
|
||||
export {
|
||||
PERMISSION_WILDCARD,
|
||||
isWildcardAdmin,
|
||||
checkPermission,
|
||||
checkAnyPermission,
|
||||
checkAllPermissions,
|
||||
} from './permission';
|
||||
@@ -0,0 +1,38 @@
|
||||
// 权限码常量与纯函数 — 供 hooks/usePermission 复用 // Logan.Li
|
||||
|
||||
export const PERMISSION_WILDCARD = '*';
|
||||
|
||||
/** 是否拥有通配符(超级管理员) */
|
||||
export function isWildcardAdmin(permissions: string[] | null | undefined): boolean {
|
||||
return permissions?.includes(PERMISSION_WILDCARD) ?? false;
|
||||
}
|
||||
|
||||
/** 检查单个权限码 */
|
||||
export function checkPermission(
|
||||
permissions: string[] | null | undefined,
|
||||
code: string,
|
||||
): boolean {
|
||||
if (permissions === null || permissions === undefined) return true;
|
||||
if (isWildcardAdmin(permissions)) return true;
|
||||
return permissions.includes(code);
|
||||
}
|
||||
|
||||
/** OR 逻辑 */
|
||||
export function checkAnyPermission(
|
||||
permissions: string[] | null | undefined,
|
||||
codes: string[],
|
||||
): boolean {
|
||||
if (permissions === null || permissions === undefined) return true;
|
||||
if (isWildcardAdmin(permissions)) return true;
|
||||
return codes.some((c) => permissions.includes(c));
|
||||
}
|
||||
|
||||
/** AND 逻辑 */
|
||||
export function checkAllPermissions(
|
||||
permissions: string[] | null | undefined,
|
||||
codes: string[],
|
||||
): boolean {
|
||||
if (permissions === null || permissions === undefined) return true;
|
||||
if (isWildcardAdmin(permissions)) return true;
|
||||
return codes.every((c) => permissions.includes(c));
|
||||
}
|
||||
Reference in new issue
Block a user