diff --git a/packages/client/src/acl/ACLAction.tsx b/packages/client/src/acl/ACLShortcut.tsx similarity index 87% rename from packages/client/src/acl/ACLAction.tsx rename to packages/client/src/acl/ACLShortcut.tsx index 81fa48321..dc930d74f 100644 --- a/packages/client/src/acl/ACLAction.tsx +++ b/packages/client/src/acl/ACLShortcut.tsx @@ -1,8 +1,8 @@ -import { Menu } from 'antd'; import React, { useState } from 'react'; import { LockOutlined } from '@ant-design/icons'; import { SchemaComponent, useActionVisible, VisibleContext } from '../schema-component'; import { ISchema, useForm } from '@formily/react'; +import { PluginManager } from '../plugin-manager'; const useCloseAction = () => { const { setVisible } = useActionVisible(); @@ -47,18 +47,17 @@ const schema: ISchema = { }, }; -export const ACLAction = () => { +export const ACLShortcut = () => { const [visible, setVisible] = useState(false); return ( - } + title={'角色和权限'} onClick={() => { setVisible(true); }} - > - - + /> ); diff --git a/packages/client/src/acl/index.tsx b/packages/client/src/acl/index.tsx index c5f671c00..eb4cb16c4 100644 --- a/packages/client/src/acl/index.tsx +++ b/packages/client/src/acl/index.tsx @@ -1,3 +1,3 @@ export * from './ACLProvider'; export * from './RolePermissionManager'; -export * from './ACLAction'; +export * from './ACLShortcut'; diff --git a/packages/client/src/application/demos/demo2/index.tsx b/packages/client/src/application/demos/demo2/index.tsx index da6d304b7..137eef4e7 100644 --- a/packages/client/src/application/demos/demo2/index.tsx +++ b/packages/client/src/application/demos/demo2/index.tsx @@ -13,6 +13,11 @@ import { SchemaComponentProvider, Menu, Action, + PluginManagerProvider, + DesignableSwitch, + CollectionManagerShortcut, + ACLShortcut, + SystemSettingsShortcut, } from '@nocobase/client'; import { I18nextProvider } from 'react-i18next'; import { Spin } from 'antd'; @@ -24,6 +29,10 @@ const providers = [ [APIClientProvider, { apiClient }], [I18nextProvider, { i18n }], [AntdConfigProvider, { remoteLocale: true }], + [ + PluginManagerProvider, + { components: { ACLShortcut, DesignableSwitch, CollectionManagerShortcut, SystemSettingsShortcut } }, + ], [SchemaComponentProvider, { components: { Menu, Action } }], [RouteSwitchProvider, { components: { AuthLayout, AdminLayout } }], ]; diff --git a/packages/client/src/collection-manager/CollectionManagerAction.tsx b/packages/client/src/collection-manager/CollectionManagerShortcut.tsx similarity index 86% rename from packages/client/src/collection-manager/CollectionManagerAction.tsx rename to packages/client/src/collection-manager/CollectionManagerShortcut.tsx index 819be2203..22f4c777c 100644 --- a/packages/client/src/collection-manager/CollectionManagerAction.tsx +++ b/packages/client/src/collection-manager/CollectionManagerShortcut.tsx @@ -1,8 +1,8 @@ -import { Menu } from 'antd'; import React, { useState } from 'react'; import { DatabaseOutlined } from '@ant-design/icons'; import { SchemaComponent, useActionVisible, VisibleContext } from '../schema-component'; import { ISchema, useForm } from '@formily/react'; +import { PluginManager } from '../plugin-manager'; const useCloseAction = () => { const { setVisible } = useActionVisible(); @@ -47,18 +47,17 @@ const schema: ISchema = { }, }; -export const CollectionManagerAction = () => { +export const CollectionManagerShortcut = () => { const [visible, setVisible] = useState(false); return ( - } + title={'数据表配置'} onClick={() => { setVisible(true); }} - > - - + /> ); diff --git a/packages/client/src/collection-manager/index.tsx b/packages/client/src/collection-manager/index.tsx index a0962f948..dcf55241c 100644 --- a/packages/client/src/collection-manager/index.tsx +++ b/packages/client/src/collection-manager/index.tsx @@ -5,4 +5,4 @@ export * from './context'; export * from './hooks'; export * from './types'; export * from './CollectionField'; -export * from './CollectionManagerAction'; +export * from './CollectionManagerShortcut'; diff --git a/packages/client/src/current-user/index.tsx b/packages/client/src/current-user/index.tsx index 616b8fb13..103358d05 100644 --- a/packages/client/src/current-user/index.tsx +++ b/packages/client/src/current-user/index.tsx @@ -7,13 +7,16 @@ export const CurrentUser = () => null; CurrentUser.Dropdown = () => { return ( - // @ts-ignore - - - 切换角色 - 语言设置 - - 注销 - +
+ + + + 切换角色 + 语言设置 + + 注销 + + +
); }; diff --git a/packages/client/src/plugin-manager/PluginManager.tsx b/packages/client/src/plugin-manager/PluginManager.tsx index e2af0f622..fb46b0dbc 100644 --- a/packages/client/src/plugin-manager/PluginManager.tsx +++ b/packages/client/src/plugin-manager/PluginManager.tsx @@ -1,18 +1,41 @@ import React, { createContext, useContext } from 'react'; -import { Menu, Space, Tooltip } from 'antd'; +import { Menu, Space, Tooltip, MenuItemProps } from 'antd'; import { SettingOutlined, MoreOutlined, DesktopOutlined } from '@ant-design/icons'; -import { CurrentUser, DesignableSwitch, CollectionManagerAction, ACLAction, SystemSettings } from '../'; import { get } from 'lodash'; -import { PluginManagerContext, PluginManagerProvider } from '.'; +import { PluginManagerContext } from './context'; +import cls from 'classnames'; +import { ConfigProvider } from 'antd'; -// TODO -export const PluginManager: any = () => null; +export const usePrefixCls = ( + tag?: string, + props?: { + prefixCls?: string; + }, +) => { + const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); + return getPrefixCls(tag, props?.prefixCls); +}; -PluginManager.Provider = PluginManagerProvider; +type PluginManagerType = { + Toolbar?: React.FC & { + Item?: React.FC; + }; +}; -const ToolbarItemContext = createContext(null); +export const PluginManager: PluginManagerType = () => null; -PluginManager.Toolbar = (props: any) => { +const ToolbarItemContext = createContext(null); + +interface ToolbarProps { + items?: ToolbarItemProps[]; +} + +interface ToolbarItemProps { + component: string; + pin?: boolean; +} + +PluginManager.Toolbar = (props: ToolbarProps) => { const { components } = useContext(PluginManagerContext); const { items = [] } = props; return ( @@ -44,7 +67,9 @@ PluginManager.Toolbar = (props: any) => { ); })} - }>管理插件 + }> + 管理插件 + @@ -53,18 +78,20 @@ PluginManager.Toolbar = (props: any) => { PluginManager.Toolbar.Item = (props) => { const item = useContext(ToolbarItemContext); - const { icon, title, ...others } = props; + const { selected, icon, title, ...others } = props; + const prefix = usePrefixCls(); + const className = cls({ [`${prefix}-menu-item-selected`]: selected }); if (item.pin) { return ( - + {icon} ); } return ( - + {title} ); diff --git a/packages/client/src/plugin-manager/demos/plugins/plugin1.tsx b/packages/client/src/plugin-manager/demos/plugins/plugin1.tsx index 9447a87f6..054aa35c5 100644 --- a/packages/client/src/plugin-manager/demos/plugins/plugin1.tsx +++ b/packages/client/src/plugin-manager/demos/plugins/plugin1.tsx @@ -1,6 +1,5 @@ -import { Menu } from 'antd'; import React from 'react'; -import { SaveOutlined, KeyOutlined, DatabaseOutlined, VerifiedOutlined, NotificationOutlined } from '@ant-design/icons'; +import { DatabaseOutlined } from '@ant-design/icons'; import { PluginManager } from '@nocobase/client'; export const Plugin1 = () => null; diff --git a/packages/client/src/route-switch/antd/admin-layout/index.tsx b/packages/client/src/route-switch/antd/admin-layout/index.tsx index ff5601eaa..0ad940f76 100644 --- a/packages/client/src/route-switch/antd/admin-layout/index.tsx +++ b/packages/client/src/route-switch/antd/admin-layout/index.tsx @@ -1,8 +1,8 @@ import React, { useRef, useState } from 'react'; -import { Layout } from 'antd'; +import { Button, Layout } from 'antd'; import { useRoute } from '../../hooks'; import { useHistory, useRouteMatch } from 'react-router-dom'; -import { findMenuItem, RemoteSchemaComponent, PluginManager } from '../../../'; +import { findMenuItem, RemoteSchemaComponent, PluginManager, CurrentUser } from '../../../'; export function AdminLayout(props: any) { const route = useRoute(); @@ -44,7 +44,15 @@ export function AdminLayout(props: any) { />
- + +
diff --git a/packages/client/src/schema-component/components/DesignableSwitch.tsx b/packages/client/src/schema-component/components/DesignableSwitch.tsx index 6ca36d53c..2cb82073c 100644 --- a/packages/client/src/schema-component/components/DesignableSwitch.tsx +++ b/packages/client/src/schema-component/components/DesignableSwitch.tsx @@ -3,12 +3,18 @@ import { Button, Menu } from 'antd'; import { HighlightOutlined } from '@ant-design/icons'; import cls from 'classnames'; import { useDesignable } from '..'; +import { PluginManager } from '../../plugin-manager'; export const DesignableSwitch = () => { const { designable, setDesignable } = useDesignable(); return ( - - - + } + title={'界面配置'} + onClick={() => { + setDesignable(!designable); + }} + > ); }; diff --git a/packages/client/src/system-settings/SystemSettingsAction.tsx b/packages/client/src/system-settings/SystemSettingsShortcut.tsx similarity index 85% rename from packages/client/src/system-settings/SystemSettingsAction.tsx rename to packages/client/src/system-settings/SystemSettingsShortcut.tsx index 5acbb4dad..91cb6df01 100644 --- a/packages/client/src/system-settings/SystemSettingsAction.tsx +++ b/packages/client/src/system-settings/SystemSettingsShortcut.tsx @@ -1,8 +1,9 @@ import { Menu } from 'antd'; import React, { useState } from 'react'; -import { LockOutlined } from '@ant-design/icons'; +import { SettingOutlined } from '@ant-design/icons'; import { SchemaComponent, useActionVisible, VisibleContext } from '../schema-component'; import { ISchema, useForm } from '@formily/react'; +import { PluginManager } from '..'; const useCloseAction = () => { const { setVisible } = useActionVisible(); @@ -47,18 +48,18 @@ const schema: ISchema = { }, }; -export const SystemSettingsAction = () => { +export const SystemSettingsShortcut = () => { const [visible, setVisible] = useState(false); return ( - { setVisible(true); }} - > - 系统设置 - + icon={} + title={'系统设置'} + /> ); diff --git a/packages/client/src/system-settings/index.tsx b/packages/client/src/system-settings/index.tsx index 645bbd698..e1f4f1820 100644 --- a/packages/client/src/system-settings/index.tsx +++ b/packages/client/src/system-settings/index.tsx @@ -1,5 +1 @@ -import { SystemSettingsAction } from './SystemSettingsAction'; - -export const SystemSettings = () => null; - -SystemSettings.Action = SystemSettingsAction; +export * from './SystemSettingsShortcut';