更新 Schema

This commit is contained in:
2betop 2020-09-09 15:58:05 +08:00
parent 4341bebf91
commit 7dd979981f
6 changed files with 221 additions and 48 deletions

View File

@ -15,6 +15,8 @@ import {CollapseSchema} from './renderers/Collapse';
import {ColorSchema} from './renderers/Color'; import {ColorSchema} from './renderers/Color';
import {ContainerSchema} from './renderers/Container'; import {ContainerSchema} from './renderers/Container';
import {CRUDSchema} from './renderers/CRUD'; import {CRUDSchema} from './renderers/CRUD';
import {DateSchema} from './renderers/Date';
import {DividerSchema} from './renderers/Divider';
// 每加个类型,这补充一下。 // 每加个类型,这补充一下。
export type SchemaType = export type SchemaType =
@ -37,7 +39,11 @@ export type SchemaType =
| 'collapse' | 'collapse'
| 'color' | 'color'
| 'container' | 'container'
| 'crud'; | 'crud'
| 'date'
| 'datetime'
| 'time'
| 'divider';
export type SchemaObject = export type SchemaObject =
| PageSchema | PageSchema
@ -56,7 +62,9 @@ export type SchemaObject =
| CollapseSchema | CollapseSchema
| ColorSchema | ColorSchema
| ContainerSchema | ContainerSchema
| CRUDSchema; | CRUDSchema
| DateSchema
| DividerSchema;
export type SchemaCollection = export type SchemaCollection =
| SchemaObject | SchemaObject

View File

@ -104,7 +104,7 @@ export interface ButtonSchema extends BaseSchema {
/** /**
* *
*/ */
activeClassName: string; activeClassName?: string;
/** /**
* *
@ -128,8 +128,7 @@ export interface AjaxActionSchema extends ButtonSchema {
*/ */
api: SchemaApi; api: SchemaApi;
// todo feedback?: DialogSchema;
feedback?: any;
reload?: SchemaReload; reload?: SchemaReload;
redirect?: string; redirect?: string;
@ -158,8 +157,7 @@ export interface DialogActionSchema extends ButtonSchema {
*/ */
actionType: 'dialog'; actionType: 'dialog';
// todo dialog: DialogSchema;
dialog: any;
/** /**
* *
@ -174,8 +172,10 @@ export interface DrawerActionSchema extends ButtonSchema {
* *
*/ */
actionType: 'drawer'; actionType: 'drawer';
// todo /**
drawer: any; *
*/
drawer: DrawerSchema;
/** /**
* *
@ -284,6 +284,8 @@ import {
SchemaTooltip, SchemaTooltip,
SchemaTpl SchemaTpl
} from '../Schema'; } from '../Schema';
import {DialogSchema} from './Dialog';
import {DrawerSchema} from './Drawer';
export interface ActionProps export interface ActionProps
extends ButtonSchema, extends ButtonSchema,

View File

@ -1,16 +1,46 @@
import React from 'react'; import React from 'react';
import {Renderer, RendererProps} from '../factory'; import {Renderer, RendererProps} from '../factory';
import moment from 'moment'; import moment from 'moment';
import {BaseSchema} from '../Schema';
export interface DateProps extends RendererProps { /**
className?: string; * Date
placeholder?: string; * https://baidu.gitee.io/amis/docs/components/date
*/
export interface DateSchema extends BaseSchema {
/**
*
*/
type: 'date' | 'datetime' | 'time';
/**
* moment
*/
format?: string; format?: string;
/**
*
*/
placeholder?: string;
/**
* moment
*/
valueFormat?: string; valueFormat?: string;
/**
* 1
*/
fromNow?: boolean; fromNow?: boolean;
/**
* 1
*/
updateFrequency?: number; updateFrequency?: number;
} }
export interface DateProps extends RendererProps, DateSchema {}
export interface DateState { export interface DateState {
random?: number; random?: number;
} }
@ -18,7 +48,10 @@ export interface DateState {
export class DateField extends React.Component<DateProps, DateState> { export class DateField extends React.Component<DateProps, DateState> {
refreshInterval: NodeJS.Timeout; refreshInterval: NodeJS.Timeout;
static defaultProps: Partial<DateProps> = { static defaultProps: Pick<
DateProps,
'placeholder' | 'format' | 'valueFormat' | 'fromNow' | 'updateFrequency'
> = {
placeholder: '-', placeholder: '-',
format: 'YYYY-MM-DD', format: 'YYYY-MM-DD',
valueFormat: 'X', valueFormat: 'X',

View File

@ -12,11 +12,75 @@ import {ModalStore, IModalStore} from '../store/modal';
import {findDOMNode} from 'react-dom'; import {findDOMNode} from 'react-dom';
import {Spinner} from '../components'; import {Spinner} from '../components';
import {IServiceStore} from '../store/service'; import {IServiceStore} from '../store/service';
import {
BaseSchema,
SchemaClassName,
SchemaCollection,
SchemaName,
SchemaObject,
SchemaTpl
} from '../Schema';
import {ActionSchema} from './Action';
export interface DialogProps extends RendererProps { /**
title?: string; // 标题 * Dialog
size?: 'md' | 'lg' | 'sm' | 'xl' | 'full'; * https://baidu.gitee.io/amis/docs/components/dialog
*/
export interface DialogSchema extends Omit<BaseSchema, 'type'> {
/**
*
*/
actions?: Array<ActionSchema>;
/**
*
*/
body?: SchemaCollection;
/**
* Body className
*/
bodyClassName?: SchemaClassName;
/**
* ESC Dialog
*/
closeOnEsc?: boolean; closeOnEsc?: boolean;
name?: SchemaName;
/**
* Dialog
*/
size?: 'xs' | 'sm' | 'md' | 'lg' | 'full';
/**
* title
*/
title?: SchemaTpl | SchemaObject;
header?: SchemaTpl | SchemaObject;
headerClassName?: SchemaClassName;
footer?: SchemaTpl | SchemaObject;
/**
*
*/
confirm?: boolean;
/**
*
*/
showCloseButton?: boolean;
/**
*
*/
showErrorMsg?: boolean;
}
export interface DialogProps extends RendererProps, DialogSchema {
onClose: () => void; onClose: () => void;
onConfirm: ( onConfirm: (
values: Array<object>, values: Array<object>,
@ -26,18 +90,9 @@ export interface DialogProps extends RendererProps {
) => void; ) => void;
children?: React.ReactNode | ((props?: any) => React.ReactNode); children?: React.ReactNode | ((props?: any) => React.ReactNode);
store: IModalStore; store: IModalStore;
className?: string;
header?: SchemaNode;
body?: SchemaNode;
headerClassName?: string;
bodyClassName?: string;
footer?: SchemaNode;
confirm?: boolean;
show?: boolean; show?: boolean;
lazyRender?: boolean; lazyRender?: boolean;
wrapperComponent: React.ReactType; wrapperComponent: React.ElementType;
showCloseButton?: boolean;
showErrorMsg?: boolean;
} }
export interface DialogState { export interface DialogState {
@ -122,14 +177,14 @@ export default class Dialog extends React.Component<DialogProps, DialogState> {
this.isDead = true; this.isDead = true;
} }
buildActions(): Array<Action> { buildActions(): Array<ActionSchema> {
const {actions, confirm, translate: __} = this.props; const {actions, confirm, translate: __} = this.props;
if (typeof actions !== 'undefined') { if (typeof actions !== 'undefined') {
return actions; return actions;
} }
let ret: Array<Action> = []; let ret: Array<ActionSchema> = [];
ret.push({ ret.push({
type: 'button', type: 'button',
actionType: 'cancel', actionType: 'cancel',

View File

@ -1,13 +1,18 @@
import React from 'react'; import React from 'react';
import {Renderer, RendererProps} from '../factory'; import {Renderer, RendererProps} from '../factory';
import {ServiceStore, IServiceStore} from '../store/service'; import {BaseSchema} from '../Schema';
import {filter} from '../utils/tpl';
import cx from 'classnames';
export interface DividerProps extends RendererProps { /**
lineStyle: 'dashed' | 'solid'; * Divider 线
* https://baidu.gitee.io/amis/docs/components/divider
*/
export interface DividerSchema extends BaseSchema {
type: 'divider';
lineStyle?: 'dashed' | 'solid';
} }
export interface DividerProps extends RendererProps, DividerSchema {}
export default class Divider extends React.Component<DividerProps, object> { export default class Divider extends React.Component<DividerProps, object> {
static defaultProps: Pick<DividerProps, 'className' | 'lineStyle'> = { static defaultProps: Pick<DividerProps, 'className' | 'lineStyle'> = {
className: '', className: '',

View File

@ -11,12 +11,90 @@ import {IModalStore, ModalStore} from '../store/modal';
import {filter} from '../utils/tpl'; import {filter} from '../utils/tpl';
import {Spinner} from '../components'; import {Spinner} from '../components';
import {IServiceStore} from '../store/service'; import {IServiceStore} from '../store/service';
import {
BaseSchema,
SchemaClassName,
SchemaCollection,
SchemaName,
SchemaObject,
SchemaTpl
} from '../Schema';
import {ActionSchema} from './Action';
export interface DrawerProps extends RendererProps { /**
title?: string; // 标题 * Drawer
size?: 'md' | 'lg' | 'xs' | 'sm'; * https://baidu.gitee.io/amis/docs/components/drawer
position?: 'left' | 'right' | 'top' | 'bottom'; */
export interface DrawerSchema extends Omit<BaseSchema, 'type'> {
/**
*
*/
actions?: Array<ActionSchema>;
/**
*
*/
body?: SchemaCollection;
/**
* Body className
*/
bodyClassName?: SchemaClassName;
/**
* ESC Dialog
*/
closeOnEsc?: boolean; closeOnEsc?: boolean;
name?: SchemaName;
/**
* Dialog
*/
size?: 'xs' | 'sm' | 'md' | 'lg' | 'full';
/**
* title
*/
title?: SchemaTpl | SchemaObject;
/**
*
*/
position?: 'left' | 'right' | 'top' | 'bottom';
/**
*
*/
header?: SchemaCollection;
/**
*
*/
footer?: SchemaCollection;
/**
*
*/
confirm?: boolean;
/**
*
*/
resizable?: boolean;
/**
*
*/
overlay?: boolean;
/**
*
*/
closeOnOutside?: boolean;
}
export interface DrawerProps extends RendererProps, DrawerSchema {
onClose: () => void; onClose: () => void;
onConfirm: ( onConfirm: (
values: Array<object>, values: Array<object>,
@ -26,16 +104,8 @@ export interface DrawerProps extends RendererProps {
) => void; ) => void;
children?: React.ReactNode | ((props?: any) => React.ReactNode); children?: React.ReactNode | ((props?: any) => React.ReactNode);
store: IModalStore; store: IModalStore;
className?: string;
header?: SchemaNode;
body?: SchemaNode;
bodyClassName?: string;
footer?: SchemaNode;
confirm?: boolean;
show?: boolean; show?: boolean;
resizable?: boolean;
overlay?: boolean;
closeOnOutside?: boolean;
drawerContainer?: () => HTMLElement; drawerContainer?: () => HTMLElement;
} }
@ -113,14 +183,14 @@ export default class Drawer extends React.Component<DrawerProps, object> {
this.reaction && this.reaction(); this.reaction && this.reaction();
} }
buildActions(): Array<Action> { buildActions(): Array<ActionSchema> {
const {actions, confirm, translate: __} = this.props; const {actions, confirm, translate: __} = this.props;
if (typeof actions !== 'undefined') { if (typeof actions !== 'undefined') {
return actions; return actions;
} }
let ret: Array<Action> = []; let ret: Array<ActionSchema> = [];
ret.push({ ret.push({
type: 'button', type: 'button',
actionType: 'close', actionType: 'close',