docs/docs/cn/users-permissions/acl/dev/permission-tab.md
下面以“移动端菜单”配置项为例,演示如何扩展一个新的权限配置栏。效果如下图所示:
代码如下:
import { Plugin } from '@nocobase/client';
import PluginACLClient from '@nocobase/plugin-acl/client';
class PluginMobileClient extends Plugin {
async load() {
const aclInstance = this.app.pm.get(PluginACLClient);
aclInstance?.settingsUI.addPermissionsTab(({ t, TabLayout, activeKey }) => ({
key: 'mobile-menu',
label: t('Mobile menu', {
ns: 'plugin-mobile',
}),
children: (
<TabLayout>
<MenuPermissions />
</TabLayout>
),
}));
}
}
首先,我们需要获取到 PluginACLClient 插件的实例(获取插件实例的其它方法),通过 settingsUI.addPermissionsTab 方法添加一个新的权限配置栏。在这个例子中,我们添加了一个名为“移动端菜单”的权限配置栏。
settingsUI 属性的值是一个名为 ACLSettingsUI 的类的实例,其类型信息如下:
import { TabsProps } from 'antd/es/tabs/index';
interface ACLSettingsUI {
addPermissionsTab(tab: Tab | TabCallback): void;
getPermissionsTabs(props: PermissionsTabsProps): Tab[];
}
type Tab = TabsProps['items'][0];
type TabCallback = (props: PermissionsTabsProps) => Tab;
interface PermissionsTabsProps {
/**
* the key of the currently active tab panel
*/
activeKey: string;
/**
* the currently selected role
*/
role: Role;
/**
* translation function
*/
t: TFunction;
/**
* used to constrain the size of the container in the Tab
*/
TabLayout: React.FC;
}