feat(client): improve code

This commit is contained in:
chenos 2022-01-30 19:31:00 +08:00
parent fd130901be
commit 218eb5ced3
6 changed files with 35 additions and 28 deletions

View File

@ -3,6 +3,7 @@ import {
Action, Action,
AdminLayout, AdminLayout,
AntdConfigProvider, AntdConfigProvider,
AntdSchemaComponentProvider,
APIClientProvider, APIClientProvider,
AuthLayout, AuthLayout,
CollectionManagerShortcut, CollectionManagerShortcut,
@ -36,6 +37,7 @@ const providers = [
{ components: { ACLShortcut, DesignableSwitch, CollectionManagerShortcut, SystemSettingsShortcut } }, { components: { ACLShortcut, DesignableSwitch, CollectionManagerShortcut, SystemSettingsShortcut } },
], ],
[SchemaComponentProvider, { components: { Page, Menu, Action } }], [SchemaComponentProvider, { components: { Page, Menu, Action } }],
AntdSchemaComponentProvider,
[DocumentTitleProvider, { addonAfter: 'NocoBase' }], [DocumentTitleProvider, { addonAfter: 'NocoBase' }],
[RouteSwitchProvider, { components: { AuthLayout, AdminLayout } }], [RouteSwitchProvider, { components: { AuthLayout, AdminLayout } }],
]; ];

View File

@ -1,8 +1,9 @@
import React, { useState } from 'react';
import { DatabaseOutlined } from '@ant-design/icons'; import { DatabaseOutlined } from '@ant-design/icons';
import { SchemaComponent, useActionVisible, VisibleContext } from '../schema-component';
import { ISchema, useForm } from '@formily/react'; import { ISchema, useForm } from '@formily/react';
import { uid } from '@formily/shared';
import React, { useState } from 'react';
import { PluginManager } from '../plugin-manager'; import { PluginManager } from '../plugin-manager';
import { SchemaComponent, useActionVisible, VisibleContext } from '../schema-component';
const useCloseAction = () => { const useCloseAction = () => {
const { setVisible } = useActionVisible(); const { setVisible } = useActionVisible();
@ -20,7 +21,7 @@ const useCloseAction = () => {
const schema: ISchema = { const schema: ISchema = {
type: 'object', type: 'object',
properties: { properties: {
drawer1: { [uid()]: {
'x-component': 'Action.Drawer', 'x-component': 'Action.Drawer',
type: 'void', type: 'void',
title: 'Drawer Title', title: 'Drawer Title',

View File

@ -1,10 +1,9 @@
import React, { createContext, useContext } from 'react'; import { MoreOutlined, SettingOutlined } from '@ant-design/icons';
import { Menu, Space, Tooltip, MenuItemProps } from 'antd'; import { ConfigProvider, Menu, MenuItemProps, Tooltip } from 'antd';
import { SettingOutlined, MoreOutlined, DesktopOutlined } from '@ant-design/icons';
import { get } from 'lodash';
import { PluginManagerContext } from './context';
import cls from 'classnames'; import cls from 'classnames';
import { ConfigProvider } from 'antd'; import { get } from 'lodash';
import React, { createContext, useContext } from 'react';
import { PluginManagerContext } from './context';
export const usePrefixCls = ( export const usePrefixCls = (
tag?: string, tag?: string,
@ -67,7 +66,7 @@ PluginManager.Toolbar = (props: ToolbarProps) => {
); );
})} })}
<Menu.Divider key={'divider'}></Menu.Divider> <Menu.Divider key={'divider'}></Menu.Divider>
<Menu.Item key={'plugins'} disabled icon={<SettingOutlined />}> <Menu.Item key={'plugins'} disabled icon={<SettingOutlined />}>
</Menu.Item> </Menu.Item>
</Menu.SubMenu> </Menu.SubMenu>

View File

@ -1,9 +1,9 @@
import { observer, RecursionField, useField, useFieldSchema } from '@formily/react';
import { Drawer } from 'antd';
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import { createPortal } from 'react-dom'; import { createPortal } from 'react-dom';
import { Drawer } from 'antd';
import { VisibleContext } from './context'; import { VisibleContext } from './context';
import { ComposedActionDrawer } from './types'; import { ComposedActionDrawer } from './types';
import { observer, RecursionField, useField, useFieldSchema } from '@formily/react';
export const ActionDrawer: ComposedActionDrawer = observer((props) => { export const ActionDrawer: ComposedActionDrawer = observer((props) => {
const [visible, setVisible] = useContext(VisibleContext); const [visible, setVisible] = useContext(VisibleContext);
@ -13,6 +13,7 @@ export const ActionDrawer: ComposedActionDrawer = observer((props) => {
<> <>
{createPortal( {createPortal(
<Drawer <Drawer
width={'50%'}
title={schema.title} title={schema.title}
{...props} {...props}
destroyOnClose destroyOnClose

View File

@ -12,7 +12,7 @@ import {
useFieldSchema useFieldSchema
} from '@formily/react'; } from '@formily/react';
import { toArr } from '@formily/shared'; import { toArr } from '@formily/shared';
import { Button, Drawer, Select, Tag } from 'antd'; import { Button, Drawer, Select, Space, Tag } from 'antd';
import React, { createContext, useContext, useMemo, useState } from 'react'; import React, { createContext, useContext, useMemo, useState } from 'react';
import { useAttach } from '../../hooks/useAttach'; import { useAttach } from '../../hooks/useAttach';
import { VisibleContext } from '../action'; import { VisibleContext } from '../action';
@ -54,28 +54,32 @@ const InputRecordPicker: React.FC = (props) => {
<FormContext.Provider value={form}> <FormContext.Provider value={form}>
<FieldContext.Provider value={f}> <FieldContext.Provider value={f}>
<Drawer <Drawer
width={'50%'}
placement={'right'} placement={'right'}
destroyOnClose destroyOnClose
visible={visible} visible={visible}
onClose={() => setVisible(false)} onClose={() => setVisible(false)}
footer={ footer={
<Button <Space style={{ justifyContent: 'flex-end', width: '100%' }}>
onClick={async () => { <Button
await form.submit(); type={'primary'}
setVisible(false); onClick={async () => {
}} await form.submit();
> setVisible(false);
}}
</Button> >
Submit
</Button>
</Space>
} }
> >
<RecursionField <RecursionField
onlyRenderProperties onlyRenderProperties
basePath={f.address} basePath={f.address}
schema={fieldSchema} schema={fieldSchema}
filterProperties={(s) => { // filterProperties={(s) => {
return s['x-component'] === 'RowSelection'; // return s['x-component'] === 'RowSelection';
}} // }}
/> />
</Drawer> </Drawer>
</FieldContext.Provider> </FieldContext.Provider>

View File

@ -1,9 +1,9 @@
import { Menu } from 'antd';
import React, { useState } from 'react';
import { SettingOutlined } from '@ant-design/icons'; import { SettingOutlined } from '@ant-design/icons';
import { SchemaComponent, useActionVisible, VisibleContext } from '../schema-component';
import { ISchema, useForm } from '@formily/react'; import { ISchema, useForm } from '@formily/react';
import { uid } from '@formily/shared';
import React, { useState } from 'react';
import { PluginManager } from '..'; import { PluginManager } from '..';
import { SchemaComponent, useActionVisible, VisibleContext } from '../schema-component';
const useCloseAction = () => { const useCloseAction = () => {
const { setVisible } = useActionVisible(); const { setVisible } = useActionVisible();
@ -21,7 +21,7 @@ const useCloseAction = () => {
const schema: ISchema = { const schema: ISchema = {
type: 'object', type: 'object',
properties: { properties: {
drawer1: { [uid()]: {
'x-component': 'Action.Drawer', 'x-component': 'Action.Drawer',
type: 'void', type: 'void',
title: 'Drawer Title', title: 'Drawer Title',