演示

角色与权限

前端 RBAC 将菜单可见性与 Protected UI 绑定到与请求相同的 API 元数据。

withApiMetadataFetchFn

在 fetchFn 旁声明 url + method,确保权限校验与真实接口一致。

TSXapi
1import { withApiMetadataFetchFn } from "@quan-erp/shared-types"; 2 3export const getBranchApi = withApiMetadataFetchFn({ 4 api: { method: "GET", url: "/branch" }, 5 fetchFn: async () => { /* return payload */ }, 6});

受保护页面

用 <Protected requiredApis={getBranchApi} ...> 包裹页面,无权限用户看到受限占位而非坏掉的界面。