mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:37:01 +00:00
feat: improve code
This commit is contained in:
parent
ad700c61b8
commit
c410c188a3
@ -37,6 +37,7 @@ const api = new Application({
|
||||
});
|
||||
|
||||
const plugins = [
|
||||
'@nocobase/plugin-error-handler',
|
||||
'@nocobase/plugin-collection-manager',
|
||||
'@nocobase/plugin-ui-schema-storage',
|
||||
'@nocobase/plugin-ui-routes-storage',
|
||||
|
@ -2,6 +2,7 @@ import { LockOutlined } from '@ant-design/icons';
|
||||
import { ISchema, useForm } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { PluginManager } from '../plugin-manager';
|
||||
import { ActionContext, SchemaComponent, useActionContext } from '../schema-component';
|
||||
import * as components from './Configuration';
|
||||
@ -25,7 +26,7 @@ const schema: ISchema = {
|
||||
[uid()]: {
|
||||
'x-component': 'Action.Drawer',
|
||||
type: 'void',
|
||||
title: '角色配置',
|
||||
title: '{{t("Roles & Permissions")}}',
|
||||
properties: {
|
||||
hello1: {
|
||||
type: 'void',
|
||||
@ -38,11 +39,12 @@ const schema: ISchema = {
|
||||
|
||||
export const ACLShortcut = () => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<ActionContext.Provider value={{ visible, setVisible }}>
|
||||
<PluginManager.Toolbar.Item
|
||||
icon={<LockOutlined />}
|
||||
title={'角色和权限'}
|
||||
title={t('Roles & Permissions')}
|
||||
onClick={() => {
|
||||
setVisible(true);
|
||||
}}
|
||||
|
@ -2,6 +2,7 @@ import { DatabaseOutlined } from '@ant-design/icons';
|
||||
import { ISchema } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { PluginManager } from '../plugin-manager';
|
||||
import { ActionContext, SchemaComponent } from '../schema-component';
|
||||
import { AddFieldAction, ConfigurationTable, EditFieldAction } from './Configuration';
|
||||
@ -12,7 +13,7 @@ const schema: ISchema = {
|
||||
[uid()]: {
|
||||
'x-component': 'Action.Drawer',
|
||||
type: 'void',
|
||||
title: '数据表配置',
|
||||
title: '{{t("Collections & Fields")}}',
|
||||
properties: {
|
||||
configuration: {
|
||||
'x-component': 'ConfigurationTable',
|
||||
@ -24,11 +25,12 @@ const schema: ISchema = {
|
||||
|
||||
export const CollectionManagerShortcut = () => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<ActionContext.Provider value={{ visible, setVisible }}>
|
||||
<PluginManager.Toolbar.Item
|
||||
icon={<DatabaseOutlined />}
|
||||
title={'数据表配置'}
|
||||
title={t('Collections & Fields')}
|
||||
onClick={() => {
|
||||
setVisible(true);
|
||||
}}
|
||||
|
@ -5,6 +5,7 @@ import { uid } from '@formily/shared';
|
||||
import { Button, Dropdown, Menu } from 'antd';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useRequest } from '../../api-client';
|
||||
import { ActionContext, SchemaComponent, useCompile } from '../../schema-component';
|
||||
import { useCreateAction } from '../action-hooks';
|
||||
@ -102,6 +103,7 @@ export const AddFieldAction = () => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [schema, setSchema] = useState({});
|
||||
const compile = useCompile();
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<ActionContext.Provider value={{ visible, setVisible }}>
|
||||
<Dropdown
|
||||
@ -132,7 +134,7 @@ export const AddFieldAction = () => {
|
||||
}
|
||||
>
|
||||
<Button icon={<PlusOutlined />} type={'primary'}>
|
||||
添加字段
|
||||
{t('Add field')}
|
||||
</Button>
|
||||
</Dropdown>
|
||||
<SchemaComponent schema={schema} components={{ ArrayTable }} scope={{ useCreateCollectionField }} />
|
||||
|
@ -5,6 +5,7 @@ import { uid } from '@formily/shared';
|
||||
import { Button, Dropdown, Menu } from 'antd';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useRequest } from '../../api-client';
|
||||
import { RecordProvider } from '../../record-provider';
|
||||
import { ActionContext, SchemaComponent, useActionContext, useCompile } from '../../schema-component';
|
||||
@ -98,6 +99,7 @@ export const AddSubFieldAction = () => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [schema, setSchema] = useState({});
|
||||
const compile = useCompile();
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<ActionContext.Provider value={{ visible, setVisible }}>
|
||||
<Dropdown
|
||||
@ -122,7 +124,7 @@ export const AddSubFieldAction = () => {
|
||||
}
|
||||
>
|
||||
<Button icon={<PlusOutlined />} type={'primary'}>
|
||||
添加字段
|
||||
{t('Add field')}
|
||||
</Button>
|
||||
</Dropdown>
|
||||
<RecordProvider record={{}}>
|
||||
|
@ -1,10 +1,12 @@
|
||||
import { ISchema, useField, useFieldSchema } from '@formily/react';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { GeneralSchemaDesigner, SchemaSettings, useDesignable } from '../../../';
|
||||
|
||||
const InsertMenuItems = (props) => {
|
||||
const { dn, refresh } = useDesignable();
|
||||
const { eventKey, title, insertPosition } = props;
|
||||
const { t } = useTranslation();
|
||||
const { dn } = useDesignable();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const isSubMenu = fieldSchema['x-component'] === 'Menu.SubMenu';
|
||||
if (!isSubMenu && insertPosition === 'beforeEnd') {
|
||||
@ -14,21 +16,21 @@ const InsertMenuItems = (props) => {
|
||||
<SchemaSettings.SubMenu eventKey={eventKey} title={title}>
|
||||
<SchemaSettings.ModalItem
|
||||
eventKey={`${insertPosition}group`}
|
||||
title={'分组'}
|
||||
title={t('Group')}
|
||||
schema={
|
||||
{
|
||||
type: 'object',
|
||||
title: `${title}分组`,
|
||||
title: t('Add group'),
|
||||
properties: {
|
||||
title: {
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Input',
|
||||
title: '分组名称',
|
||||
title: t('Menu item title'),
|
||||
'x-component-props': {},
|
||||
// description: `原字段标题:${collectionField?.uiSchema?.title}`,
|
||||
},
|
||||
icon: {
|
||||
title: '图标',
|
||||
title: t('Icon'),
|
||||
'x-component': 'IconPicker',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
@ -48,21 +50,20 @@ const InsertMenuItems = (props) => {
|
||||
/>
|
||||
<SchemaSettings.ModalItem
|
||||
eventKey={`${insertPosition}page`}
|
||||
title={'页面'}
|
||||
title={t('Page')}
|
||||
schema={
|
||||
{
|
||||
type: 'object',
|
||||
title: `${title}页面`,
|
||||
title: t('Add page'),
|
||||
properties: {
|
||||
title: {
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Input',
|
||||
title: '菜单项名称',
|
||||
title: t('Menu item title'),
|
||||
'x-component-props': {},
|
||||
// description: `原字段标题:${collectionField?.uiSchema?.title}`,
|
||||
},
|
||||
icon: {
|
||||
title: '图标',
|
||||
title: t('Icon'),
|
||||
'x-component': 'IconPicker',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
@ -97,27 +98,27 @@ const InsertMenuItems = (props) => {
|
||||
/>
|
||||
<SchemaSettings.ModalItem
|
||||
eventKey={`${insertPosition}link`}
|
||||
title={'链接'}
|
||||
title={t('Link')}
|
||||
schema={
|
||||
{
|
||||
type: 'object',
|
||||
title: `${title}链接`,
|
||||
title: t('Add link'),
|
||||
properties: {
|
||||
title: {
|
||||
title: '链接文字',
|
||||
'x-component': 'Input',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
href: {
|
||||
title: '链接',
|
||||
title: t('Menu item title'),
|
||||
'x-component': 'Input',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
icon: {
|
||||
title: '图标',
|
||||
title: t('Icon'),
|
||||
'x-component': 'IconPicker',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
href: {
|
||||
title: t('Link'),
|
||||
'x-component': 'Input',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
},
|
||||
} as ISchema
|
||||
}
|
||||
@ -141,24 +142,24 @@ export const MenuDesigner = () => {
|
||||
const field = useField();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { dn, refresh } = useDesignable();
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<GeneralSchemaDesigner>
|
||||
<SchemaSettings.ModalItem
|
||||
title={'编辑'}
|
||||
title={t('Edit')}
|
||||
schema={
|
||||
{
|
||||
type: 'object',
|
||||
title: '编辑菜单项',
|
||||
title: t('Edit menu item'),
|
||||
properties: {
|
||||
title: {
|
||||
title: t('Menu item title'),
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Input',
|
||||
title: '菜单项名称',
|
||||
'x-component-props': {},
|
||||
// description: `原字段标题:${collectionField?.uiSchema?.title}`,
|
||||
},
|
||||
icon: {
|
||||
title: '图标',
|
||||
title: t('Menu item icon'),
|
||||
'x-component': 'IconPicker',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
@ -189,11 +190,15 @@ export const MenuDesigner = () => {
|
||||
}}
|
||||
/>
|
||||
<SchemaSettings.Divider />
|
||||
<InsertMenuItems eventKey={'insertbeforeBegin'} title={'在前面插入'} insertPosition={'beforeBegin'} />
|
||||
<InsertMenuItems eventKey={'insertafterEnd'} title={'在后面插入'} insertPosition={'afterEnd'} />
|
||||
<InsertMenuItems eventKey={'insertbeforeEnd'} title={'在里面插入'} insertPosition={'beforeEnd'} />
|
||||
<InsertMenuItems eventKey={'insertbeforeBegin'} title={t('Insert before')} insertPosition={'beforeBegin'} />
|
||||
<InsertMenuItems eventKey={'insertafterEnd'} title={t('Insert after')} insertPosition={'afterEnd'} />
|
||||
<InsertMenuItems eventKey={'insertbeforeEnd'} title={t('Insert inner')} insertPosition={'beforeEnd'} />
|
||||
<SchemaSettings.Divider />
|
||||
<SchemaSettings.Remove />
|
||||
<SchemaSettings.Remove
|
||||
confirm={{
|
||||
title: t('Delete menu item'),
|
||||
}}
|
||||
/>
|
||||
</GeneralSchemaDesigner>
|
||||
);
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ export const GroupItem = itemWrap((props) => {
|
||||
<SchemaInitializer.Item
|
||||
{...props}
|
||||
onClick={async () => {
|
||||
const values = await FormDialog('添加分组', () => {
|
||||
const values = await FormDialog(t('Add group'), () => {
|
||||
return (
|
||||
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
||||
<FormLayout layout={'vertical'}>
|
||||
@ -54,12 +54,12 @@ export const GroupItem = itemWrap((props) => {
|
||||
schema={{
|
||||
properties: {
|
||||
title: {
|
||||
title: '分组标题',
|
||||
title: t('Menu item title'),
|
||||
'x-component': 'Input',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
icon: {
|
||||
title: '图标',
|
||||
title: t('Icon'),
|
||||
'x-component': 'IconPicker',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
@ -94,7 +94,7 @@ export const PageMenuItem = itemWrap((props) => {
|
||||
<SchemaInitializer.Item
|
||||
{...props}
|
||||
onClick={async () => {
|
||||
const values = await FormDialog('添加页面', () => {
|
||||
const values = await FormDialog(t('Add page'), () => {
|
||||
return (
|
||||
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
||||
<FormLayout layout={'vertical'}>
|
||||
@ -102,12 +102,12 @@ export const PageMenuItem = itemWrap((props) => {
|
||||
schema={{
|
||||
properties: {
|
||||
title: {
|
||||
title: '页面标题',
|
||||
title: t('Menu item title'),
|
||||
'x-component': 'Input',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
icon: {
|
||||
title: '图标',
|
||||
title: t('Icon'),
|
||||
'x-component': 'IconPicker',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
@ -157,7 +157,7 @@ export const LinkMenuItem = itemWrap((props) => {
|
||||
<SchemaInitializer.Item
|
||||
{...props}
|
||||
onClick={async () => {
|
||||
const values = await FormDialog('添加链接', () => {
|
||||
const values = await FormDialog(t('Add link'), () => {
|
||||
return (
|
||||
<SchemaComponentOptions scope={options.scope} components={{ ...options.components }}>
|
||||
<FormLayout layout={'vertical'}>
|
||||
@ -165,20 +165,20 @@ export const LinkMenuItem = itemWrap((props) => {
|
||||
schema={{
|
||||
properties: {
|
||||
title: {
|
||||
title: '链接文字',
|
||||
'x-component': 'Input',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
href: {
|
||||
title: '链接',
|
||||
title: t('Menu item title'),
|
||||
'x-component': 'Input',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
icon: {
|
||||
title: '图标',
|
||||
title: t('Icon'),
|
||||
'x-component': 'IconPicker',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
href: {
|
||||
title: t('Link'),
|
||||
'x-component': 'Input',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
|
@ -29,6 +29,7 @@ export const useSchemaSettings = () => {
|
||||
};
|
||||
|
||||
interface RemoveProps {
|
||||
confirm?: any;
|
||||
removeParentsIfNoChildren?: boolean;
|
||||
breakRemoveOn?: ISchema | ((s: ISchema) => boolean);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { SettingOutlined } from '@ant-design/icons';
|
||||
import { ISchema, useForm } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useSystemSettings } from '.';
|
||||
import { PluginManager, useAPIClient, useRequest } from '..';
|
||||
import { ActionContext, SchemaComponent, useActionContext } from '../schema-component';
|
||||
@ -54,7 +55,7 @@ const schema: ISchema = {
|
||||
},
|
||||
'x-component': 'Action.Drawer',
|
||||
type: 'void',
|
||||
title: '系统设置',
|
||||
title: '{{t("System settings")}}',
|
||||
properties: {
|
||||
title: {
|
||||
type: 'string',
|
||||
@ -69,7 +70,8 @@ const schema: ISchema = {
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Upload.Attachment',
|
||||
'x-component-props': {
|
||||
'action': 'attachments:upload'
|
||||
action: 'attachments:upload',
|
||||
multiple: false,
|
||||
// accept: 'jpg,png'
|
||||
},
|
||||
},
|
||||
@ -84,15 +86,15 @@ const schema: ISchema = {
|
||||
],
|
||||
},
|
||||
allowSignUp: {
|
||||
type: 'string',
|
||||
title: '{{t("Allow sign up")}}',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
'x-content': '{{t("Allow sign up")}}',
|
||||
'x-component': 'Checkbox',
|
||||
'x-decorator': 'FormItem',
|
||||
default: true,
|
||||
},
|
||||
footer1: {
|
||||
'x-component': 'Action.Drawer.Footer',
|
||||
type: 'void',
|
||||
'x-component': 'Action.Drawer.Footer',
|
||||
properties: {
|
||||
cancel: {
|
||||
title: 'Cancel',
|
||||
@ -118,6 +120,7 @@ const schema: ISchema = {
|
||||
|
||||
export const SystemSettingsShortcut = () => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<ActionContext.Provider value={{ visible, setVisible }}>
|
||||
<PluginManager.Toolbar.Item
|
||||
@ -126,7 +129,7 @@ export const SystemSettingsShortcut = () => {
|
||||
setVisible(true);
|
||||
}}
|
||||
icon={<SettingOutlined />}
|
||||
title={'系统设置'}
|
||||
title={t('System settings')}
|
||||
/>
|
||||
<SchemaComponent
|
||||
scope={{ useSaveSystemSettingsValues, useSystemSettingsValues, useCloseAction }}
|
||||
|
@ -42,22 +42,22 @@ const schema: ISchema = {
|
||||
'x-decorator': 'Form',
|
||||
'x-component': 'Action.Drawer',
|
||||
type: 'void',
|
||||
title: '修改密码',
|
||||
title: '{{t("Change password")}}',
|
||||
properties: {
|
||||
oldPassword: {
|
||||
type: 'string',
|
||||
title: '{{t("Old Password")}}',
|
||||
title: '{{t("Old password")}}',
|
||||
required: true,
|
||||
'x-component': 'Password',
|
||||
'x-decorator': 'FormItem',
|
||||
},
|
||||
newPassword: {
|
||||
type: 'string',
|
||||
title: '{{t("New Password")}}',
|
||||
title: '{{t("New password")}}',
|
||||
required: true,
|
||||
'x-component': 'Password',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component-props': { placeholder: '{{t("New Password")}}', checkStrength: true, style: {} },
|
||||
'x-component-props': { checkStrength: true, style: {} },
|
||||
'x-reactions': [
|
||||
{
|
||||
dependencies: ['.confirmPassword'],
|
||||
@ -72,10 +72,10 @@ const schema: ISchema = {
|
||||
confirmPassword: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
title: '{{t("Confirm Password")}}',
|
||||
title: '{{t("Confirm password")}}',
|
||||
'x-component': 'Password',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component-props': { placeholder: '{{t("Confirm password")}}', checkStrength: true, style: {} },
|
||||
'x-component-props': { checkStrength: true, style: {} },
|
||||
'x-reactions': [
|
||||
{
|
||||
dependencies: ['.newPassword'],
|
||||
|
@ -46,7 +46,7 @@ const schema: ISchema = {
|
||||
},
|
||||
'x-component': 'Action.Drawer',
|
||||
type: 'void',
|
||||
title: '个人资料',
|
||||
title: '{{t("Edit profile")}}',
|
||||
properties: {
|
||||
nickname: {
|
||||
type: 'string',
|
||||
|
@ -27,6 +27,7 @@ export class ErrorHandler {
|
||||
try {
|
||||
await next();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
for (const handler of self.handlers) {
|
||||
if (handler.guard(err)) {
|
||||
return handler.render(err, ctx);
|
||||
@ -34,7 +35,6 @@ export class ErrorHandler {
|
||||
}
|
||||
|
||||
self.defaultHandler(err, ctx);
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
1
packages/plugin-error-handler/src/index.ts
Normal file
1
packages/plugin-error-handler/src/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { PluginErrorHandler as default } from './server';
|
@ -1,10 +1,10 @@
|
||||
import { Plugin } from '@nocobase/server';
|
||||
import { ErrorHandler } from './error-handler';
|
||||
import { BaseError } from 'sequelize';
|
||||
import zhCN from './locale/zh_CN';
|
||||
import enUS from './locale/en_US';
|
||||
import lodash from 'lodash';
|
||||
import { compile } from '@formily/json-schema/lib/compiler';
|
||||
import { Plugin } from '@nocobase/server';
|
||||
import lodash from 'lodash';
|
||||
import { BaseError } from 'sequelize';
|
||||
import { ErrorHandler } from './error-handler';
|
||||
import enUS from './locale/en_US';
|
||||
import zhCN from './locale/zh_CN';
|
||||
|
||||
export class PluginErrorHandler extends Plugin {
|
||||
errorHandler: ErrorHandler = new ErrorHandler();
|
||||
|
Loading…
Reference in New Issue
Block a user