wsj
2026-10-17 5630cce7759c27d910fbeeec370a2e9f6b4b26b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { ReactNode } from 'react';
import { useAuthStore } from '@/store/auth';
 
interface PermissionProps {
  /** 不传表示不做权限限制 */
  permission?: string;
  fallback?: ReactNode;
  children: ReactNode;
}
 
/** 包裹任意 UI 的权限组件,适合控制菜单项、卡片、表格列等非按钮元素。 */
export default function Permission({
  permission,
  fallback = null,
  children,
}: PermissionProps) {
  const hasPermission = useAuthStore((state) => state.hasPermission);
 
  if (permission && !hasPermission(permission)) {
    return <>{fallback}</>;
  }
 
  return <>{children}</>;
}